void kernel_main() { terminal_initialize(); start_screen(20); testStuff(); //runs other main to init everything else, sloppy but short on time main_call(); }
void setftty() { int change = 0; flags.cbreak = ON; flags.echo = OFF; /* Should use (ECHO|CRMOD) here instead of ECHO */ if(curttyb.c_lflag & ECHO){ curttyb.c_lflag &= ~ECHO; change++; } if(curttyb.c_lflag & ICANON){ curttyb.c_lflag &= ~ICANON; /* be satisfied with one character; no timeout */ curttyb.c_cc[VMIN] = 1; curttyb.c_cc[VTIME] = 0; change++; } if(change){ setctty(); } start_screen(); }
int main(int argc, char *argv[]) { //initializing initscr(); //starts ncurses cbreak(); //allows input to be accessed as soon as it is typed without having to press the 'enter' key keypad(stdscr, TRUE); //allows arrow keys and F1,F2,etc to be read noecho(); //does not echo the typed characters on the screen curs_set(0); //does not display the curser start_color(); //starts colour functionality start_screen(); //calls the start screen function (in start_end_screen.c) //variable declaration WINDOW *my_win,*enemy_win; int startx, starty; int ch,end_game=0,first_time=1; int score=0; time_t t; //seed the random function srand((unsigned) time(&t)); //initial placement of player is in the centre of the screen starty = (LINES) / 2; startx = (COLS) / 2; refresh(); //create player my_win = create_playerwin(starty, startx); //this is to space out the enemies to be dropped and make sure that even if a value for getchar() isnt enetered the game loop continues. i.e. enemies continue to be dropped. - but remember with just this, the game will do a loop without this delay if the player gives an input in less than 0.5 seconds. So this case is handled later. Lets call it 'case1'. . /* So if this is changed for difficulty also correspondingly change the place where case1 is handled where get_time_gap() is called in main*/ halfdelay(5); //this waits for 0.5 seconds for an input, if no input is given, it skips the scan statement and continues the program //game loop - ch holds the currently entered button while((ch = getch()) != 'q') { //for movement - the player window is destroyed and recreated at the new position switch(ch) { case KEY_LEFT: if (startx==0) //left side boundary for player { break; } destroy_win(my_win); my_win = create_playerwin(starty,--startx); break; case KEY_RIGHT: if (startx>=COLS-6) //right side boundary for the player (the -6 is to account for the size of the player object) { break; } destroy_win(my_win); my_win = create_playerwin(starty,++startx); break; case KEY_UP: if (starty==1) //top boundary for the player { break; } destroy_win(my_win); my_win = create_playerwin(--starty,startx); break; case KEY_DOWN: //bottom boundary for the player (the -4 is to account for the size of the player object) if (starty==LINES-4) { break; } destroy_win(my_win); my_win = create_playerwin(++starty,startx); break; //pausing the game case 'p': cbreak(); mvprintw(0,0,"Press any key to resume. SCORE: %d ",score); getch(); halfdelay(5); break; } //for the first time the time must be set (the time at the previous instant when the enemy was dropped is recorded and the time elapsed since then is checked. If it reaches 0.5 seconds, it drops the next enemy) if (first_time==1) { first_time=0; gettimeofday(&time1,NULL); } gettimeofday(&time2,NULL); //print important game statistics and instructions mvprintw(0,0,"Press 'q' to quit. 'p' to pause. SCORE: %d",score); //this condition is to ensure that the game loop waits for 0.5 sec before executing again in the situation that the player has entered an input quickly. It takes care of 'case1' /* So if this is changed for difficulty, also correspondingly change the place where case1 was mentioned in the half_delay function*/ if (get_time_gap()<500000.0) { continue; } //end game becomes 1 if you have been hit end_game=drop_enemy(&score,starty,startx); if (end_game==1) { break; //breaks the game loop } gettimeofday(&time1,NULL); } //call the high scores screen (in start_end_screen.c) high_scores(score); endwin(); /* End curses mode */ return 0; }