void setup_handle_event(SDL_Event event, camera *camera, PLAYERS *players) { if(paused) { paused_state.handle_event(event, camera, players); return; } game_handle_event(event, camera, players); if(event.type == SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_RETURN: change_state(&game_state); break; case SDLK_r: players->setup = false; change_state(&setup_state); break; default: break; } } }
int main(int argc, char** argv) { global_argc = argc; global_argv = argv; //Initialize Allegro and give the user the chance to //set up the game. TaigaInit(game_bootup()); //Whether or not there is something to draw. bool redraw = true; //Whether enough time has passed that we aren't violating the framerate //cap if we draw another frame. bool frameokay = true; while(true) { ALLEGRO_EVENT ev; //Process all incoming events. Note that all events generated by Allegro //are passed to game_handle_event() except for ones generated by //taiga_ticktimer and taiga_frametimer. al_wait_for_event(taiga_events, &ev); if(ev.type == ALLEGRO_EVENT_TIMER && ev.timer.source == taiga_ticktimer) { //Clear all TaigaDrawers from the canvas. canvas.clear(); //Update input based on keyboard and mouse events. key.update(); mouse.update(); //Process all game and actor logic. game_pretick(); actors.tick(); game_posttick(); //Now that a tick has passed, we have something to draw to the screen. redraw = true; } //When the frametimer (if any) expires, it's okay to draw another frame. else if(ev.type == ALLEGRO_EVENT_TIMER && ev.timer.source == taiga_frametimer) { frameokay = true; } else { game_handle_event(ev); } //When the display is out of focus, events telling the game that a key //has been released are never generated, and keys may get "stuck" as a //result. To remedy this, when the display loses focus, we should //assume all keys have immediately been released. if(ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) { mouse.clear(); key.clear(); } if(taiga_quitting) break; //If we have something to redraw and we don't have any events //left in the queue that need to be processed, then we draw //the frame onto the screen. if(redraw && al_is_event_queue_empty(taiga_events) && frameokay) { redraw = false; canvas.draw_entries(); al_flip_display(); if(taiga_frametimer) frameokay = false; } } return 0; }