//----------------------------DRAW LABYRINTHE - PLAYER - ENEMIES - UI void DrawLevel() { glPushMatrix(); if (inGame) { // Translate Map glTranslatef(-player.GetPos().x + (windowWidth / 2), -player.GetPos().y + (windowHeight / 2), 0); // Draw map lvl.DisplayMap(); //Draw Enemies lvl.DrawSpecialCases(); //Draw Enemies lvl.DrawEnemies(); if (player.GetPos().z == 1) { // If the player is UP // Draw UpCase under the player and his fire lvl.DrawUpCase(); } //Draw Fires lvl.DrawAllFires(); // Add player player.Draw(inGame); if (player.GetPos().z == 0) { // If the player is DOWN // Draw UpCase over the player and his fire lvl.DrawUpCase(); } glLoadIdentity(); glutSwapBuffers(); glPopMatrix(); //Draw HUD hud.displayScore(lvl.HUD_Score(), player.GetLife(), player.GetWeapon()); } else { lvl.DisplayMap(); //Draw Menu menu.Display(); // Add player player.Draw(inGame); glLoadIdentity(); glutSwapBuffers(); glPopMatrix(); } }
int main(){ // variables {{{1 int x=10; int y=10; int estado=2; ALLEGRO_DISPLAY *Screen; ALLEGRO_EVENT_QUEUE *qu; ALLEGRO_EVENT Event; ALLEGRO_TIMER *timer; ALLEGRO_BITMAP *Image = NULL; ALLEGRO_BITMAP *background= NULL; bool Exit = false; //}}}1 // Iniciando allegro {{{1 if(!al_init()){ cout<<"eror iniciando allegro"<<endl; return -1; } if(!al_init_image_addon()){ cout<<"error iniciando addon de imagenes"<<endl; return -1; } if(!al_init_primitives_addon()){ cout<<"Couldn't initialize primitives addon!\n"; return -1; } if(!al_install_keyboard()){ cout<<"error iniciando teclado"<<endl; return -1; } //}}}1 // pantalla y resoluciones {{{1 ALLEGRO_DISPLAY_MODE disp_data; int n=al_get_num_display_modes(); bool continuar_resolucion_w=false; bool continuar_resolucion_h=false; for(int i=0;i<n;i++){ al_get_display_mode(i, &disp_data); int w=disp_data.width; int h=disp_data.height; if(w==SWIDTH){ continuar_resolucion_w=true; } if(h==SHEIGHT){ continuar_resolucion_h=true; } } if(continuar_resolucion_w==false && continuar_resolucion_h==false){ cerr<<"resolucion no soportada"<<endl; return -1; } //al_set_new_display_flags(ALLEGRO_FULLSCREEN); Screen = al_create_display(SWIDTH,SHEIGHT); if(!Screen){ cout<<"no se pudo crear el display"<<endl; } //}}}1 // crear queue - timer screen keyboard {{{1 qu= al_create_event_queue(); if(!qu){ cout<<"error creando queue"<<endl; } al_register_event_source(qu, al_get_display_event_source(Screen)); timer = al_create_timer(1.0 / 35); if(!timer){ cout<<"error iniciando timer"<<endl; } al_register_event_source(qu, al_get_timer_event_source(timer)); al_register_event_source(qu, al_get_keyboard_event_source()); //}}}1 // iniciar clases y timer{{{1 // 0 inicio // 1 menu // 2 core Inicio inicio; Menu menu; Core core; inicio.Iniciar(); core.Iniciar_core(Screen); al_start_timer(timer); Image = al_load_bitmap("data/test.png"); ///load the bitmap from a file background= al_load_bitmap("data/background.png"); // ALLEGRO_COLOR clearcol=al_map_rgb(255,255,255); //}}}1 // main loop {{{1 while(Exit == false){ al_wait_for_event(qu, &Event); if(al_is_event_queue_empty(qu)){ if(estado==0){ inicio.Display(Screen); menu.Iniciar_menu(Screen); estado=1; } if(estado==1){ menu.Display(Screen); core.Iniciar_core(Screen); } if(estado==2){ x+=1; core.Animar(); al_draw_bitmap(background,0,0,0); core.Display(Screen); al_draw_bitmap(Image,x,y,0); } al_flip_display(); } if(Event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { Exit = true; } if(Event.type == ALLEGRO_EVENT_TIMER){ } if(Event.type==ALLEGRO_EVENT_KEY_DOWN){ Exit=true; } } return 0; }