static void push_state(struct State *s, void *param) { if (current_state == (MAX_STATES * 2)) { puts("push_state(): State stack is full"); return; } if (!s->loaded) { if (loaded_count < MAX_STATES) { s->_load(param); s->loaded = TRUE; engine.loaded_states[loaded_count++] = s; } else { puts("change_state(): Unable to load state (reached MAX_STATES)"); return; } } s->_enter(param); if (engine.states[current_state] != NULL) { engine.states[current_state]->_pause(); } engine.states[++current_state] = s; al_flush_event_queue(engine.event_queue); }
void EditorEngine::PopState() { int popLevel = states_.back()->GetPopLevel(); //store something mmmm so pop back x levels then push something aswell int i = 0; while(i < popLevel){ // cleanup the current state if ( !states_.empty() ) { if(states_.size() > 1){ states_.back()->CleanUp(); delete states_.back(); states_.pop_back(); } } i++; } //fprintf(stderr,"States Popped\n\n\n"); // resume previous state..This will control where in the last state it should appear and what variables need to be reSet if ( !states_.empty() ) { states_.back()->Resume(); //clears all events in queue so the other menus keystate is cleared al_flush_event_queue(states_.back()->GetEventQueue()); } currentState_ = states_.back(); }
void EventQueue::listenEvents() { checkInit(); al_flush_event_queue(this->implementation->allegroEventQueue); al_register_event_source(this->implementation->allegroEventQueue, al_get_display_event_source(fgeal::display->implementation->allegroDisplay)); al_register_event_source(this->implementation->allegroEventQueue, al_get_keyboard_event_source()); al_register_event_source(this->implementation->allegroEventQueue, al_get_mouse_event_source()); }
int allegro_initialization(int widht, int height) { if(!al_init()) { al_show_native_message_box(display, "Error", "Error", "Failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } //else // printf("Allegro initialized\n"); al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE); al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); display = al_create_display(widht, height); if(!display) { al_show_native_message_box(display, "Error", "Error", "failed to create display!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } //else // printf("Display created\n"); event_queue = al_create_event_queue(); if(!event_queue) { al_show_native_message_box(display, "Error", "Error", "failed to create event_queue!", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); return -1; } //else // printf("Event queue created\n"); al_flush_event_queue(event_queue); al_init_font_addon(); al_init_ttf_addon(); font = al_load_ttf_font("C:\\Windows\\Fonts\\cour.ttf", TEXT_SIZE, 0); font_scale = al_load_ttf_font("C:\\Windows\\Fonts\\cour.ttf", TEXT_SIZE, 0); if(!font || !font_scale) { al_destroy_event_queue(event_queue); al_show_native_message_box(display, "Error", "Error", "Failed to initialize font!", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); return -1; } //else // printf("Fonts installed\n"); al_install_keyboard(); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_keyboard_event_source()); ALLEGRO_EVENT ev; al_init_primitives_addon(); al_clear_to_color(al_map_rgb(0,0,20)); //al_flip_display(); return 0; }
/* Takes all states off and goes back to first state eg: main menu most often */ void EditorEngine::PopStateToFirst() { int popLevel = states_.size(); int i = 1; while(i < popLevel){ states_.back()->CleanUp(); delete states_.back(); states_.pop_back(); popLevel--; } states_.back()->Resume(); al_flush_event_queue(states_.back()->GetEventQueue()); currentState_ = states_.back(); }
void changeGameState(GameState state) { gState = state; al_destroy_bitmap(background); switch(gState) { case Game: background = al_load_bitmap(GAME_BACKGROUND_PATH); break; case Menu: background = al_load_bitmap(MENU_BACKGROUND_PATH); break; } executeFade(display, background); al_flush_event_queue(eventMenuQueue); }
int main(int argc, char* argv[]) { gameEngine.Init(); //Sets up allegro libraries and implements drivers gameEngine.PushState(new MenuState); while(gameEngine.Running()) { gameEngine.HandleEvents(); gameEngine.Update(); gameEngine.Draw(); al_wait_for_event(gameEngine.redrawQueue, NULL); al_flush_event_queue(gameEngine.redrawQueue); } gameEngine.Cleanup(); return 0; }
void GameEngine::Flush() { al_wait_for_event(GetEventQueue(), GetEvent()); al_flush_event_queue(GetEventQueue()); }
void game_rest(double secs) { al_rest(secs); al_flush_event_queue(engine.event_queue); }
void main_game_loop(void) { ALLEGRO_EVENT ev; int fps = 0; int cps = 0; int force_display_update = 0; // display always runs at least once each second int playing = 1; view.fps = 0; view.cycles_per_second = 0; int skip_frame = 0; // if game is running too slowly, it will skip frames to save drawing time. // if (game.phase == GAME_PHASE_PREGAME) // skip_frame = 1; // display is not updated during pregame phase. do // main game loop { // if (game.phase != GAME_PHASE_PREGAME) // no input in pregame phase get_ex_control(0, (game.pause_soft == 0)); // ex_control needs to be updated even when halted (control will not be updated) run_input(); run_panels(); run_editor(); /* // should probably run display at the end of the loop rather than the start // - so that the game has run through at least once when loading game if (!skip_frame || force_display_update) { run_display(); fps ++; force_display_update = 0; } */ game.total_time++; // if (game.pause_hard == 0) // { // if (view.focus_proc != NULL // && view.focus_proc->exists != 1) // will be -1 if proc has just been deallocated // { // view.focus_proc = NULL; // reset_proc_box_height(NULL); // } // need to find a better place to put this if (game.phase == GAME_PHASE_WORLD || game.phase == GAME_PHASE_OVER) // game continues to run while over. { if (!game.pause_soft) { if (game.watching != WATCH_PAUSED_TO_WATCH) { // if (run_turns()) // returns 0 if game has left world phase (e.g. because time has run out), 1 if still in world phase { if (game.watching == WATCH_FINISHED_AND_STOP_WATCHING || game.watching == WATCH_FINISHED_BUT_STILL_WATCHING || game.watching == WATCH_FINISHED_JUST_STOP_PAUSING) { w.core[bcp_state.watch_core_index].next_execution_timestamp = w.world_time; run_cores_and_procs(bcp_state.watch_core_index); w.core[bcp_state.watch_core_index].next_execution_timestamp = w.world_time + EXECUTION_COUNT; switch(game.watching) { case WATCH_FINISHED_AND_STOP_WATCHING: game.watching = WATCH_OFF; bcp_state.watch_core_index = -1; bcp_state.bcp_mode = BCP_MODE_EMPTY; break; case WATCH_FINISHED_BUT_STILL_WATCHING: game.watching = WATCH_ON; break; case WATCH_FINISHED_JUST_STOP_PAUSING: game.watching = WATCH_OFF; break; } } else { run_world(); // runs the world and also the mission, if this is a mission. Can end the game. // should run_world be after the next three function calls? Maybe. // run_clouds(); clouds don't need to be run run_fragments(); run_cores_and_procs(-1); } if (game.watching != WATCH_PAUSED_TO_WATCH) // this may have been set in either of the run_cores_and_procs() calls above { run_packets(); cps ++; w.world_time ++; w.world_seconds = (w.world_time - BASE_WORLD_TIME) / 60; update_vision_area(); // update fog of war after w.world_time is incremented so that the vision_time timestamps are up to date if (game.phase != GAME_PHASE_OVER) { if (game.type == GAME_TYPE_BASIC) run_custom_game(); else run_mission(); // for now ignore return values } play_sound_list(); } } } // end if (!game.pause_watch) else run_bcode_watch(); } // end if (!game.pause_soft) } // end game phase test if (game.phase == GAME_PHASE_OVER) { game.fast_forward = 0; if (run_game_over()) break; // user clicked game over button } if (game.phase == GAME_PHASE_PREGAME) { game.fast_forward = 0; run_pregame(); } // w.total_time ++; // total_time is affected by hard pause, but unlike world_time is not affected by soft pause (so it can only be used for things that don't affect gameplay, like console line highlighting) // run_input(); // this derives control (available to programs) from ex_control. doesn't need to be run for user to be able to use mode buttons and interact with sysmenu/editor/templates etc (as these use ex_control directly) if (game.phase == GAME_PHASE_FORCE_QUIT) break; // can be set in run_input() if user clicks on quit in system menu run_commands(); view.just_resized = 0; // fps_queue generates an event once each second - used for calculating fps and forcing a display update at least once per second if (al_get_next_event(fps_queue, &ev)) { view.fps = fps; fps = 0; view.cycles_per_second = cps; cps = 0; // if (game.phase != GAME_PHASE_PREGAME) // force_display_update = 1; // this is checked next time through this loop (see display call above) } // if (!skip_frame) { // run_panels(); // run_editor(); // may need to set playing to 0 here if player quits using sysmenu /* switch(settings.edit_window) { case EDIT_WINDOW_EDITOR: run_editor(); break; case EDIT_WINDOW_TEMPLATES: run_templates(); break; case EDIT_WINDOW_SYSMENU: playing = run_sysmenu(); break; // case EDIT_WINDOW_PROGRAMS: // run_programs_menu(); break; }*/ } if (playing == 0) break; run_consoles(); // I think it's okay to call this even when halted skip_frame = 0; // check for fast-forward (skip). Ignore FF if not in world, or if paused if (game.fast_forward > 0 && game.phase == GAME_PHASE_WORLD // let's not allow ff in GAME_PHASE_OVER && game.pause_soft == 0 && game.watching != WATCH_PAUSED_TO_WATCH) // && game.pause_hard == 0) { switch (game.fast_forward_type) { case FAST_FORWARD_TYPE_NO_DISPLAY: if (game.fast_forward == FAST_FORWARD_JUST_STARTED) game.fast_forward = FAST_FORWARD_ON; // don't skip this frame (to prevent a delay before "FAST FORWARD" message appears on screen) else { /* if (fps == 0) { fps = 1; } else*/ skip_frame = 1; // else } break; case FAST_FORWARD_TYPE_SMOOTH: game.fast_forward = FAST_FORWARD_ON; al_flush_event_queue(event_queue); break; case FAST_FORWARD_TYPE_SKIP: game.fast_forward = FAST_FORWARD_ON; if (w.world_time % 8 != 0) skip_frame = 1; break; /* case FAST_FORWARD_TYPE_8X: game.fast_forward = FAST_FORWARD_ON; if (w.world_time % 8 != 0) skip_frame = 1; break;*/ } } // now check whether the timer has expired during game processing. If it has, don't generate a display this tick (unless force_display_update==1) if (al_get_next_event(event_queue, &ev)) { // switch(ev.type) // { // case ALLEGRO_EVENT_TIMER: this should be the only possible type. skip_frame = 1; // break; // } // al_flush_event_queue(event_queue); } if (!skip_frame || force_display_update) { run_display(); fps ++; force_display_update = 0; } // wait for the timer so we can go to the next tick (unless we're fast-forwarding or the timer has already expired) if (!skip_frame && (game.fast_forward == FAST_FORWARD_OFF || game.pause_soft || game.watching == WATCH_PAUSED_TO_WATCH)) // don't skip frames if paused, even if fast-forwarding { al_wait_for_event(event_queue, &ev); // al_flush_event_queue(event_queue); } } while (TRUE); // end main game loop // if game has been finished or quit, we can end up here outside the loop }
int real_main() { srand48(time(NULL)); if (!al_init()) { puts("Could not initialise allegro"); return 1; } if (!al_install_keyboard()) { puts("Could not initialise allegro keyboard subsystem"); return 1; } keys = malloc(sizeof(ALLEGRO_KEYBOARD_STATE)); if (!init_font()) { puts("Could not initialise allegro font subsystem"); return 1; } al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); ALLEGRO_DISPLAY* display = al_create_display(1, 1); if (!display) { puts("Could not initialise allegro display"); return 1; } Vector size = new_vector(); size.x = al_get_display_width(display); size.y = al_get_display_height(display); Game* game = new_game(size); int i; for (i = 0; i < ASTEROIDN; i++) spawn_asteroid(game); ALLEGRO_TIMER* timer = al_create_timer(1.0/FPS); ALLEGRO_EVENT_QUEUE *timereq = al_create_event_queue(); ALLEGRO_EVENT_QUEUE *genericeq = al_create_event_queue(); if (!timereq || !genericeq) { puts("Could not create allegro event queue"); return 1; } al_register_event_source(timereq, al_get_timer_event_source(timer)); al_register_event_source(genericeq, al_get_keyboard_event_source()); al_register_event_source(genericeq, al_get_display_event_source(display)); al_start_timer(timer); // Start generating timer events ALLEGRO_EVENT *timerevent = malloc(sizeof(ALLEGRO_EVENT)); ALLEGRO_EVENT *genericevent = malloc(sizeof(ALLEGRO_EVENT)); float last_drawn, now; last_drawn = now = al_get_time(); while (game->status != Quit) { al_get_keyboard_state(keys); al_wait_for_event(timereq, NULL); al_get_next_event(timereq, timerevent); // No need to fill up the queue if we are late drawing frames al_flush_event_queue(timereq); handle_key_status(game, keys); while(al_get_next_event(genericeq, genericevent)) switch(genericevent->type) { case ALLEGRO_EVENT_KEY_DOWN: handle_key_event(game, genericevent->keyboard.keycode); break; case ALLEGRO_EVENT_DISPLAY_RESIZE: game->size.x = genericevent->display.x; game->size.y = genericevent->display.y; al_acknowledge_resize(display); break; case ALLEGRO_EVENT_DISPLAY_CLOSE: game->status = Quit; break; } now = al_get_time(); update_game(game, now - last_drawn); last_drawn = now; draw_game(game, game->status == Playing ? 1 : 0.2); switch(game->status) { case Playing: break; case Paused: draw_paused(game); break; case Won: draw_won(game); break; case Lost: draw_lost(game); break; default: break; } al_flip_display(); } free(timerevent); free(genericevent); delete_game(game); return 0; }
int main(int argc, char **argv) { A.x = 0; A.y = 0; B.x = 400; B.y = 0; C.x = 400; C.y = 350; D.x = 0; D.y = 350; if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) { printf("could not init Allegro\n"); return 1; } ALLEGRO_DISPLAY *display = al_create_display(800, 600); if (!display) { printf("could not create display\n"); return 1; } if (!al_init_primitives_addon()) { printf("could not init primitives\n"); return 1; } if (!al_install_keyboard()) { printf("could not install keybaord\n"); return 1; } if (!al_install_mouse()) { printf("could not install mouse\n"); return 1; } ALLEGRO_BITMAP *bitmap = al_create_bitmap(800, 600); if (bitmap == NULL) { printf("could not create bitmap\n"); return 1; } al_set_target_bitmap(bitmap); al_clear_to_color(al_map_rgb(255, 255, 255)); al_draw_rectangle(A.x + xOfs, A.y + yOfs, C.x + xOfs, C.y + yOfs, al_map_rgb(0, 0, 0), 2.0); al_set_target_backbuffer(display); al_draw_bitmap(bitmap, 0, 0, 0); al_flip_display(); int pair1 = 0; int pair2 = 0; ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); ALLEGRO_EVENT event; al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); while (input_counter < 4) { al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && event.mouse.button == 1) { input_points[input_counter].x = event.mouse.x; input_points[input_counter].y = event.mouse.y; input_counter++; if (input_counter > 1) { pair1 = input_counter - 2; pair2 = input_counter - 1; al_set_target_bitmap(bitmap); al_draw_line(input_points[pair1].x, input_points[pair1].y, input_points[pair2].x, input_points[pair2].y, al_map_rgb(0, 150, 0), 3.0); al_set_target_backbuffer(display); al_draw_bitmap(bitmap, 0, 0, 0); al_flip_display(); } if (input_counter == 4) { pair1 = 3; pair2 = 0; al_set_target_bitmap(bitmap); al_draw_line(input_points[pair1].x, input_points[pair1].y, input_points[pair2].x, input_points[pair2].y, al_map_rgb(0, 150, 0), 3.0); al_set_target_backbuffer(display); al_draw_bitmap(bitmap, 0, 0, 0); al_flip_display(); } } } VECTOR AAPrime = getCornerOffset(input_points[0], A); VECTOR BBPrime = getCornerOffset(input_points[1], B); VECTOR CCPrime = getCornerOffset(input_points[2], C); VECTOR DDPrime = getCornerOffset(input_points[3], D); VECTOR AAPrimeS, BBPrimeS, CCPrimeS, DDPrimeS; ALLEGRO_MOUSE_STATE state; POINT p; POINT PPPrime; POINT center; center.x = 0; center.y = 0; for (int i = 0; i < 4; i++) { center.x += input_points[i].x; center.y += input_points[i].y; } center.x /= 4; center.y /= 4; float total; al_flush_event_queue(queue); while (1) { al_wait_for_event(queue, &event); if (event.type != ALLEGRO_EVENT_MOUSE_AXES) { if (event.type == ALLEGRO_EVENT_KEY_DOWN || event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } continue; } al_draw_bitmap(bitmap, 0, 0, 0); // get the input point al_get_mouse_state(&state); p.x = state.x; p.y = state.y; // calculate the distances float ADistance = distance(p, input_points[0]); float BDistance = distance(p, input_points[1]); float CDistance = distance(p, input_points[2]); float DDistance = distance(p, input_points[3]); float AB = ADistance / BDistance; float BA = BDistance / ADistance; total = AB + BA; AB /= total; BA /= total; float topVec = AAPrime.y * BA + BBPrime.y * AB; float ACurs = fabs(p.y - input_points[0].y); float BCurs = fabs(p.y - input_points[1].y); float topCurs = ACurs * BA + BCurs * AB; al_draw_line(p.x, p.y, p.x, p.y + topVec, al_map_rgb(0, 255, 0), 4.0); al_draw_circle(p.x, p.y + topVec, 5, al_map_rgb(0, 0, 0), 2.0); float CD = CDistance / DDistance; float DC = DDistance / CDistance; total = DC + CD; CD /= total; DC /= total; float bottomVec = CCPrime.y * DC + DDPrime.y * CD; float DCurs = fabs(p.y - input_points[3].y); float CCurs = fabs(p.y - input_points[2].y); float bottomCurs = DCurs * CD + CCurs * DC; al_draw_line(p.x, p.y, p.x, p.y + bottomVec, al_map_rgb(0, 255, 0), 4.0); al_draw_circle(p.x, p.y + bottomVec, 5, al_map_rgb(0, 0, 0), 2.0); float topBottom = topCurs / bottomCurs; float bottomTop = bottomCurs / topCurs; total = topBottom + bottomTop; topBottom /= total; bottomTop /= total; float BC = BDistance / CDistance; float CB = CDistance / BDistance; total = BC + CB; BC /= total; CB /= total; float rightVec = BBPrime.x * CB + CCPrime.x * BC; BCurs = fabs(p.x - input_points[1].x); CCurs = fabs(p.x - input_points[2].x); float rightCurs= BCurs * CB + CCurs * BC; al_draw_line(p.x, p.y, p.x + rightVec, p.y, al_map_rgb(0, 255, 0), 4.0); al_draw_circle(p.x + rightVec, p.y, 5, al_map_rgb(0, 0, 0), 2.0); float DA = DDistance / ADistance; float AD = ADistance / DDistance; total = DA + AD; DA /= total; AD /= total; float leftVec = DDPrime.x * AD + AAPrime.x * DA; ACurs = fabs(p.x - input_points[0].x); DCurs = fabs(p.x - input_points[3].x); float leftCurs = ACurs * DA + DCurs * AD; al_draw_line(p.x, p.y, p.x + leftVec, p.y, al_map_rgb(0, 255, 0), 4.0); al_draw_circle(p.x + leftVec, p.y, 5, al_map_rgb(0, 0, 0), 2.0); float leftRight = leftCurs / rightCurs; float rightLeft = rightCurs / leftCurs; total = leftRight + rightLeft; leftRight /= total; rightLeft /= total; // draw the main corner vectors /* al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x + AAPrime.x, input_points[0].y + AAPrime.y, al_map_rgb(0, 0, 0), 2.0);*/ /* al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x + BBPrime.x, input_points[1].y + BBPrime.y, al_map_rgb(0, 0, 0), 2.0);*/ /* al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x + CCPrime.x, input_points[2].y + CCPrime.y, al_map_rgb(0, 0, 0), 2.0);*/ /* al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x + DDPrime.x, input_points[3].y + DDPrime.y, al_map_rgb(0, 0, 0), 2.0);*/ // draw the corner vector components /* al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x + AAPrime.x, input_points[0].y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x, input_points[0].y + AAPrime.y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x + BBPrime.x, input_points[1].y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x, input_points[1].y + BBPrime.y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x + CCPrime.x, input_points[2].y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x, input_points[2].y + CCPrime.y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x + DDPrime.x, input_points[3].y, al_map_rgb(255, 0, 0), 1.0);*/ /* al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x, input_points[3].y + DDPrime.y, al_map_rgb(255, 0, 0), 1.0);*/ // draw the processed point PPPrime.y = topVec * bottomTop + bottomVec * topBottom; PPPrime.x = rightVec * leftRight + leftVec * rightLeft; al_draw_line(p.x, p.y, p.x + PPPrime.x, p.y, al_map_rgb(0, 0, 255), 2.0); al_draw_line(p.x, p.y, p.x, p.y + PPPrime.y, al_map_rgb(0, 0, 255), 2.0); al_draw_circle(p.x + xOfs + PPPrime.x, p.y + yOfs + PPPrime.y, 5, al_map_rgb(0, 255, 0), 2.0); al_draw_circle(p.x + xOfs + PPPrime.x, p.y + yOfs + PPPrime.y, 1, al_map_rgb(0, 0, 0), 1.0); al_flip_display(); } return 0; }
int MonopolyGame::run() { // Start the timer's so that revisions are properly drawn. al_start_timer( m_alTimer ); al_start_timer( m_alFrameTimer ); // Perform the first display update. al_flip_display(); // Zero the FPS counters. m_oldFps = 0.0; m_currFps = 0.0; m_framesDone = 0.0; al_flush_event_queue( m_alEventQueue ); // Run until the exit flag is thrown. while( !m_exitGame ) { ALLEGRO_EVENT alEvent; al_wait_for_event( m_alEventQueue, &alEvent ); al_get_keyboard_state( &m_alKeyState ); // If the user clicks the window's 'close (X)' button. if( alEvent.type == ALLEGRO_EVENT_DISPLAY_CLOSE ) { // Exit the game. m_exitGame = true; } // Or if the user hits the 'ESC' key. else if( al_key_down( &m_alKeyState, ALLEGRO_KEY_ESCAPE ) ) { // Exit the game. m_exitGame = true; } // Process any timed events that have been triggered. else if( alEvent.type == ALLEGRO_EVENT_TIMER ) { if( alEvent.timer.source == m_alTimer ) { // This is the hook into the turn logic. handleTurn(); // We will update the camera position only if the timer has been triggered. cameraUpdate( m_alCamera.cameraPosition, // X and Y location of the camera. m_playerList[m_playersTurn].get_x(), // Player's x position. m_playerList[m_playersTurn].get_y(), // Player's y position. 32, 32 ); // Width and height of player's image. } else if( alEvent.timer.source == m_alFrameTimer ) { for( int pCounter = 0; pCounter < NUM_PLAYERS; pCounter++ ) { // If this player has more than '0' money. if( m_playerList[pCounter].get_money() > 0 ) { // For each player, update the image we will display this frame. m_playerList[pCounter].animationLogic(); } } } // Do some camera transform magic. al_identity_transform( &m_alCamera.alCameraTransform ); // Adjust the camera so that it is centered over our player's position. al_translate_transform( &m_alCamera.alCameraTransform, -m_alCamera.cameraPosition[Positions::X_POS], -m_alCamera.cameraPosition[Positions::Y_POS] ); // Push the camera's changes. al_use_transform( &m_alCamera.alCameraTransform ); // Since the screen has been updated, we want to flag the screen to be redrawn. m_redrawScreen = true; } //if( m_redrawScreen ) { if( m_redrawScreen && al_is_event_queue_empty( m_alEventQueue ) ) { m_redrawScreen = false; m_framesDone++; draw(); } calcFramerate(); } return 0; }
void EventQueue::flushEvents() { checkInit(); al_flush_event_queue(this->implementation->allegroEventQueue); }
int main(void) { ALLEGRO_DISPLAY *display; ALLEGRO_FONT *font; ALLEGRO_CONFIG *config; ALLEGRO_EVENT_QUEUE *queue; bool write = false; bool flip = false; bool quit; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_font_addon(); al_init_image_addon(); al_install_keyboard(); al_install_mouse(); /* Read parameters from ex_vsync.ini. */ config = al_load_config_file("ex_vsync.ini"); if (!config) { config = al_create_config(); write = true; } /* 0 -> Driver chooses. * 1 -> Force vsync on. * 2 -> Force vsync off. */ vsync = option(config, "vsync", 0); fullscreen = option(config, "fullscreen", 0); frequency = option(config, "frequency", 0); /* Write the file back (so a template is generated on first run). */ if (write) { al_save_config_file("ex_vsync.ini", config); } al_destroy_config(config); /* Vsync 1 means force on, 2 means forced off. */ if (vsync) al_set_new_display_option(ALLEGRO_VSYNC, vsync, ALLEGRO_SUGGEST); /* Force fullscreen mode. */ if (fullscreen) { al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); /* Set a monitor frequency. */ if (frequency) al_set_new_display_refresh_rate(frequency); } display = al_create_display(640, 480); if (!display) { abort_example("Error creating display.\n"); } font = al_load_font("data/a4_font.tga", 0, 0); if (!font) { abort_example("Failed to load a4_font.tga\n"); } queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); quit = display_warning(queue, font); al_flush_event_queue(queue); while (!quit) { ALLEGRO_EVENT event; /* With vsync, this will appear as a 50% gray screen (maybe * flickering a bit depending on monitor frequency). * Without vsync, there will be black/white shearing all over. */ if (flip) al_clear_to_color(al_map_rgb_f(1, 1, 1)); else al_clear_to_color(al_map_rgb_f(0, 0, 0)); al_flip_display(); flip = !flip; while (al_get_next_event(queue, &event)) { switch (event.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: quit = true; case ALLEGRO_EVENT_KEY_DOWN: if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) quit = true; } } /* Let's not go overboard and limit flipping at 1000 Hz. Without * this my system locks up and requires a hard reboot :P */ al_rest(0.001); } al_destroy_font(font); al_destroy_event_queue(queue); return 0; }
static int allua_Event_queue_flush(lua_State * L) { ALLUA_event_queue event_queue = allua_check_event_queue(L, 1); al_flush_event_queue(event_queue); return 0; }
void correr(void){ const int CANTIBOTONES=4; ALLEGRO_TIMER *timer=NULL; ALLEGRO_EVENT_QUEUE *queue=NULL; ALLEGRO_BITMAP *main=NULL, *icons[CANTIBOTONES]; bool redraw=false; ALLEGRO_FONT *font=NULL; boton items[CANTIBOTONES]; void (*p2buttonf[CANTIBOTONES])(void); //create display, event queue and timer display = al_create_display(SCREEN_W, SCREEN_H); queue = al_create_event_queue(); timer = al_create_timer(1.0/FPS); //register events al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_timer_event_source(timer)); //load bitmap main=al_load_bitmap("main.jpg"); al_draw_bitmap(main,0,0,0); //mainfondo switch((wallnumber=get_wallp())){ // carga de wallpaper por archivo de configuracion case 1:cambiarfondo1(); break; case 2:cambiarfondo2(); break; case 3:cambiarfondo3(); break; case 4:cambiarfondo4(); break; } exitmenu=false; //wallpaper icon icons[0]=al_load_bitmap("wallpaper-icon.png"); botones(&items[0], 30,OFFSETDOWN-BUTTONSIZE-25, BUTTONSIZE, BUTTONSIZE); p2buttonf[0]=correrwallp; //message icon icons[1]=al_load_bitmap("message-icon.png"); botones(&items[1], 30*2+BUTTONSIZE*1,OFFSETDOWN-BUTTONSIZE-25, BUTTONSIZE, BUTTONSIZE); p2buttonf[1]=corrercontactos; //music icon icons[2]=al_load_bitmap("musica.png"); botones(&items[2], 30*3+BUTTONSIZE*2,OFFSETDOWN-BUTTONSIZE-25, BUTTONSIZE, BUTTONSIZE); p2buttonf[2]=corrermusica; //fractal icon icons[3]=al_load_bitmap("fractal.png"); botones(&items[3], 30*4+BUTTONSIZE*3,OFFSETDOWN-BUTTONSIZE-25, BUTTONSIZE, BUTTONSIZE); p2buttonf[3]=correrfractal; //start timer and font al_start_timer(timer); font=al_load_font("digital.ttf",72,0); while(!doexit) // main loop { ALLEGRO_EVENT ev; al_wait_for_event(queue, &ev); // espero a timer, salida o keyboard if(ev.type == ALLEGRO_EVENT_TIMER) redraw = true; // si es el timer de refresco, redibujo salio(ev);// salio del celular= presionobotones(ev, items, p2buttonf,CANTIBOTONES); // presiono en los icons al_flush_event_queue(queue); if(redraw){ // si hay que redibujar drawfondo();// fondo drawbotones(items, icons,CANTIBOTONES);// dibujo icons hora(font);//horario redraw=false; al_flush_event_queue(queue); al_flip_display();//flipeo } } al_destroy_display(display); al_destroy_timer(timer); al_destroy_bitmap(main); al_destroy_bitmap(mainfondo); al_destroy_event_queue(queue); }