int main(void) { ALLEGRO_FONT *font; ALLEGRO_DISPLAY *display; ALLEGRO_EVENT_QUEUE *event_queue; ALLEGRO_EVENT event; bool right_button_down = false; bool redraw = true; int fake_x = 0, fake_y = 0; ALLEGRO_COLOR white; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_primitives_addon(); al_init_font_addon(); al_init_image_addon(); al_install_mouse(); al_install_keyboard(); al_set_new_display_flags(ALLEGRO_WINDOWED); display = al_create_display(width, height); if (!display) { abort_example("Could not create display.\n"); return 1; } memset(&event, 0, sizeof(event)); event_queue = al_create_event_queue(); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_mouse_event_source()); al_register_event_source(event_queue, al_get_keyboard_event_source()); font = al_load_font("data/fixed_font.tga", 0, 0); white = al_map_rgb_f(1, 1, 1); while (1) { if (redraw && al_is_event_queue_empty(event_queue)) { int th = al_get_font_line_height(font); al_clear_to_color(al_map_rgb_f(0, 0, 0)); if (right_button_down) { al_draw_line(width / 2, height / 2, fake_x, fake_y, al_map_rgb_f(1, 0, 0), 1); al_draw_line(fake_x - 5, fake_y, fake_x + 5, fake_y, al_map_rgb_f(1, 1, 1), 2); al_draw_line(fake_x, fake_y - 5, fake_x, fake_y + 5, al_map_rgb_f(1, 1, 1), 2); } al_draw_textf(font, white, 0, 0, 0, "x: %i y: %i dx: %i dy %i", event.mouse.x, event.mouse.y, event.mouse.dx, event.mouse.dy); al_draw_textf(font, white, width / 2, height / 2 - th, ALLEGRO_ALIGN_CENTRE, "Left-Click to warp pointer to the middle once."); al_draw_textf(font, white, width / 2, height / 2, ALLEGRO_ALIGN_CENTRE, "Hold right mouse button to constantly move pointer to the middle."); al_flip_display(); redraw = false; } al_wait_for_event(event_queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; } if (event.type == ALLEGRO_EVENT_MOUSE_WARPED) { printf("Warp\n"); } if (event.type == ALLEGRO_EVENT_MOUSE_AXES) { if (right_button_down) { al_set_mouse_xy(display, width / 2, height / 2); fake_x += event.mouse.dx; fake_y += event.mouse.dy; } redraw = true; } if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if (event.mouse.button == 1) al_set_mouse_xy(display, width / 2, height / 2); if (event.mouse.button == 2) { right_button_down = true; fake_x = width / 2; fake_y = height / 2; } } if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { if (event.mouse.button == 2) { right_button_down = false; } } } al_destroy_event_queue(event_queue); al_destroy_display(display); return 0; }
int main(int argc, char **argv){ //tela ALLEGRO_DISPLAY *display = NULL; //fila de eventos detectados pelo Allegro (ex: tecla que foi apertada, clique do mouse etc) ALLEGRO_EVENT_QUEUE *event_queue = NULL; //temporizador: quando FPS = 10, a cada 0.1 segundos o tempo passa de t para t+1 e a fila de eventos detecta ALLEGRO_TIMER *timer = NULL; //figura do passaro ALLEGRO_BITMAP *bird = NULL; //variavel que indica se eh para redesenhar o passaro bool redraw = true; //------------------------------ rotinas de inicializacao ------------------------- //inicializa o allegro. Se nao conseguir, imprime na tela uma msg de erro. if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } //inicializa o temporizador com a taxa de 1 quadro a cada 0.1 segundos. Se nao conseguir, imprime na tela uma msg de erro. timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } //inicializa a tela. Se nao conseguir, imprime na tela uma msg de erro. display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(timer); return -1; } //inicializar o modulo de imagens al_init_image_addon(); //carregar a figura .jpg na variavel bird bird = al_load_bitmap("Angry-Bird.jpg"); //se nao conseguiu achar o arquivo, imprime uma msg de erro if(!bird) { fprintf(stderr, "failed to create bird bitmap!\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } //largura e altura da figura do passaro float largura_passaro = al_get_bitmap_width(bird); float altura_passaro = al_get_bitmap_height(bird); //posicao x e y inicial do passaro na tela float bird_x = 0; float bird_y = SCREEN_H / 2.0 - altura_passaro / 2.0; //variacao de x e y ao longo do tempo float bird_dx = 1.0, bird_dy = 0.0; //criar a fila de eventos event_queue = al_create_event_queue(); //se nao conseguiu criar a fila de eventos if(!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); al_destroy_bitmap(bird); al_destroy_display(display); al_destroy_timer(timer); return -1; } //registrar mudancas na tela dentro da fila de eventos, isto e, sempre que a tela mudar, um evento ocorrerah al_register_event_source(event_queue, al_get_display_event_source(display)); //coloca o timer na fila de eventos, isto e, sempre que o tempo passar, um evento eh gerado al_register_event_source(event_queue, al_get_timer_event_source(timer)); //limpa a tela e coloca o fundo preto, cor: rgb(0,0,0) = preto al_clear_to_color(al_map_rgb(0,0,0)); //reinicializa a tela al_flip_display(); //inicia o temporizador al_start_timer(timer); //enquanto a posicao x do passaro for menor que a largura da tela while(bird_x < SCREEN_W) { //variavel do tipo evento ALLEGRO_EVENT ev; //a variavel ev recebe o primeiro evento da fila de eventos al_wait_for_event(event_queue, &ev); //se for um evento de timer, ou seja, se foi o tempo que passou de t para t+1 if(ev.type == ALLEGRO_EVENT_TIMER) { //incrementa as posicoes x e y do passaro com o seu deslocamento dx e dy bird_x += bird_dx; bird_y += bird_dy; //como eu movi o passaro, preciso redesenhar ele (remova essa linha e veja o que acontece) redraw = true; } //se o evento for o fechamento da tela (clicando no x no canto superior direito) else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE ) { //paro de executar o while break; } //se for para eu redesenhar a tela e nao tenho mais nenhum evento para ler if(redraw && al_is_event_queue_empty(event_queue)) { //nao preciso redesenhar redraw = false; //limpo a tela al_clear_to_color(al_map_rgb(0,0,0)); //desenho o passaro na nova posicao al_draw_bitmap(bird, bird_x, bird_y, 0); //dou um refresh na tela al_flip_display(); } } //fim while //rotinas de fim de jogo al_destroy_bitmap(bird); al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
int main() { bool menu = true; char pontuacao[100]; char vida[100]; ALLEGRO_COLOR font_color; ALLEGRO_FONT *font,*font2; ALLEGRO_AUDIO_STREAM *musica = NULL; camera *cam = camera_inicializa(0); if(!cam) erro("erro na inicializacao da camera\n"); int x = 0, y = 0; int largura = cam->largura; int altura = cam->altura; int fps = 0,tempo = 5; int ndisco = 9; if(!al_init()) erro("erro na inicializacao do allegro\n"); if(!al_init_image_addon()) erro("erro na inicializacao do adicional de imagem\n"); al_init_font_addon(); al_init_ttf_addon(); font_color = al_map_rgb(0, 0, 0); font = al_load_ttf_font("Fontes/Blokletters-Viltstift.ttf", 20, 0); font2 = al_load_ttf_font("Fontes/Blokletters-Viltstift.ttf", 50, 0); if(!al_init_primitives_addon()) erro("erro na inicializacao do adicional de primitivas\n"); ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); if(!timer) erro("erro na criacao do relogio\n"); ALLEGRO_DISPLAY *display = al_create_display(2 * largura,altura); if(!display) erro("erro na criacao da janela\n"); ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); if(!queue) erro("erro na criacao da fila\n"); if (!al_install_audio()) { fprintf(stderr, "Falha ao inicializar áudio.\n"); return false; } if (!al_init_acodec_addon()) { fprintf(stderr, "Falha ao inicializar codecs de áudio.\n"); return false; } if (!al_reserve_samples(1)) { fprintf(stderr, "Falha ao alocar canais de áudio.\n"); return false; } musica = al_load_audio_stream("Audio/elementary.ogg", 4, 1024); if(!musica) erro("Erro na alocação da musica de fundo\n"); al_attach_audio_stream_to_mixer(musica, al_get_default_mixer()); al_set_audio_stream_playing(musica, true); al_register_event_source(queue, al_get_timer_event_source(timer)); al_register_event_source(queue, al_get_display_event_source(display)); al_start_timer(timer); unsigned char ***matriz = camera_aloca_matriz(cam); ALLEGRO_BITMAP *buffer = al_get_backbuffer(display); ALLEGRO_BITMAP *fundo = al_load_bitmap("Imagens/Elementary2.png"); if(!fundo) erro("erro ao carregar Elementary.png"); ALLEGRO_BITMAP *esquerda = al_create_sub_bitmap(buffer, 0, 0, largura, altura); ALLEGRO_BITMAP *direita = al_create_sub_bitmap(buffer, largura, 0, largura, altura); /**********/ Disco *discos[9]; bool perdeu = false; carregarDiscos(discos); int pontos=0,velo = 1; int aux1 = 1; int vidas = 10; int ultimoDisco = 0; int distance = 0; int desenhar = 0; int terminar = 0; al_set_target_bitmap(esquerda); al_draw_bitmap(fundo,0,0,0); while(1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); switch(event.type) { case ALLEGRO_EVENT_TIMER: desenhar = 1; break; case ALLEGRO_EVENT_DISPLAY_CLOSE: terminar = 1; break; } if(terminar) break; if(desenhar && al_is_event_queue_empty(queue)) { desenhar = 0; camera_atualiza(cam); mediana(cam); /**********/ al_set_target_bitmap(esquerda); al_draw_bitmap(fundo,0,0,0); if(!menu){ while(aux1 <= ndisco){ if(discos[aux1]->status == false){ if(distance > 50 || ultimoDisco==0 ){ printf("%d\n",aux1 ); al_draw_bitmap(discos[aux1]->elemento,discos[aux1]->pos_x,discos[aux1]->pos_y,0); discos[aux1]->status = true; distance = 0; ultimoDisco = aux1; break; }else aux1++; }else{ discos[aux1]->pos_y+=(10+velo); al_draw_bitmap(discos[aux1]->elemento,discos[aux1]->pos_x,discos[aux1]->pos_y,0); aux1++; } } distance = discos[ultimoDisco]->pos_y; for(aux1 = 1;aux1<ndisco;aux1++){ if(discos[aux1]->pos_x >= x-30 && discos[aux1]->pos_x <= x+30 && discos[aux1]->pos_y >= y-30 && discos[aux1]->pos_y <= y+30){ if(discos[aux1]->tipo == 2){ // Tipo do fogo(Necessario para vencer o jogo) pontos +=10; velo += 1; discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; }else if(discos[aux1]->tipo == 1){ //Tipo da agua(Perde o jogo se destruir esse disco) discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; al_flip_display(); vidas--; }else if(discos[aux1]->tipo == 3){//Tipo planta(Aumenta velocidade de queda das peças) velo *= 2; discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; } }else if( discos[aux1]->pos_y > 480){ if(discos[aux1]->tipo == 2){ //Tipo da agua e Planta(Não perde se deixar cair) discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; al_flip_display(); vidas--; }else{ discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; } } } aux1 = 1; sprintf(pontuacao,"PONTUAÇÃO: %d",pontos); al_draw_text(font, al_map_rgb(255, 255, 255), 50, 5, 0,pontuacao); sprintf(vida,"VIDAS: %d",vidas); al_draw_text(font, al_map_rgb(255, 255, 255), 300, 5, 0,vida); al_flip_display(); } if(perdeu){ al_draw_text(font2, al_map_rgb(255, 0, 0), 50, 100, 0,"PONTUAÇÃO FINAL"); sprintf(pontuacao,"%d",pontos); al_draw_text(font2, al_map_rgb(255, 0, 0), 250, 170, 0,pontuacao); al_flip_display(); al_rest(3); break; } if(vidas == 0){ perdeu = true; } if(menu){ if(abrirJogo(x,y,&fps,&tempo,font,font2, font_color)){ fundo = al_load_bitmap("Imagens/galaxia.png"); menu = false; } } cameraRastreia(cam,&x,&y); al_set_target_bitmap(direita); camera_copia(cam, cam->quadro, direita); al_flip_display(); } } al_destroy_bitmap(direita); al_destroy_bitmap(fundo); al_destroy_bitmap(esquerda); camera_libera_matriz(cam, matriz); int fri = 9; while(fri != 0){ free(discos[fri]); fri--; } al_stop_timer(timer); al_unregister_event_source(queue, al_get_display_event_source(display)); al_unregister_event_source(queue, al_get_timer_event_source(timer)); al_destroy_event_queue(queue); al_destroy_display(display); al_destroy_timer(timer); al_destroy_audio_stream(musica); al_shutdown_primitives_addon(); al_shutdown_image_addon(); al_uninstall_system(); camera_finaliza(cam); return EXIT_SUCCESS; }
int main() { const float FPS = 60.0; if(!al_init()) { al_show_native_message_box(NULL, "Fatal Error", NULL, "No se pudo inicializar Allegro", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_set_new_display_flags(ALLEGRO_WINDOWED); // Pone la ventana en modo Windowed ALLEGRO_DISPLAY *display = al_create_display(ScreenWidth, ScreenHeight); // Pone la posición en la que debe salir l`a ventana //al_set_window_position(display, 0, 30); // Pone el título de la ventana al_set_window_title(display, "Killer Bunny"); if(!display) // Si no se pudo crear la ventana, entonces pone un mensaje de error { al_show_native_message_box(NULL, "Error", NULL, "No se pudo crear la pantalla", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_install_keyboard(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_init_primitives_addon(); // ----------------------------------------------------------------- ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS); ALLEGRO_KEYBOARD_STATE keyState; // Utilizado para debugging ALLEGRO_FONT *font = al_load_font("sprites/DroidSans.ttf", 10, 0); ALLEGRO_BITMAP *fondo1 = al_load_bitmap("sprites/fondo1.png"); bool done = false; // ---------Estructuras del juego----------------------------------- struct Player player; player.image = al_load_bitmap("sprites/player.png"); al_convert_mask_to_alpha(player.image, al_map_rgb(255,255,255)); player.x = ScreenWidth / 2; player.y = ScreenHeight / 2; player.w = al_get_bitmap_width(player.image); player.h = al_get_bitmap_height(player.image); player.moveSpeed = 3; player.degrees = -ALLEGRO_PI/2; player.alive = true; player.clip = 6; player.vida = 100; struct Bala bala; //~ void Bala::update() //~ { //~ bala.dx = cosf(player.xmouse - player.x); //~ bala.dy = senf(player.ymouse - player.y); //~ //~ if(bala.shot){ //~ //~ bala.x += bala.dx; //~ bala.y += bala.dy; //~ } //~ //~ } bala.image = al_load_bitmap("sprites/bullet.png"); bala.x = player.x+50; bala.y = player.y+25; bala.shot = false; struct Enemigo robot; robot.image = al_load_bitmap("sprites/Robot_sprites.png"); robot.death = al_load_bitmap("sprites/explosiondelrobot.png"); al_convert_mask_to_alpha(robot.death, al_map_rgb(255, 255, 255)); //al_convert_mask_to_alpha(robot.image, al_map_rgb(255,255,255)); robot.x = 50; robot.y = 50; robot.w = al_get_bitmap_width(robot.image); robot.h = al_get_bitmap_height(robot.image); robot.velocidad_x = 0.23; robot.velocidad_y = 0.23; robot.fuerza= 0.5; robot.vida=50; //~ void Weapon::recargar() //~ { //~ for(int i = 0; i < 6; i++) //~ { //~ bullets[i] = bala; //~ } //~ } // ----------------------------------------------------------------- // Esta variable guardará los eventos del mouse ALLEGRO_MOUSE_STATE mouseState; // Registro varias fuentes de eventos al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_mouse_event_source()); // Inicializo el temporizador principal al_start_timer(timer); while(!done) { // La variable de los eventos ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); // Y aquí espero por los eventos if(ev.type == ALLEGRO_EVENT_TIMER) { // Dos funciones para pasar eventos del mouse y del teclado al_get_keyboard_state(&keyState); al_get_mouse_state(&mouseState); // Esto detecta la posición del mouse y lo guarda a un par de variables player.xmouse = al_get_mouse_state_axis(&mouseState, 0); player.ymouse = al_get_mouse_state_axis(&mouseState, 1); // Si presiono Esc entonces me saca del juego if(al_key_down(&keyState, ALLEGRO_KEY_ESCAPE)) { done = true; } // Si presiono A entonces el valor x se reduce, osea, se va a la izquierda if(al_key_down(&keyState, ALLEGRO_KEY_A)) { player.x -= player.moveSpeed; } // Si... meh, ya sabes lo que sigue if(al_key_down(&keyState, ALLEGRO_KEY_D)) { player.x += player.moveSpeed; } // ... if(al_key_down(&keyState, ALLEGRO_KEY_W)) { player.y -= player.moveSpeed; } // ... if(al_key_down(&keyState, ALLEGRO_KEY_S)) { player.y += player.moveSpeed; } // Mata al robot if(al_key_down(&keyState, ALLEGRO_KEY_K)) { robot.vida -= 10; } } // Esto permite que el jugador se mueva con el mouse player.degrees = atan2((player.ymouse-player.y),(player.xmouse-player.x)); // La Inteligencia Artificial del enemigo if(robot.alive && player.alive){ if(robot.x < player.x) robot.x += robot.velocidad_x; if(robot.x > player.x) robot.x -= robot.velocidad_x; if(robot.y > player.y) robot.y -= robot.velocidad_y; if(robot.y < player.y) robot.y += robot.velocidad_y; } // Uso de las funciones para las colisiones //if(Collision(player.x, player.y, 50, 50, robot.x, robot.y, 34, 34)) player.alive = false; if(PixelCol(player.image, robot.image, player.x-(player.w/2), player.y-(player.h/2), player.w, player.h, robot.x, robot.y, robot.w/7, robot.h)) player.vida -= robot.fuerza; if(player.vida==0) player.alive = false; if(robot.vida<=0){ robot.vida = 0; robot.alive = false; } al_clear_to_color(al_map_rgb(255, 255, 255)); // Se pinta todo a negro al_draw_scaled_bitmap(fondo1,0, 0, 256, 256, 0, 0, ScreenWidth, ScreenHeight, 0); // Se dibuja el fondo if(player.alive){ // Si el jugador está vivo al_draw_rotated_bitmap(player.image, 25, 25, player.x, player.y, player.degrees, 0); // Dibujo el jugador al_draw_rotated_bitmap(bala.image, 0, 0, player.x+5, player.y+5, player.degrees, 0); // Dibujo la bala (esto hay que quitarlo) } if(robot.alive){ al_draw_bitmap_region(robot.image, 0, 0, 60, 52, robot.x, robot.y, 0); // Dibujo el robot } else { robot.w = al_get_bitmap_width(robot.death); robot.h = al_get_bitmap_width(robot.death); al_draw_bitmap_region(robot.death, 0, 0, robot.w/4, robot.h, robot.x, robot.y, 0); } // Esto es para el debugging // Dibujo rectángulos para las colisiones al_draw_rectangle(player.x-(player.w/2), player.y-(player.h/2), (player.x+player.w)-(player.w/2), (player.y+player.h)-(player.h/2), al_map_rgb(0, 255, 0), 1.0); al_draw_rectangle(robot.x, robot.y, robot.x+(robot.w/7), robot.y+robot.h, al_map_rgb(0, 255, 0), 1.0); // Escribo en una esquina de la pantalla, información respecto al personaje al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 2, ALLEGRO_ALIGN_RIGHT, "Player x, y : %.1f %.1f", player.x, player.y); al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 12, ALLEGRO_ALIGN_RIGHT, "Rotation (rad): %.5f", player.degrees); al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 22, ALLEGRO_ALIGN_RIGHT, "Rotation (degrees): %.2f", (player.degrees*180)/ALLEGRO_PI); // Status bar al_draw_filled_rectangle(0,0,player.vida*2,15, al_map_rgb(0,255,0)); // Actualizo la pantalla (flip) al_flip_display(); } //-----After party (hay que limpiar)-------------------------------- // A destruirlo todo!! BAM BAM BAM, KABOOM!! al_destroy_font(font); al_destroy_bitmap(fondo1); al_destroy_bitmap(robot.image); al_destroy_display(display); al_destroy_event_queue(event_queue); al_destroy_bitmap(player.image); al_destroy_timer(timer); return 0; }
int main() { const float FPS = 60.0f; ALLEGRO_DISPLAY *display; if(!al_init()) { al_show_native_message_box(NULL,"Error","Error", "Cannot initialize Allegro",NULL,NULL); return -1; } display = al_create_display(ScreenWidth, ScreenHeight); if(!display) { al_show_native_message_box(NULL,"Error","Error", "Cannot create display",NULL,NULL); return -1; } al_install_keyboard(); al_install_mouse(); al_init_font_addon(); al_init_ttf_addon(); al_init_image_addon(); //al_init_acodec_addon(); ALLEGRO_TIMER *timer = al_create_timer(1.0f / FPS); ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); ALLEGRO_KEYBOARD_STATE keystate; al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_display_event_source(display)); InputManager input; ScreenManager::GetInstance().Initialize(); ScreenManager::GetInstance().LoadContent(); bool done = false; al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); al_start_timer(timer); while(!done) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); al_get_keyboard_state(&keystate); if(input.IsKeyPressed(ev, ALLEGRO_KEY_ESCAPE)) done = true; else if(input.IsKeyReleased(ev, ALLEGRO_KEY_SPACE)) done = true; if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) done = true; ScreenManager::GetInstance().Update(ev); ScreenManager::GetInstance().Draw(display); al_flip_display(); al_clear_to_color(al_map_rgb(0,0,0)); } ScreenManager::GetInstance().UnloadContent(); al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); return 0; }
int main(void) { bool done = false; // Variavel booleana para identificar se o programa terminou de ser executado bool redraw = true; // Enquanto essa variavel for verdadeira, ira ser desenhado algo na tela bool desenha = true; int draw[5]= {0, 0, 0, 0, 0}; int pos_x = WIDTH / 2; int pos_y = HEIGHT / 2; int timer_tiros = 0; int timer_energy = 0; int timer_heats = 0; int timer_tamenho_heat = 0; int timer_componente = 0; int count = 0; Gamer(gamer); Zone zone[LINHAS][COLUNAS]; Bullet bullets[NUM_BULLETS+1]; Energy energy[NUM_ENERGYS+1]; Heat heats[NUM_HEAT+1]; Zombie zombie[NUM_ZOMBIES]; Battery battery[NUM_BATTERY]; ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_FONT *font18 = NULL; ALLEGRO_FONT *font_maior = NULL; ALLEGRO_BITMAP *resistor = NULL; ALLEGRO_BITMAP *capacitor = NULL; ALLEGRO_BITMAP *indutor = NULL; ALLEGRO_BITMAP *diodo = NULL; ALLEGRO_BITMAP *bateria = NULL; ALLEGRO_BITMAP *protoboard = NULL; ALLEGRO_BITMAP *fogo = NULL; ALLEGRO_BITMAP *zombie_bitmap = NULL; ALLEGRO_BITMAP *ataque_eletromagnetico = NULL; ALLEGRO_BITMAP *energia_capacitor = NULL; ALLEGRO_BITMAP *logo = NULL; if(!al_init()) //initialize Allegro return -1; display = al_create_display(WIDTH, HEIGHT); //create our display object if(!display) //test display object return -1; al_init_primitives_addon(); al_install_keyboard(); al_init_font_addon(); al_init_ttf_addon(); al_install_mouse(); al_init_image_addon(); resistor = al_load_bitmap("Resistor.png"); capacitor = al_load_bitmap("Capacitor.png"); indutor = al_load_bitmap("Indutor.png"); diodo = al_load_bitmap("Diodo.png"); bateria = al_load_bitmap("Bateria.png"); protoboard = al_load_bitmap("Protoboard.png"); fogo = al_load_bitmap("fogo_resistor/fire1.png"); zombie_bitmap = al_load_bitmap("Zombie.png"); ataque_eletromagnetico = al_load_bitmap("eletromagnetismo.jpg"); energia_capacitor = al_load_bitmap("energia_capacitor.png"); logo = al_load_bitmap("logo_EvsZ.jpg"); al_convert_mask_to_alpha(resistor, al_map_rgb(255, 0, 255)); al_convert_mask_to_alpha(capacitor, al_map_rgb(255, 0, 255)); al_convert_mask_to_alpha(indutor, al_map_rgb(255, 0, 255)); al_convert_mask_to_alpha(diodo, al_map_rgb(255, 0, 255)); al_convert_mask_to_alpha(bateria, al_map_rgb(255, 0, 255)); al_convert_mask_to_alpha(zombie_bitmap, al_map_rgb(255, 255, 255)); al_convert_mask_to_alpha(ataque_eletromagnetico, al_map_rgb(255, 255, 255)); event_queue = al_create_event_queue(); timer = al_create_timer(1.0 / FPS); InitGamer(gamer); InitZone(zone, LINHAS, COLUNAS); InitBullet(bullets, NUM_BULLETS+1); InitHeat(heats, NUM_HEAT+1); InitZombie(zombie, NUM_ZOMBIES); InitEnergy(energy, NUM_ENERGYS+1); InitBattery(battery, NUM_BATTERY); font18 = al_load_font("arial.ttf", 18, 0); font_maior = al_load_font("arial.ttf", 24, 0); al_register_event_source(event_queue, al_get_mouse_event_source()); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_display_event_source(display)); al_hide_mouse_cursor(display); al_start_timer(timer); while(!done) { ALLEGRO_EVENT ev; /*===============================================================================================================================================*/ if(state == MENU) { al_wait_for_event(event_queue, &ev); al_draw_bitmap(logo, WIDTH / 2 - 145, HEIGHT - 500, 0); al_draw_text(font18, al_map_rgb(255, 255, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Os Zombies querem roubar seu diploma, proteja-o"); al_draw_text(font18, al_map_rgb(0, 255, 255), WIDTH / 2, HEIGHT / 2 + 100, ALLEGRO_ALIGN_CENTRE, "Pressione Space para jogar"); al_draw_text(font_maior, al_map_rgb(0, 255, 0), WIDTH / 2, HEIGHT / 2 + 150, ALLEGRO_ALIGN_CENTRE, "Tecla 1 = Resistor Tecla 2 = Capacitor Tecla 3 = Indutor Tecla 4 = Diodo"); if(ev.type == ALLEGRO_EVENT_KEY_DOWN) if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE) state = PLAYING; if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) done = true; al_flip_display(); } /*===============================================================================================================================================*/ if(state == PLAYING) { al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) done = true; if(ev.type == ALLEGRO_EVENT_TIMER) { redraw = true; for(int i = 0; i < LINHAS; i++) for(int j=0; j<COLUNAS; j++) if(zone[i][j].x < pos_x && zone[i][j].x + ZONEX > pos_x && zone[i][j].y < pos_y && zone[i][j].y + ZONEY > pos_y) if(desenha) if(zone[i][j].draw == 0) { if(keys[KEY_1] && gamer.energy >= 100) { zone[i][j].draw = draw[1]; gamer.energy -=100; draw[1] = 0; } if(keys[KEY_2] && gamer.energy >= 50) { zone[i][j].draw = draw[2]; gamer.energy -=50; draw[2] = 0; } if(keys[KEY_3] && gamer.energy >= 100) { zone[i][j].draw = draw[3]; gamer.energy -=100; draw[3] = 0; } if(keys[KEY_4] && gamer.energy >= 100) { zone[i][j].draw = draw[4]; gamer.energy -=100; draw[4] = 0; } } timer_battery_speed++; timer_battery_start++; if(timer_battery_start >= 360) // diminui a frequencia com que nasce uma bateria nova { StartBattery(battery, NUM_BATTERY); timer_battery_start = 0; } if(timer_battery_speed >= 2) // reduz um pouco a velocidade da bateria { UpdateBattery(battery, NUM_BATTERY); timer_battery_speed = 0; } timer_heats++; for(int i=0; i<LINHAS; i++) for(int j=0; j<COLUNAS; j++) if(zone[i][j].draw == 1) if(timer_heats >= 200) { FireHeat(heats, NUM_HEAT+1, zone); timer_heats = 0; } timer_energy++; timer_energy_cap_death++; for(int i=0; i<LINHAS; i++) for(int j=0; j<COLUNAS; j++) if(zone[i][j].draw == 2) { if(timer_energy >= 420) { CreateEnergy(energy, NUM_ENERGYS+1, zone); timer_energy = 0; } } timer_tiros++; for(int i=0; i<LINHAS; i++) for(int j=0; j<COLUNAS; j++) if(zone[i][j].draw == 3) if(timer_tiros >= 200) // faz os Electronics atirarem numa velocidade constante { FireBullet(bullets, NUM_BULLETS+1, zone); timer_tiros = 0; } timer_zombie_start++; timer_zombie_speed++; timer_dificuldade++; if(timer_zombie_start >= 3) { StartZombie(zombie, NUM_ZOMBIES); timer_zombie_start = 0; } if(dificuldade >20 && dificuldade <=500) { if(timer_dificuldade >= 300) { dificuldade -= 30; timer_dificuldade = 0; } } if(timer_zombie_speed >= 3) { UpdateZombie(zombie, NUM_ZOMBIES); timer_zombie_speed = 0; } UpdateBullet(bullets, NUM_BULLETS+1); CollideBullet(bullets, NUM_BULLETS, zombie, NUM_ZOMBIES, gamer); CollideHeat(heats, NUM_HEAT, zombie, NUM_ZOMBIES, gamer, timer_tamenho_heat); CollideZone(zone, LINHAS, COLUNAS, zombie, NUM_ZOMBIES); CollideZoneDiodo(zone, LINHAS, COLUNAS, zombie, NUM_ZOMBIES); for(int i = 0; i < NUM_ENERGYS; i++) if(energy[i].live) if(energy[i].x - energy[i].boundx < pos_x && energy[i].x + energy[i].boundx > pos_x && energy[i].y - energy[i].boundy < pos_y && energy[i].y + energy[i].boundy > pos_y) { energy[i].live = false; gamer.energy += 25; } } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_1: keys[KEY_1] = true; break; case ALLEGRO_KEY_2: keys[KEY_2] = true; break; case ALLEGRO_KEY_3: keys[KEY_3] = true; break; case ALLEGRO_KEY_4: keys[KEY_4] = true; break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_1: keys[KEY_1] = false; break; case ALLEGRO_KEY_2: keys[KEY_2] = false; break; case ALLEGRO_KEY_3: keys[KEY_3] = false; break; case ALLEGRO_KEY_4: keys[KEY_4] = false; break; } } else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if (ev.mouse.button & 2) done = true; } else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES) { pos_x = ev.mouse.x; pos_y = ev.mouse.y; CaptureBattery(battery, NUM_BATTERY, ev.mouse.x, ev.mouse.y, gamer); } timer_componente++; if(timer_componente >= 10) { if(keys[KEY_1]) draw[1] = 1; if(keys[KEY_2]) draw[2] = 2; if(keys[KEY_3]) draw[3] = 3; if(keys[KEY_4]) draw[4] = 4; } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; DrawZone(zone, LINHAS, COLUNAS, resistor, capacitor, indutor, diodo); DrawBullet(bullets, NUM_BULLETS+1, ataque_eletromagnetico); DrawEnergy(energy, NUM_ENERGYS+1, energia_capacitor); DrawZombie(zombie, NUM_ZOMBIES, zombie_bitmap); DrawBattery(battery, NUM_BATTERY, bateria); timer_tamenho_heat++; DrawHeat(heats, NUM_HEAT+1, timer_tamenho_heat, fogo); if(timer_tamenho_heat > 80) for(int i=0; i<NUM_HEAT; i++) { heats[i].live = false; timer_tamenho_heat = 0; } al_draw_filled_rectangle(pos_x, pos_y, pos_x + 10, pos_y + 10, al_map_rgb(0, 0, 0)); count++; al_draw_textf(font18, al_map_rgb(255, 0, 0), WIDTH*13/16, 85, 0, "Time: %i", count/60); al_draw_textf(font18, al_map_rgb(255, 0, 0), WIDTH*13/300, 85, 0, "Energy: %i", gamer.energy); al_draw_textf(font18, al_map_rgb(255, 0, 0), WIDTH*13/25, 85, 0, "Score: %i", gamer.score); al_flip_display(); al_draw_bitmap(protoboard, 0, 0, 0); } } /*================================================================================================================================================*/ if(state == GAMEOVER) { al_wait_for_event(event_queue, &ev); al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(font18, al_map_rgb(255, 168, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Os Zombies roubaram seu diploma"); al_draw_text(font18, al_map_rgb(255, 255, 255), WIDTH / 2, HEIGHT / 2 +40, ALLEGRO_ALIGN_CENTRE, "Pressione Space para sair"); al_draw_textf(font_maior, al_map_rgb(255, 0, 0), WIDTH*13/28, 85, 0, "Score: %i", gamer.score); al_flip_display(); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) done = true; if(ev.type == ALLEGRO_EVENT_KEY_DOWN) if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE) { al_destroy_event_queue(event_queue); al_destroy_timer(timer); al_destroy_font(font18); al_destroy_bitmap(resistor); al_destroy_bitmap(capacitor); al_destroy_bitmap(indutor); al_destroy_bitmap(diodo); al_destroy_bitmap(bateria); al_destroy_bitmap(protoboard); al_destroy_bitmap(zombie_bitmap); al_destroy_display(display); } } } return 0; }
int main(int argc, char **argv) { //-------------------------------------------------------------------------------------------------------------------------------- #pragma region "Variable Initialization" const float FPS = 60; int screenw = 900; int screenh = 650; float bounce = 32; float bouncer_x = screenw / 2.0 - bounce / 2.0; float bouncer_y = screenh / 2.0 - bounce / 2.0; float wall1_x = 30.0; float wall1_y = 40.0; float wall1_w = 30.0; float wall1_h = 30.0; bool key[4] = { false, false, false, false }; bool redraw = true; bool exiting = false; bool menu = false; enum MYKEYS { KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT }; pac game; game.setpacmanx(bouncer_x); game.setpacmany(bouncer_y); ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_BITMAP *bouncer = NULL; ALLEGRO_BITMAP *wall1 = NULL; #pragma endregion //-------------------------------------------------------------------------------------------------------------------------------- #pragma region "System Protection" // Begining Initialization // Checks if Allegro is initialized if (!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } //Checks if keyboard is initialized if (!al_install_keyboard()) { fprintf(stderr, "failed to initialize the keyboard!\n"); return -1; } //Checks if mouse is initialized if (!al_install_mouse()) { fprintf(stderr, "failed to initialize the mouse!\n"); return -1; } //Intializes timer to fps and then checks if there is a timer timer = al_create_timer(1.0 / FPS); if (!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } //checks if there is a display display = al_create_display(screenw , screenh); if (!display) { fprintf(stderr, "failed to create display!\n"); return -1; } al_init_font_addon(); al_init_ttf_addon(); ALLEGRO_FONT *font = al_load_ttf_font("DroidSans.ttf", 36, 0); ALLEGRO_FONT *font2 = al_load_ttf_font("DroidSans.ttf", 12, 0); if (!font){ fprintf(stderr, "Could not load 'pirulen.ttf'.\n"); return -1; } bouncer = al_create_bitmap(bounce, bounce); if (!bouncer) { fprintf(stderr, "failed to create bouncer bitmap!\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } wall1 = al_create_bitmap(wall1_w, wall1_h); if (!bouncer) { fprintf(stderr, "failed to create bouncer bitmap!\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_init_image_addon(); ALLEGRO_DISPLAY_MODE disp_data; al_get_display_mode(al_get_num_display_modes() - 1, &disp_data); al_set_target_bitmap(bouncer); al_clear_to_color(al_map_rgb(255, 0, 0)); al_set_target_bitmap(al_get_backbuffer(display)); al_set_target_bitmap(wall1); al_clear_to_color(al_map_rgb(0, 0, 255)); al_set_target_bitmap(al_get_backbuffer(display)); event_queue = al_create_event_queue(); if (!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); al_destroy_bitmap(bouncer); al_destroy_display(display); al_destroy_timer(timer); return -1; } #pragma endregion //-------------------------------------------------------------------------------------------------------------------------------- #pragma region "Event Initialization" al_register_event_source(event_queue, al_get_display_event_source(display)); //display event handler al_register_event_source(event_queue, al_get_timer_event_source(timer)); //time envent handler al_register_event_source(event_queue, al_get_keyboard_event_source()); //keyboard event handler al_register_event_source(event_queue, al_get_mouse_event_source()); //mouse event handler al_clear_to_color(al_map_rgb(0, 0, 0)); al_flip_display(); al_start_timer(timer); #pragma endregion //-------------------------------------------------------------------------------------------------------------------------------- #pragma region "Simple Menu" while (!menu) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if (ev.type == ALLEGRO_EVENT_KEY_UP) { if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_ENTER: menu = true; break; } } } else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } if (redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(255, 255, 255)); al_draw_text(font, al_map_rgb(0, 0, 0), screenw / 2, (screenh / 2), ALLEGRO_ALIGN_CENTRE, "Press Enter to Start"); al_flip_display(); } } #pragma endregion //-------------------------------------------------------------------------------------------------------------------------------- #pragma region "Driver Program" while (!exiting) { #pragma region "Timer Events" ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if (ev.type == ALLEGRO_EVENT_TIMER) { if(key[KEY_UP] && game.getpacmany() >= 4.0) { game.uppacman(); } if (key[KEY_DOWN] && game.getpacmany() <= screenh - bounce - 4.0) { game.downpacman(); } if (key[KEY_LEFT] && game.getpacmanx() >= 4.0) { game.leftpacman(); } if (key[KEY_RIGHT] && game.getpacmany() <= screenw - bounce - 4.0) { game.rightpacman(); } redraw = true; } // "Closes the Window When Pressing X button" else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } #pragma endregion #pragma region "Checks for when key was pressed down" else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = true; break; case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = true; break; } } #pragma endregion #pragma region "Checks for when key was released" else if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = false; break; case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = false; break; case ALLEGRO_KEY_ESCAPE: exiting = true; break; case ALLEGRO_KEY_Q: exiting = true; break; //Full screen when f is pressed case ALLEGRO_KEY_F: if (screenw != disp_data.width) { al_set_new_display_flags(ALLEGRO_FULLSCREEN); display = al_create_display(disp_data.width, disp_data.height); screenw = disp_data.width; screenh = disp_data.height; wall1_x = 2 * (screenw / 10); wall1_y = (screenh / screenh) + 50 * (screenh / screenh); } break; //Normal screen when n is pressed case ALLEGRO_KEY_N: if (screenw != 640) { al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); display = al_create_display(640, 480); screenw = 640; screenh = 480; } break; } } #pragma endregion #pragma region "Redraw Objects" if (redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_bitmap(wall1, wall1_x, wall1_y, 0); al_draw_bitmap(bouncer, game.getpacmanx(), game.getpacmany(), 0); al_draw_text(font2, al_map_rgb(255, 0, 0), screenw / 2, (screenh / screenh), ALLEGRO_ALIGN_CENTRE, "Moving a Square"); al_flip_display(); } #pragma endregion } #pragma endregion //-------------------------------------------------------------------------------------------------------------------------------- #pragma region "Destroyers" al_destroy_bitmap(bouncer); al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); #pragma endregion return 0; }
int main(void){ //allegro variables ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_BITMAP *bg = NULL; ALLEGRO_TIMER *timer; //program init if(!al_init()) //initialize Allegro return -1; display = al_create_display(WIDTH, HEIGHT); //create our display object if(!display) //test display object return -1; //============================================== //ADDON INSTALL //============================================== al_install_keyboard(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_init_primitives_addon(); // FONT DEL PROGRAMA. ALLEGRO_FONT *font = al_load_ttf_font("Sarpanch-SemiBold.ttf",30,0 ); // VARIABLES DEL JUEGO ======================== bg = al_load_bitmap("img/sp1.jpg"); SpaceShip nave_jugador; Enemy enemies1[10]; Enemy enemies2[10]; Enemy enemies3[10]; Enemy enemies4[10]; Enemy jefe1[10]; Bullet bullets[5]; char vidas_char[2]; // INICIALIZAR OBJETOS==================== InitShip(nave_jugador); InitBullet(bullets, NUM_BULLETS); InitEnemies(enemies1,ENM1,10,0,220,WIDTH/2); InitEnemies(enemies2,ENM2,8,50,180,WIDTH/2+100); InitEnemies(enemies3,ENM3,6,100,140,WIDTH); InitEnemies(enemies4,ENM4,4,150,100,(WIDTH/2)+100); InitEnemies(jefe1,JEFE,2,200,60); //DrawEnemies(enemies,NUM_ENEMIES); //============================================== //TIMER INIT AND STARTUP //============================================== event_queue = al_create_event_queue(); timer = al_create_timer(1.0 / 60); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_start_timer(timer); //AnimacionEntrada(enemies,NUM_ENEMIES); printf("ya"); int animacion=1; int movimientos=0; while(!done){ ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); // INFORMACION DEL JUEGO Y BG // DrawWindowStatus(); al_draw_bitmap(bg, 0, 0, 0); al_draw_bitmap(nave_jugador.image, 5,440,0); al_draw_text(font, al_map_rgb(255,255,255), 40,430, 0, "X"); sprintf(vidas_char,"%d",vidas); al_draw_text(font, al_map_rgb(255,255,255), 60,430, 0, vidas_char); al_draw_text(font, al_map_rgb(255,255,255), WIDTH/2 - 30, 0,ALLEGRO_ALIGN_CENTRE, "Score"); char vartext[10]; sprintf(vartext,"%d",score); al_draw_text(font, al_map_rgb(255,255,255), WIDTH/2 + 40, 0, 0, vartext); //============================================== //INPUT //============================================== if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN){ switch(ev.keyboard.keycode){ case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = true; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = true; break; case ALLEGRO_KEY_SPACE: keys[SPACE] = true; FireBullet(bullets, NUM_BULLETS, nave_jugador); break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = false; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = false; break; case ALLEGRO_KEY_SPACE: keys[SPACE] = false; break; } } //============================================== //GAME UPDATE //============================================== else if(ev.type == ALLEGRO_EVENT_TIMER){ render = true; if(keys[LEFT]) MoveShipLeft(nave_jugador); else if(keys[RIGHT]) MoveShipRight(nave_jugador); UpdateBullet(bullets, NUM_BULLETS); CollideBullet(bullets,NUM_BULLETS,enemies1,NUM_ENEMIES); CollideBullet(bullets,NUM_BULLETS,enemies2,8); CollideBullet(bullets,NUM_BULLETS,enemies3,6); CollideBullet(bullets,NUM_BULLETS,enemies4,4); CollideBullet(bullets,NUM_BULLETS,jefe1,2); } //============================================== //RENDER //============================================== if(render && al_is_event_queue_empty(event_queue)) { if (animacion==1){ printf("si primero"); movEnemies(enemies1,10,1); movEnemies(enemies2, 8,1); movEnemies(enemies3,6,1); movEnemies(enemies4,4,1); movEnemies(jefe1,2,1); animacion=0; movimientos=1; } render = false; // Dibujar nave al_draw_bitmap(nave_jugador.image, nave_jugador.x - nave_jugador.w / 2, nave_jugador.y - nave_jugador.h / 2, 0); // Dibujar Balas DrawBullet(bullets, NUM_BULLETS); // Dibuja los enemigos. DrawEnemies(enemies1,10); DrawEnemies(enemies2,8); DrawEnemies(enemies3,6); DrawEnemies(enemies4,4); DrawEnemies(jefe1,2); al_flip_display(); al_clear_to_color(al_map_rgb(0,0,0)); if (movimientos){ movimientos=0; movEnemies(enemies1,10,2); movEnemies(enemies2,8,3); } } } for (int i =0;i<10;i++) al_destroy_bitmap(enemies1[i].image); al_destroy_event_queue(event_queue); al_destroy_timer(timer); al_destroy_display(display); //destroy our display object return 0; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_BITMAP *bouncer = NULL; float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0; float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0; bool redraw = true; if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } if(!al_install_mouse()) { fprintf(stderr, "failed to initialize the mouse!\n"); return -1; } timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(timer); return -1; } bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); if(!bouncer) { fprintf(stderr, "failed to create bouncer bitmap!\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_set_target_bitmap(bouncer); al_clear_to_color(al_map_rgb(255, 0, 255)); al_set_target_bitmap(al_get_backbuffer(display)); event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); al_destroy_bitmap(bouncer); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_mouse_event_source()); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); al_start_timer(timer); while(1) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { redraw = true; } else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) { bouncer_x = ev.mouse.x; bouncer_y = ev.mouse.y; } else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { break; } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0); al_flip_display(); } } al_destroy_bitmap(bouncer); al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
int main(int argc, char **argv){ /*declaramos nave como una estructura tipo móvil, q está definida * en el archivo "physics.h"*/ struct Movil nave; /*creamos las variables de allegro, que son punteros * apuntando a NULL, de momento*/ ALLEGRO_DISPLAY *display = NULL; ALLEGRO_BITMAP *sprites = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; bool key[4] = {false, false, false,false};//Array para las teclas, todos a false bool redraw = true; bool do_exit = false; /* Inicializamos allegro */ if(!al_init()) { al_show_native_message_box ( display, "Error", "Error", "Failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; } /* Inicializamos añadido de imágenes */ if(!al_init_image_addon()) { al_show_native_message_box ( display, "Error", "Error", "Failed to initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; } ni /* Inicializamos el teclado */ if(!al_install_keyboard()) { al_show_native_message_box ( display, "Error", "Error", "Failed to initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; }; /* Alegro artifact creation * del display, timer, cola eventos y sprites*/ display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { al_show_native_message_box( display, "Error", "Error", "Failed to initialize display!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; } timer = al_create_timer(1.0 / FPS); if(!timer) { al_show_native_message_box( display, "Error", "Error", "failed to create timer!\n", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); return 0; } event_queue = al_create_event_queue(); if(!event_queue) { al_show_native_message_box( display, "Error", "Error", "failed to create event_queue!\n", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); al_destroy_timer(timer); return 0; } sprites = al_load_bitmap("images/xenon2_sprites.png"); al_convert_mask_to_alpha(sprites, al_map_rgb(255,0,255)); if(!sprites) { al_show_native_message_box( display, "Error", "Error", "Failed to load sprites!", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); return 0; } /* registramos todos los eventos provenientes de la pantalla * el keyboard y el temporizador*/ al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_timer_event_source(timer)); /* Init es una funcion definida como extern el "physics.h" , que le meto * los sprites, que es el bitmap de la nave, y &nave, que es una dirección * de memoria donde hemos declarado nave como estructura*/ init(sprites, &nave); al_start_timer(timer); while(!doexit){ ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) redraw = true; else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; /* éste bloque funciona con el evento KEY_DOWN, y cuando apretamos * cualquier tecla, se registra el avento KEY_DOWN q corresponda */ else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_THROTTLE] = true; break; case ALLEGRO_KEY_DOWN: key[KEY_BRAKE] = true; break; case ALLEGRO_KEY_LEFT: key[KEY_ROTATE_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: key[KEY_ROTATE_RIGHT] = true; break; } /* Éste bloque funciona con el evento KEY_UP, cuando soltamos * la tecla se registra el evento KEY_DOWN correspondiente.*/ } else if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_THROTTLE] = false; break; case ALLEGRO_KEY_DOWN: key[KEY_BRAKE] = false; break; case ALLEGRO_KEY_LEFT: key[KEY_ROTATE_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: key[KEY_ROTATE_RIGHT] = false; break; case ALLEGRO_KEY_ESCAPE: doexit = true; break; } } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; update_physics(key, &nave); al_clear_to_color(al_map_rgb(0,0,0)); // al_draw_bitmap(sprites,200,200,0); al_draw_bitmap(nave.img[2 + (int) (nave.v.x / ROLL) ], SCREEN_W / 2 + nave.r.x, SCREEN_H - 50 - nave.r.y, 0); al_flip_display(); } } /* DEstrucción de los artefactos */ al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); al_destroy_bitmap(sprites); return 0; }
static void mainloop(void) { ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_TIMER *timer; float *buf; double pitch = 440; int i, si; int n = 0; bool redraw = false; for (i = 0; i < N; i++) { frequency[i] = 22050 * pow(2, i / (double)N); stream[i] = al_create_audio_stream(4, SAMPLES_PER_BUFFER, frequency[i], ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_1); if (!stream[i]) { abort_example("Could not create stream.\n"); } if (!al_attach_audio_stream_to_mixer(stream[i], al_get_default_mixer())) { abort_example("Could not attach stream to mixer.\n"); } } queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); for (i = 0; i < N; i++) { al_register_event_source(queue, al_get_audio_stream_event_source(stream[i])); } #ifdef ALLEGRO_POPUP_EXAMPLES if (textlog) { al_register_event_source(queue, al_get_native_text_log_event_source(textlog)); } #endif log_printf("Generating %d sine waves of different sampling quality\n", N); log_printf("If Allegro's resampling is correct there should be little variation\n", N); timer = al_create_timer(1.0 / 60); al_register_event_source(queue, al_get_timer_event_source(timer)); al_register_event_source(queue, al_get_display_event_source(display)); al_start_timer(timer); while (n < 60 * frequency[0] / SAMPLES_PER_BUFFER * N) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT) { for (si = 0; si < N; si++) { buf = al_get_audio_stream_fragment(stream[si]); if (!buf) { continue; } for (i = 0; i < SAMPLES_PER_BUFFER; i++) { double t = samplepos[si]++ / (double)frequency[si]; buf[i] = sin(t * pitch * ALLEGRO_PI * 2) / N; } if (!al_set_audio_stream_fragment(stream[si], buf)) { log_printf("Error setting stream fragment.\n"); } n++; log_printf("%d", si); if ((n % 60) == 0) log_printf("\n"); } } if (event.type == ALLEGRO_EVENT_TIMER) { redraw = true; } if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } #ifdef ALLEGRO_POPUP_EXAMPLES if (event.type == ALLEGRO_EVENT_NATIVE_DIALOG_CLOSE) { break; } #endif if (redraw &&al_is_event_queue_empty(queue)) { ALLEGRO_COLOR c = al_map_rgb(0, 0, 0); int i; al_clear_to_color(al_map_rgb_f(1, 1, 1)); for (i = 0; i < 640; i++) { al_draw_pixel(i, 50 + waveform[i] * 50, c); } al_flip_display(); redraw = false; } } for (si = 0; si < N; si++) { al_drain_audio_stream(stream[si]); } log_printf("\n"); al_destroy_event_queue(queue); }
bool Renderer::init(Minecraft *mc, const char *argv0) { NBT_Debug("begin"); al_set_org_name("mctools"); al_set_app_name("viewer"); if(!al_init()) { NBT_Debug("al_init failed???"); return false; } ALLEGRO_TIMER *tmr = nullptr; ALLEGRO_EVENT_QUEUE *queue = nullptr; ALLEGRO_DISPLAY *dpy = nullptr; ALLEGRO_BITMAP *bmp = nullptr; ALLEGRO_TRANSFORM *def_trans = nullptr; ALLEGRO_FONT *fnt = nullptr; if(!al_install_keyboard()) goto init_failed; if(!al_install_mouse()) goto init_failed; if(!al_init_primitives_addon()) goto init_failed; if(!al_init_image_addon()) goto init_failed; if(!al_init_font_addon()) goto init_failed; tmr = al_create_timer(1.0/60.0); if(!tmr) goto init_failed; queue = al_create_event_queue(); if(!queue) goto init_failed; // do display creation last so a display isn't created and instantly destroyed if any of the // preceeding initializations fail. al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_OPENGL_3_0); //al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE); //al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_REQUIRE); al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 24, ALLEGRO_REQUIRE); dpy = al_create_display(800, 600); if(!dpy) { NBT_Debug("display creation failed"); goto init_failed; } if(!al_get_opengl_extension_list()->ALLEGRO_GL_EXT_framebuffer_object) { NBT_Debug("FBO GL extension is missing. bail"); goto init_failed; } glGenVertexArrays(1, &vao_); glBindVertexArray(vao_); NBT_Debug("load shaders"); if(!loadShaders("shaders/default.vtx", "shaders/default.pxl")) { NBT_Debug("shader init failed"); goto init_failed; } NBT_Debug("load allegro shaders"); if(!loadAllegroShaders()) { NBT_Debug("allegro shader init failed"); goto init_failed; } glBindVertexArray(0); NBT_Debug("create resource manager"); resManager_ = new ResourceManager(this); if(!resManager_->init(mc, argv0)) { NBT_Debug("failed to init resource manager"); goto init_failed; } fnt = al_create_builtin_font(); if(!fnt) { NBT_Debug("failed to create builtin font"); goto init_failed; } 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(dpy)); al_register_event_source(queue, al_get_timer_event_source(tmr)); def_trans = al_get_projection_transform(dpy); al_copy_transform(&al_proj_transform_, def_trans); al_identity_transform(&camera_transform_); rx_look = 0.0; queue_ = queue; tmr_ = tmr; dpy_ = dpy; bmp_ = bmp; fnt_ = fnt; grab_mouse_ = false; // initial clear display // make things look purdy al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); NBT_Debug("end"); return true; init_failed: delete resManager_; resManager_ = nullptr; if(fnt) al_destroy_font(fnt); if(dpy) al_destroy_display(dpy); if(queue) al_destroy_event_queue(queue); al_uninstall_system(); NBT_Debug("end"); return false; }
int main(void) { ALLEGRO_DISPLAY *displays[2]; ALLEGRO_MONITOR_INFO *info; int adapter_count; int x, y; ALLEGRO_FONT *myfont; ALLEGRO_EVENT_QUEUE *events; ALLEGRO_EVENT event; int i; srand(time(NULL)); if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_install_mouse(); al_init_font_addon(); al_init_image_addon(); adapter_count = al_get_num_video_adapters(); info = malloc(adapter_count * sizeof(ALLEGRO_MONITOR_INFO)); for (i = 0; i < adapter_count; i++) { al_get_monitor_info(i, &info[i]); } x = ((info[0].x2 - info[0].x1) / 3) - (W / 2); y = ((info[0].y2 - info[0].y1) / 2) - (H / 2); al_set_new_window_position(x, y); displays[0] = al_create_display(W, H); x *= 2; al_set_new_window_position(x, y); displays[1] = al_create_display(W, H); if (!displays[0] || !displays[1]) { abort_example("Could not create displays.\n"); } al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); myfont = al_load_font("data/fixed_font.tga", 0, 0); if (!myfont) { abort_example("Could not load font.\n"); } events = al_create_event_queue(); al_register_event_source(events, al_get_mouse_event_source()); al_register_event_source(events, al_get_display_event_source(displays[0])); al_register_event_source(events, al_get_display_event_source(displays[1])); for (;;) { for (i = 0; i < 2; i++) { al_set_target_backbuffer(displays[i]); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); if (i == 0) al_clear_to_color(al_map_rgb(255, 0, 255)); else al_clear_to_color(al_map_rgb(155, 255, 0)); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); al_draw_textf(myfont, al_map_rgb(0, 0, 0), 50, 50, ALLEGRO_ALIGN_CENTRE, "Click me.."); al_flip_display(); } if (al_wait_for_event_timed(events, &event, 1)) { if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { int a = rand() % adapter_count; int w = info[a].x2 - info[a].x1; int h = info[a].y2 - info[a].y1; int margin = 20; x = margin + info[a].x1 + (rand() % (w - W - margin)); y = margin + info[a].y1 + (rand() % (h - H - margin)); al_set_window_position(event.mouse.display, x, y); } } } al_destroy_event_queue(events); al_destroy_display(displays[0]); al_destroy_display(displays[1]); free(info); return 0; }
int main(int, char**) { // Setup Allegro al_init(); al_install_keyboard(); al_install_mouse(); al_init_primitives_addon(); al_set_new_display_flags(ALLEGRO_RESIZABLE); ALLEGRO_DISPLAY* display = al_create_display(1280, 720); al_set_window_title(display, "ImGui Allegro 5 example"); ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue(); 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()); // Setup ImGui binding ImGui_ImplA5_Init(display); // Load Fonts // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details) //ImGuiIO& io = ImGui::GetIO(); //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); bool show_test_window = true; bool show_another_window = false; ImVec4 clear_color = ImColor(114, 144, 154); // Main loop bool running = true; while (running) { ALLEGRO_EVENT ev; while (al_get_next_event(queue, &ev)) { ImGui_ImplA5_ProcessEvent(&ev); if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false; if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { ImGui_ImplA5_InvalidateDeviceObjects(); al_acknowledge_resize(display); Imgui_ImplA5_CreateDeviceObjects(); } } ImGui_ImplA5_NewFrame(); // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ImGui::ColorEdit3("clear color", (float*)&clear_color); if (ImGui::Button("Test Window")) show_test_window ^= 1; if (ImGui::Button("Another Window")) show_another_window ^= 1; ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); } // 2. Show another simple window, this time using an explicit Begin/End pair if (show_another_window) { ImGui::Begin("Another Window", &show_another_window); ImGui::Text("Hello from another window!"); ImGui::End(); } // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } // Rendering al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); ImGui::Render(); al_flip_display(); } // Cleanup ImGui_ImplA5_Shutdown(); al_destroy_event_queue(queue); al_destroy_display(display); return 0; }
int main(int argc, char **argv){ struct Movil nave; ALLEGRO_DISPLAY *display = NULL; ALLEGRO_BITMAP *sprites = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; bool key[4] = { false, false, false, false }; bool redraw = true; bool doexit = false; /* Alegro startup */ if(!al_init()) { al_show_native_message_box(display, "Error", "Error", "Failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; } if(!al_init_image_addon()) { al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; } if(!al_install_keyboard()){ al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; }; /* Alegro artifact creation */ display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 0; } timer = al_create_timer(1.0 / FPS); if(!timer) { al_show_native_message_box(display, "Error", "Error", "failed to create timer!\n", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); return -1; } event_queue = al_create_event_queue(); if(!event_queue) { al_show_native_message_box(display, "Error", "Error", "failed to create event_queue!\n", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); al_destroy_timer(timer); return -1; } /* stitching */ sprites = al_load_bitmap("images/xenon2_sprites.png"); if(!sprites) { al_show_native_message_box(display, "Error", "Error", "Failed to load sprites!", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); return 0; } al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_timer_event_source(timer)); /* Init game objects */ init(sprites, &nave); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); al_start_timer(timer); /* Game loop */ while(!doexit){ ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) redraw = true; else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = true; break; case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = true; break; } } else if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = false; break; case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = false; break; case ALLEGRO_KEY_ESCAPE: doexit = true; break; } } update_physics(key, &nave); if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; //al_draw_bitmap(sprites,200,200,0); al_draw_bitmap(nave.img, 100, 100, 0); al_flip_display(); } } /* Housekeeping */ al_rest(2); al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); al_destroy_bitmap(sprites); return 0; }
void Mousebinds::shutdownMouseBinds() noexcept { al_unregister_event_source(m_events, m_mouseEventSource); al_destroy_event_queue(m_events); }
int main(int argc, char **argv) { ALLEGRO_TIMER *timer; ALLEGRO_EVENT_SOURCE user_src; ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_EVENT user_event; ALLEGRO_EVENT event; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } timer = al_create_timer(0.5); if (!timer) { abort_example("Could not install timer.\n"); } open_log(); al_init_user_event_source(&user_src); queue = al_create_event_queue(); al_register_event_source(queue, &user_src); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (true) { al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_TIMER) { int n = event.timer.count; log_printf("Got timer event %d\n", n); user_event.user.type = MY_SIMPLE_EVENT_TYPE; user_event.user.data1 = n; al_emit_user_event(&user_src, &user_event, NULL); user_event.user.type = MY_COMPLEX_EVENT_TYPE; user_event.user.data1 = (intptr_t)new_event(n); al_emit_user_event(&user_src, &user_event, my_event_dtor); } else if (event.type == MY_SIMPLE_EVENT_TYPE) { int n = (int) event.user.data1; ALLEGRO_ASSERT(event.user.source == &user_src); al_unref_user_event(&event.user); log_printf("Got simple user event %d\n", n); if (n == 5) { break; } } else if (event.type == MY_COMPLEX_EVENT_TYPE) { MY_EVENT *my_event = (void *)event.user.data1; ALLEGRO_ASSERT(event.user.source == &user_src); log_printf("Got complex user event %d\n", my_event->id); al_unref_user_event(&event.user); } } al_destroy_user_event_source(&user_src); al_destroy_event_queue(queue); al_destroy_timer(timer); log_printf("Done.\n"); close_log(true); return 0; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_BITMAP *bouncer = NULL; float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0; float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0; bool key[4] = { false, false, false, false }; bool redraw = true; bool doexit = false; srand(time(NULL)); if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } al_install_keyboard(); al_init_primitives_addon(); timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(timer); return -1; } bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); if(!bouncer) { fprintf(stderr, "failed to create bouncer bitmap!\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_set_target_bitmap(bouncer); al_clear_to_color(al_map_rgb(255, 255, 0)); al_set_target_bitmap(al_get_backbuffer(display)); event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); al_destroy_bitmap(bouncer); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_clear_to_color(al_map_rgb(255,255,0)); al_flip_display(); al_start_timer(timer); //¡¡QUE EMPIEZE LA FIESTA!! //¿En qué momento ponemos como verdaderos lo booleanos de las teclas? while(!doexit) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER/*?*/) { //Revisa si se sale de los bordes de la pantalla, pero no sé porqué no lo hace siempre if(key[KEY_UP] && bouncer_y >= 4.0) { bouncer_y -= 4.0; } if(key[KEY_DOWN] && bouncer_y <= SCREEN_H - BOUNCER_SIZE - 4.0) { bouncer_y += 4.0; } if(key[KEY_LEFT] && bouncer_x >= 4.0) { bouncer_x -= 4.0; } if(key[KEY_RIGHT] && bouncer_x <= SCREEN_W - BOUNCER_SIZE - 4.0) { bouncer_x += 4.0; } redraw = true; } else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_W: key[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = true; break; case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = true; break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: key[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = false; break; case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = false; break; case ALLEGRO_KEY_ESCAPE: doexit = true; break; } } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0); al_flip_display(); } } al_destroy_bitmap(bouncer); al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
//int main(int argc, char **argv) int main(int, char **) { ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; Entity *player = new Entity(); //bool key[4] = { false, false, false, false }; int mvkeys[2] = { 0, 0 }; bool redraw = true; bool doexit = false; if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } if(!al_init_image_addon()) { fprintf(stderr, "failed to initialize image addon!\n"); return -1; } if(!al_install_keyboard()) { fprintf(stderr, "failed to initialize the keyboard!\n"); return -1; } //--Calculate how long each frame should last in milliseconds, then create // a timer which ticks at that interval timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(timer); return -1; } //--Create a camera object for everything to use fprintf(stderr, "Creating camera\n"); Camera* camera = new Camera(); //--Initialize player entity player->init(display,camera); //player.init(display,sprite_x,sprite_y); //if (player->generate_bitmap() == -1) return -1; player->set_pos(SCREEN_W/2.0-SPRITE_W/2.0,SCREEN_H/2.0-SPRITE_H/2.0); MapManager* mapmanager = new MapManager(camera, player); mapmanager->add_map("data/levels/testmap.tmx"); mapmanager->set_active_map("data/levels/testmap.tmx"); //mapmanager->reset_camera(0,64); player->set_mapmanager(mapmanager); //fprintf(stderr, "Tileset for ID %i is %s\n",52,mapmanager->get_active_map()->get_tileset_for_id(19)->name); //TileMap *testmap = new TileMap("data/levels/outside.tmx"); event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); delete player; delete mapmanager; al_destroy_display(display); al_destroy_timer(timer); return -1; } al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); al_start_timer(timer); while(!doexit) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); //--Game Logic--// if(ev.type == ALLEGRO_EVENT_TIMER) { mapmanager->update(); player->update(mvkeys); //player->updatealt(mvkeys, key); redraw = true; } else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } //--Store keypress info else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { //printf("\n\nKEYCODE: %i\n\n", ev.keyboard.keycode); switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: //key[KEY_UP] = true; mvkeys[3] = 1; break; case ALLEGRO_KEY_DOWN: //key[KEY_DOWN] = true; mvkeys[4] = 1; break; case ALLEGRO_KEY_LEFT: //key[KEY_LEFT] = true; if (!mvkeys[0]) { mvkeys[0] = ALLEGRO_KEY_LEFT; } else { //mvkeys[1] = ALLEGRO_KEY_LEFT; mvkeys[1] = mvkeys[0]; mvkeys[0] = ALLEGRO_KEY_LEFT; } break; case ALLEGRO_KEY_RIGHT: //key[KEY_RIGHT] = true; if (!mvkeys[0]) { mvkeys[0] = ALLEGRO_KEY_RIGHT; } else { //mvkeys[1] = ALLEGRO_KEY_RIGHT; mvkeys[1] = mvkeys[0]; mvkeys[0] = ALLEGRO_KEY_RIGHT; } break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: //key[KEY_UP] = false; mvkeys[3] = 0; break; case ALLEGRO_KEY_DOWN: //key[KEY_DOWN] = false; mvkeys[4] = 0; break; case ALLEGRO_KEY_LEFT: //key[KEY_LEFT] = false; if (mvkeys[0] == ALLEGRO_KEY_LEFT) { mvkeys[0] = mvkeys[1]; mvkeys[1] = 0; } else if (mvkeys[1] == ALLEGRO_KEY_LEFT) { mvkeys[1] = 0; } break; case ALLEGRO_KEY_RIGHT: //key[KEY_RIGHT] = false; if (mvkeys[0] == ALLEGRO_KEY_RIGHT) { mvkeys[0] = mvkeys[1]; mvkeys[1] = 0; } else if (mvkeys[1] == ALLEGRO_KEY_RIGHT) { mvkeys[1] = 0; } break; case ALLEGRO_KEY_ESCAPE: doexit = true; break; } } //printf("\n[%i, %i]\n\n", mvkeys[0], mvkeys[1]); //--The screen has updated and needs to be redrawn //--Draw Logic--// if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(50,50,50)); mapmanager->drawbg(); player->draw(); mapmanager->drawmg(); mapmanager->drawfg(); al_flip_display(); } } //--You could let Allegro do this automatically, but it's allegedly faster // if you do it manually delete player; //delete testmap; delete mapmanager; al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
int main(int argc, const char *argv[]) { ALLEGRO_EVENT event; ALLEGRO_KEYBOARD_STATE kst; bool blend; if (!al_init()) { abort_example("Could not init Allegro.\n"); return 1; } al_init_primitives_addon(); al_install_keyboard(); al_install_mouse(); display = al_create_display(W, H); if (!display) { abort_example("Error creating display\n"); return 1; } black = al_map_rgb_f(0.0, 0.0, 0.0); white = al_map_rgb_f(1.0, 1.0, 1.0); background = al_map_rgb_f(0.5, 0.5, 0.6); if (argc > 1 && 0 == strcmp(argv[1], "--memory-bitmap")) { al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); } dbuf = al_create_bitmap(W, H); if (!dbuf) { abort_example("Error creating double buffer\n"); return 1; } al_set_target_bitmap(dbuf); al_clear_to_color(background); draw_clip_rect(); flip(); 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()); while (true) { al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { al_get_keyboard_state(&kst); blend = al_key_down(&kst, ALLEGRO_KEY_LSHIFT) || al_key_down(&kst, ALLEGRO_KEY_RSHIFT); if (event.mouse.button == 1) { plonk(event.mouse.x, event.mouse.y, blend); } else { splat(event.mouse.x, event.mouse.y, blend); } } else if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) { last_x = last_y = -1; } else if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } } al_destroy_event_queue(queue); al_destroy_bitmap(dbuf); return 0; }
void correrwallp(void) { ALLEGRO_TIMER *timer = NULL; ALLEGRO_EVENT_QUEUE *queue=NULL; ALLEGRO_BITMAP *fondo=NULL, *icons[4]; boton items[4]; void (*p2buttonf[4])(void); queue = al_create_event_queue(); timer = al_create_timer(1.0/FPS); //genero un timer para trabajar en 60 fps bool redraw=false; fondo=al_load_bitmap("wallfondo.png"); //wally1 icons[0]=al_load_bitmap("wally1.png"); botones(&items[0],30,70, 150, 200); p2buttonf[0]=cambiarfondo1; //wally2 icons[1]=al_load_bitmap("wally2.png"); botones(&items[1],230,70, 150, 200); p2buttonf[1]=cambiarfondo2; //wally3 icons[2]=al_load_bitmap("wally3.png"); botones(&items[2],30,330, 150, 200); p2buttonf[2]=cambiarfondo3; //wally4 icons[3]=al_load_bitmap("wally4.png"); botones(&items[3],230,330, 150, 200); p2buttonf[3]=cambiarfondo4; //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)); //timer starts al_start_timer(timer); while(!doexit && !exitmenu) // 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); inicio(ev); presionobotones(ev, items, p2buttonf,4); if(redraw) { // si hay que redibujar al_draw_bitmap(fondo, 0, OFFSETUP, 0); drawbotones(items, icons,4); redraw=false; al_flip_display(); //flipeo } } al_destroy_event_queue(queue); al_destroy_bitmap(fondo); al_destroy_bitmap(icons[0]); al_destroy_bitmap(icons[1]); al_destroy_bitmap(icons[2]); al_destroy_bitmap(icons[3]); al_destroy_timer(timer); exitmenu=false; }
void shutdown() { if (timer) al_destroy_timer(timer); if (display) al_destroy_display(display); if (event_queue) al_destroy_event_queue(event_queue); exit(0); }
int main() { ALLEGRO_DISPLAY *display; const float FPS = 60.0; const float frameFPS = 15.0; float degrees = 0.0f; if (!al_init()) al_show_native_message_box(NULL, "Error", NULL, "Could not Initialize Allegro", NULL, NULL); display = al_create_display(ScreenWidth, ScreenHeight); if (!display) al_show_native_message_box(NULL, "Error", NULL, "Could not create Allegro Display", NULL, NULL); al_set_window_position(display, 200, 200); bool done = false, draw = true, active = false; float moveSpeed = 5; int dir = NONE; al_install_keyboard(); al_init_image_addon(); al_init_primitives_addon(); SpriteSeq iory1SpriteSeq = SpriteUtil::process("iory-yagami.png", al_map_rgba(255, 0, 0, 255)); SpriteSeq iory2SpriteSeq = SpriteUtil::process("iory-yagami.png", al_map_rgba(255, 0, 0, 255)); iory1SpriteSeq.setX(200); iory2SpriteSeq.setX(200); iory1SpriteSeq.setY(200); iory2SpriteSeq.setY(200); ALLEGRO_KEYBOARD_STATE keyState; ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); ALLEGRO_TIMER *frameTimer = al_create_timer(1.0 / frameFPS); ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_timer_event_source(frameTimer)); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_start_timer(timer); al_start_timer(frameTimer); while(!done) { ALLEGRO_EVENT events; al_wait_for_event(event_queue, &events); al_get_keyboard_state(&keyState); if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } else if (events.type == ALLEGRO_EVENT_TIMER) { if (events.timer.source == timer) { dir = NONE; active = true; if (al_key_down(&keyState, ALLEGRO_KEY_DOWN)) { iory1SpriteSeq.incY(moveSpeed); if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT)) { iory1SpriteSeq.incX(moveSpeed); dir = DOWN_RIGHT; } else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT)) { iory1SpriteSeq.decX(moveSpeed); dir = DOWN_LEFT; } } else if (al_key_down(&keyState, ALLEGRO_KEY_UP)) { iory1SpriteSeq.decY(moveSpeed); if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT)) { iory1SpriteSeq.incX(moveSpeed); dir = UP_RIGHT; } else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT)) { iory1SpriteSeq.decX(moveSpeed); dir = UP_LEFT; } } else if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT)) { iory1SpriteSeq.incX(moveSpeed); dir = RIGHT; } else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT)) { iory1SpriteSeq.decX(moveSpeed); dir = LEFT; } else { active = false; } if (al_key_down(&keyState, ALLEGRO_KEY_W)) degrees++; else if (al_key_down(&keyState, ALLEGRO_KEY_S)) degrees--; if (degrees >= 360 || degrees <= -360) degrees = 0; } else if (events.timer.source == frameTimer) { iory1SpriteSeq.next(); if (!iory1SpriteSeq.hasNext()) iory1SpriteSeq.reset(); iory2SpriteSeq.next(); if (!iory2SpriteSeq.hasNext()) iory2SpriteSeq.reset(); } draw = true; } if (draw) { Sprite sprite1 = iory1SpriteSeq.current(); Sprite sprite2 = iory2SpriteSeq.current(); iory1SpriteSeq.setInFrontOf(&iory2SpriteSeq); iory2SpriteSeq.setInFrontOf(&iory1SpriteSeq); al_draw_bitmap(iory2SpriteSeq.getSubBitmap(), iory2SpriteSeq.getX(), iory2SpriteSeq.getY(), iory2SpriteSeq.getDrawFlags()); al_draw_bitmap(iory1SpriteSeq.getSubBitmap(), iory1SpriteSeq.getX(), iory1SpriteSeq.getY(), iory1SpriteSeq.getDrawFlags()); //al_draw_rotated_bitmap(iory1SpriteSeq.getSubBitmap(), sprite1.width/2, sprite1.height/2, iory1SpriteSeq.getX(), iory1SpriteSeq.getY(), // degrees * 3.1415 / 180, iory1SpriteSeq.getDrawFlags()); //al_draw_tinted_bitmap(sprite.bitmap, al_map_rgb(255, 0, 0), x, y, NULL); //al_draw_scaled_bitmap(subBitmap, 16, 16, 16, 16, x, y, 32 * degrees, 32 * degrees, NULL); ALLEGRO_COLOR red = al_map_rgb(255,0,0); ALLEGRO_COLOR blue = al_map_rgb(0,0,255); al_draw_line( (float) iory1SpriteSeq.getX(), (float) iory1SpriteSeq.getY() - 10.10, (float) iory1SpriteSeq.getX(), (float) iory1SpriteSeq.getY() - 20.0, red, 1.0); al_draw_line( (float) iory1SpriteSeq.getCenterX(), (float) iory1SpriteSeq.getY() - 30.0, (float) iory1SpriteSeq.getCenterX(), (float) iory1SpriteSeq.getY() - 40.0, blue, 1.0); al_draw_line( (float) iory2SpriteSeq.getX(), (float) iory2SpriteSeq.getY() - 10.10, (float) iory2SpriteSeq.getX(), (float) iory2SpriteSeq.getY() - 20.0, red, 1.0); al_draw_line( (float) iory2SpriteSeq.getCenterX(), (float) iory2SpriteSeq.getY() - 30.0, (float) iory2SpriteSeq.getCenterX(), (float) iory2SpriteSeq.getY() - 40.0, blue, 1.0); al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); } } al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); return 0; }
int main(int argc, char **argv){ ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; bool redraw = true; if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } display = al_create_display(640, 480); if(!display) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(timer); return -1; } event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); al_start_timer(timer); while(1) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { redraw = true; } else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); } } al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
int main(int argc, char **argv){ ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_BITMAP *seletor = NULL; float tamanho = 25; float espacamento = SELETOR_SIZE + 19; float seletor_x = 1174; float seletor_y = 40; bool key[4] = { false, false, false, false }; bool redraw = true; bool doexit = false; float posicao = 0; int mapa[770][3]; bool envio[4] = { false, false, false, false }; //Inicia o allegro al_init(); al_init_image_addon(); al_install_keyboard(); // Inicialização do add-on para uso de fontes al_init_font_addon(); al_init_ttf_addon(); inicializaBitmaps(); lerConf(mapa); //Cria a lista de eventos event_queue = al_create_event_queue(); //Cria o timer timer = al_create_timer(1.0 / FPS); //Cria a janela display = al_create_display(SCREEN_W, SCREEN_H); //Limpa a janela com a cor preta al_clear_to_color(al_map_rgb(0, 0, 0)); //Carrega a imagem de fundo na variável background = al_load_bitmap("img/fundo.png"); //Desenha a imagem de fundo na posição (0,0) al_draw_bitmap(background, 0, 0, 0); //Carrega a imagem do seletor na variável seletor = al_load_bitmap("img/selecao.png"); //Desenha o seletor na posição (1174,40) al_draw_bitmap(seletor, 1174, 40, 0); desenhaMapa(mapa, envio); //Registra os eventos al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_flip_display(); //Inicia o timer al_start_timer(timer); //Inicia contagem de tempo para a pergunta aparecer initClock(); //While do jogo while(!doexit){ //Aguarda o evento ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); //Se der o tempo do timer, verifica qual tecla foi pressionada e se é possível se mover para a posição de destino if(ev.type == ALLEGRO_EVENT_TIMER){ if(key[KEY_LEFT] && (posicao == 1 || posicao == 3) && (janela_aberta == 0)) { seletor_x -= espacamento; if(posicao == 1) posicao = 0; else posicao = 2; } if(key[KEY_RIGHT] && (posicao == 0 || posicao == 2) && (janela_aberta == 0)) { seletor_x += espacamento; if(posicao == 0) posicao = 1; else posicao = 3; } if(key[KEY_UP] && (posicao == 2 || posicao == 3) && (janela_aberta == 0)) { seletor_y -= espacamento; if(posicao == 2) posicao = 0; else posicao = 1; } if(key[KEY_DOWN] && (posicao == 0 || posicao == 1) && (janela_aberta == 0)) { seletor_y += espacamento; if(posicao == 0) posicao = 2; else posicao = 3; } redraw = true; } //Se a janela for fechada, termina o jogo else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } //Se o evento for um tecla pressionada, seta a variável dessa tecla para "true" (pressionada) else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = true; break; case ALLEGRO_KEY_UP: key[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = true; break; } } //Se o evento for um tecla solta, seta a variável dessa tecla para "false" (caso seja Esc, encerra o programa) else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_LEFT: key[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: key[KEY_RIGHT] = false; break; case ALLEGRO_KEY_ESCAPE: doexit = true; break; case ALLEGRO_KEY_UP: key[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: key[KEY_DOWN] = false; break; case ALLEGRO_KEY_ENTER: if (janela_aberta == 0){ if(posicao == 0) envio[VERMELHO] = true; else if(posicao == 1) envio[AZUL] = true; else if(posicao == 2) envio[VERDE] = true; else if(posicao == 3) envio[AMARELO] = true; } } } //Redesenha o jogo if(redraw && al_is_event_queue_empty(event_queue)){ redraw = false; al_draw_bitmap(background, 0, 0, 0); desenhaMapa(mapa, envio); movimento(mapa); if (janela_aberta == 0){ if (checkClock()){ janela_aberta = 1; } }else{ al_draw_bitmap(perguntas, 0, 0, 0); al_draw_textf(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, 250, ALLEGRO_ALIGN_CENTRE, "%s", texto); printf("check\n"); initClock(); } al_draw_bitmap(seletor, seletor_x, seletor_y, 0); al_flip_display(); } } //Destrói os objetos al_destroy_bitmap(background); al_destroy_bitmap(seletor); al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
int main() { ALLEGRO_DISPLAY *Screen = NULL; ALLEGRO_EVENT_QUEUE *EventQueue = NULL; ALLEGRO_EVENT Event; ALLEGRO_BITMAP *Background = NULL, *KeyDownImage = NULL; ALLEGRO_BITMAP *Image = NULL; ALLEGRO_SAMPLE *sample=NULL; bool Exit = false, KeyDown = false; if(!al_init()) { al_show_native_message_box(NULL, "Error!", "Allegro has failed to initialize.", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_init_image_addon()) { al_show_native_message_box(NULL, "Error!", "Image addon has failed to initialize.", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_install_audio()){ fprintf(stderr, "failed to initialize audio!\n"); return -1; } if(!al_init_acodec_addon()){ fprintf(stderr, "failed to initialize audio codecs!\n"); return -1; } if (!al_reserve_samples(1)){ fprintf(stderr, "failed to reserve samples!\n"); return -1; } sample = al_load_sample( "music.ogg" ); if (!sample){ printf( "Audio clip sample not loaded!\n" ); return -1; } Screen = al_create_display(512, 512); if(Screen == NULL) { al_show_native_message_box(Screen, "Error!", "Failed to create the display.", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } EventQueue = al_create_event_queue(); if(EventQueue == NULL) { al_show_native_message_box(Screen, "Error!", "Failed to create the event queue.", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_install_keyboard()) { al_show_native_message_box(NULL, "Error!", "Failed to install keyboard.", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_register_event_source(EventQueue, al_get_display_event_source(Screen)); al_register_event_source(EventQueue, al_get_keyboard_event_source()); Background = al_load_bitmap("Background.png"); if(Background == NULL) { al_show_native_message_box(Screen, "Error!", "Failed to load -Background.png-", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } Image = al_load_bitmap("image.png"); if(Image == NULL) { al_show_native_message_box(Screen, "Error!", "Failed to load -Image.png-", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } KeyDownImage = al_load_bitmap("Meteors.png"); if(KeyDownImage == NULL) { al_show_native_message_box(Screen, "Error!", "Failed to load -KeyPressed.png-", 0, 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL); while(Exit == false) { if(KeyDown == true) { al_draw_bitmap(KeyDownImage, 0, 0, 0); } else { al_draw_bitmap(Background, 0, 0, 0); al_draw_bitmap(Image, 100, 100, 0); } al_flip_display(); al_wait_for_event(EventQueue, &Event); if(Event.type == ALLEGRO_EVENT_KEY_DOWN) { if(Event.keyboard.keycode == ALLEGRO_KEY_SPACE) { KeyDown = true; } } if(Event.type == ALLEGRO_EVENT_KEY_UP) { KeyDown = false; } if(Event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { Exit = true; } } al_destroy_bitmap(Background); al_destroy_bitmap(KeyDownImage); al_destroy_event_queue(EventQueue); al_destroy_display(Screen); return 0; }
int main(int, char**) { // Setup Allegro al_init(); al_install_keyboard(); al_install_mouse(); al_init_primitives_addon(); al_set_new_display_flags(ALLEGRO_RESIZABLE); ALLEGRO_DISPLAY* display = al_create_display(1280, 720); al_set_window_title(display, "ImGui Allegro 5 example"); ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue(); 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()); // Setup ImGui binding ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls ImGui_ImplA5_Init(display); // Setup style ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); // Load Fonts // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. // - Read 'misc/fonts/README.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Main loop bool running = true; while (running) { // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. ALLEGRO_EVENT ev; while (al_get_next_event(queue, &ev)) { ImGui_ImplA5_ProcessEvent(&ev); if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false; if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { ImGui_ImplA5_InvalidateDeviceObjects(); al_acknowledge_resize(display); Imgui_ImplA5_CreateDeviceObjects(); } } ImGui_ImplA5_NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". { static float f = 0.0f; static int counter = 0; ImGui::Text("Hello, world!"); // Display some text (you can use a format string too) ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our windows open/close state ImGui::Checkbox("Another Window", &show_another_window); if (ImGui::Button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated) counter++; ImGui::SameLine(); ImGui::Text("counter = %d", counter); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); } // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows. if (show_another_window) { ImGui::Begin("Another Window", &show_another_window); ImGui::Text("Hello from another window!"); if (ImGui::Button("Close Me")) show_another_window = false; ImGui::End(); } // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui! if (show_demo_window) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! ImGui::ShowDemoWindow(&show_demo_window); } // Rendering al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); ImGui::Render(); ImGui_ImplA5_RenderDrawData(ImGui::GetDrawData()); al_flip_display(); } // Cleanup ImGui_ImplA5_Shutdown(); ImGui::DestroyContext(); al_destroy_event_queue(queue); al_destroy_display(display); return 0; }
static void main_loop(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *picture) { ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_EVENT event; bool can_draw; int new_res; queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); can_draw = true; while (1) { if (al_is_event_queue_empty(queue) && can_draw) { redraw(picture); } al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_LOST) { log_printf("Display lost\n"); can_draw = false; continue; } if (event.type == ALLEGRO_EVENT_DISPLAY_FOUND) { log_printf("Display found\n"); can_draw = true; continue; } if (event.type != ALLEGRO_EVENT_KEY_CHAR) { continue; } if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } new_res = cur_res; if (event.keyboard.unichar == '+' || event.keyboard.unichar == ' ' || event.keyboard.keycode == ALLEGRO_KEY_ENTER) { new_res++; if (new_res >= NUM_RESOLUTIONS) new_res = 0; } else if (event.keyboard.unichar == '-') { new_res--; if (new_res < 0) new_res = NUM_RESOLUTIONS - 1; } if (new_res != cur_res) { cur_res = new_res; log_printf("Switching to %dx%d... ", res[cur_res].w, res[cur_res].h); if (al_resize_display(display, res[cur_res].w, res[cur_res].h)) { log_printf("Succeeded.\n"); } else { log_printf("Failed. current resolution: %dx%d\n", al_get_display_width(display), al_get_display_height(display)); } } } al_destroy_event_queue(queue); }
int main(int argc, const char **argv){ // Variables ALLEGRO_DISPLAY *ventana = NULL; ALLEGRO_EVENT_QUEUE *mensajes = NULL; ALLEGRO_TIMER *alarma = NULL; bool dibujar = true; struct Nave nave[N]; srand(time(NULL)); srand48(time(NULL)); al_init(); // Crear: ventana = al_create_display(SW, SH); mensajes = al_create_event_queue(); alarma = al_create_timer(1/60.); al_register_event_source(mensajes, al_get_display_event_source(ventana)); al_register_event_source(mensajes, al_get_timer_event_source(alarma)); iniciar(nave); al_set_target_bitmap(al_get_backbuffer(ventana)); al_start_timer(alarma); while(1) { ALLEGRO_EVENT ev; al_wait_for_event(mensajes, &ev); if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (ev.type == ALLEGRO_EVENT_TIMER) dibujar = true; if (dibujar && al_is_event_queue_empty(mensajes) ){ dibujar = false; recalcular_posiciones(nave); al_clear_to_color(al_map_rgb(0,0,0)); for (int i=0; i<N; i++) al_draw_bitmap(nave[i].img, nave[i].x, nave[i].y, 0); al_flip_display(); } // Miro los eventos // Si cierran la ventan // salgo del bucle // Si se cumple el tiempo: // repintar // Si repintar // No repintar // Mover el cuadrado // Pintar } al_destroy_timer(alarma); al_destroy_display(ventana); al_destroy_event_queue(mensajes); return EXIT_SUCCESS; }
int main() { bool quit = false; int gamestate = 0; srand(time(NULL)); int change_bkg = 0; int stopwatch = 120; bool iddle = false; int bulletID=0; int bulletCount=0; ALLEGRO_DISPLAY* display; ALLEGRO_TIMER* timer_0p2; ALLEGRO_TIMER* timer_1; ALLEGRO_TIMER* timer_60; ALLEGRO_EVENT_QUEUE* event_queue; ALLEGRO_EVENT ev; ALLEGRO_BITMAP* img_home_screen; ALLEGRO_BITMAP* img_dica_h1n1; ALLEGRO_BITMAP* img_background0; ALLEGRO_BITMAP* img_game_over; ALLEGRO_BITMAP* img_you_win; ALLEGRO_BITMAP* img_heart; ALLEGRO_BITMAP* img_medal; ALLEGRO_BITMAP* img_clock; ALLEGRO_BITMAP* img_block1; ALLEGRO_BITMAP* img_block2; ALLEGRO_BITMAP* img_player_walking; ALLEGRO_BITMAP* img_player_walking_shoot; ALLEGRO_BITMAP* img_player_immobile; ALLEGRO_BITMAP* img_player_immobile_shoot; ALLEGRO_BITMAP* img_player_jump; ALLEGRO_BITMAP* img_player_jump_shoot; ALLEGRO_BITMAP* img_player_bullet; ALLEGRO_BITMAP* img_enemy1; ALLEGRO_BITMAP* img_boss1; ALLEGRO_BITMAP* img_enemy_bullet; ALLEGRO_SAMPLE* spl_theme; ALLEGRO_SAMPLE* spl_playerShoot; ALLEGRO_SAMPLE* spl_mlk; ALLEGRO_SAMPLE_INSTANCE* instance_theme; ALLEGRO_SAMPLE_INSTANCE* instance_playerShoot; ALLEGRO_SAMPLE_INSTANCE* instance_mlk; ALLEGRO_FONT* fonte16; /* Estruturas */ s_object player; s_object block[LINHA_MAX][COLUNA_MAX]; s_object enemy1[LINHA_MAX][COLUNA_MAX]; for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { /* Cria o player */ if(mapa[i][j] == 1) { player.y = i*16 - 24; player.x = j*64 + 24; player.speed = 3; player.direction = 1; player.live = true; player.life = 100; block[i][j].live = false; } /* Cria os Blocos */ if(mapa[i][j] == 2) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 3) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 4) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 5) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = false; } /* Cria os Inimigos */ if(mapa[i][j] == 6) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = -1; enemy1[i][j].life = 3; enemy1[i][j].live = true; block[i][j].live = false; } if(mapa[i][j] == 7 || mapa[i][j] == 8) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = 1; enemy1[i][j].life = 3; enemy1[i][j].live = false; block[i][j].live = false; } if(mapa[i][j] == 9) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = -1; enemy1[i][j].life = 25; enemy1[i][j].live = false; block[i][j].live = false; } } } s_bullet playerBullet[NUM_BULLET]; s_bullet enemyBullet[NUM_BULLET]; for(i=0; i<NUM_BULLET; i++) { playerBullet[i].x = 0; playerBullet[i].y = 0; playerBullet[i].speed = 5; playerBullet[i].direction = 1; playerBullet[i].live = false; enemyBullet[i].x = 0; enemyBullet[i].y = 0; enemyBullet[i].speed = 5; enemyBullet[i].direction = 0; enemyBullet[i].live = false; } s_animation walking; walking.maxFrame = 8; walking.frameDelay = 5; walking.frameCount = 0; walking.curFrame = 0; walking.frameHeight = 40; walking.frameWidth = 40; s_animation jumping; jumping.maxFrame = 7; jumping.frameDelay = 5; jumping.frameCount = 0; jumping.curFrame = 0; jumping.frameHeight = 52; jumping.frameWidth = 40; s_animation immobile; immobile.maxFrame = 7; immobile.frameDelay = 15; immobile.frameCount = 0; immobile.curFrame = 0; immobile.frameHeight = 40; immobile.frameWidth = 40; s_animation anim_enemy1; anim_enemy1.maxFrame = 3; anim_enemy1.frameDelay = 15; anim_enemy1.frameCount = 0; anim_enemy1.curFrame = 0; anim_enemy1.frameHeight = 40; anim_enemy1.frameWidth = 40; /* Faz com que as teclas comecem em false */ for(i=0; i<KEY_MAX; i++) { keys[i] = false; } /* Carrega as configuracoes (teclado, audio, etc) */ al_init(); al_install_keyboard(); al_init_image_addon(); al_install_audio(); al_init_acodec_addon(); al_init_font_addon(); al_init_ttf_addon(); /* Erros ao criar algo */ display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { printf("Erro ao criar o display"); exit(-1); } timer_0p2 = al_create_timer(5.0); timer_1 = al_create_timer(1.0); timer_60 = al_create_timer(1/60.0); if(!timer_0p2) { printf("Erro ao criar o timer de 0.2 FPS"); exit(-1); } if(!timer_1) { printf("Erro ao criar o timer de 1 FPS"); exit(-1); } if(!timer_60) { printf("Erro ao criar o timer de 60 FPS"); exit(-1); } event_queue = al_create_event_queue(); if(!event_queue) { printf("Erro ao criar o event_queue"); exit(-1); } /* Carregando as Imagens */ img_home_screen = al_load_bitmap("Sprites/Background/home_screen.png"); img_dica_h1n1 = al_load_bitmap("Sprites/Background/dica_h1n1.png"); img_background0 = al_load_bitmap("Sprites/Background/background_h1n1.png"); img_you_win = al_load_bitmap("Sprites/Background/you_win.png"); img_game_over = al_load_bitmap("Sprites/Background/game_over.png"); img_heart = al_load_bitmap("Sprites/heart.png"); img_medal = al_load_bitmap("Sprites/medal.png"); img_clock = al_load_bitmap("Sprites/clock.png"); img_block1 = al_load_bitmap("Sprites/block1.png"); img_block2 = al_load_bitmap("Sprites/block2.png"); img_player_walking = al_load_bitmap("Sprites/Player/player_walking.png"); img_player_walking_shoot = al_load_bitmap("Sprites/Player/player_walking_shoot.png"); img_player_immobile = al_load_bitmap("Sprites/Player/player_immobile.png"); img_player_immobile_shoot = al_load_bitmap("Sprites/Player/player_immobile_shoot.png"); img_player_jump = al_load_bitmap("Sprites/Player/player_jump.png"); img_player_jump_shoot = al_load_bitmap("Sprites/Player/player_jump_shoot.png"); img_player_bullet = al_load_bitmap("Sprites/Player/player_bullet.png"); img_enemy1 = al_load_bitmap("Sprites/Enemies/enemy_h1n1.png"); img_boss1 = al_load_bitmap("Sprites/Enemies/boss_h1n1.png"); img_enemy_bullet = al_load_bitmap("Sprites/Enemies/enemy_bullet.png"); /* Carregando os Samples */ al_reserve_samples(10); spl_theme = al_load_sample("Sounds/theme.wav"); spl_playerShoot = al_load_sample("Sounds/shoot.wav"); spl_mlk = al_load_sample("Sounds/mlk.wav"); instance_theme = al_create_sample_instance(spl_theme); instance_playerShoot = al_create_sample_instance(spl_playerShoot); instance_mlk = al_create_sample_instance(spl_mlk); al_set_sample_instance_gain(instance_playerShoot, 0.5); al_attach_sample_instance_to_mixer(instance_theme, al_get_default_mixer()); al_attach_sample_instance_to_mixer(instance_playerShoot, al_get_default_mixer()); al_attach_sample_instance_to_mixer(instance_mlk, al_get_default_mixer()); /* Registra os Eventos */ al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer_0p2)); al_register_event_source(event_queue, al_get_timer_event_source(timer_1)); al_register_event_source(event_queue, al_get_timer_event_source(timer_60)); al_register_event_source(event_queue, al_get_keyboard_event_source()); /* Carregando os timers */ al_start_timer(timer_0p2); al_start_timer(timer_1); al_start_timer(timer_60); /* Carregando a fonte */ fonte16 = al_load_ttf_font("Joystix.TTF", 16, 0); if (!fonte16) { printf("Erro ao carregar Joystix.TTF\n"); exit(1); } while(!quit) { switch(gamestate) { case 0: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE) /* Faz com que o jogo inicie ao pressionar space */ { change_bkg++; if(change_bkg >= 2) { gamestate = 1; } } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); if(change_bkg == 0) { al_draw_bitmap(img_home_screen, 0, 0, 0); } if(change_bkg == 1) { al_draw_bitmap(img_dica_h1n1, 0, 0, 0); if(++anim_enemy1.frameCount >= anim_enemy1.frameDelay) { if(++anim_enemy1.curFrame >= anim_enemy1.maxFrame) { anim_enemy1.curFrame = 0; } anim_enemy1.frameCount = 0; } al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, 330, 320, 0); al_draw_bitmap_region(img_boss1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, 450, 320, 0); } al_flip_display(); } } break; case 1: if(force>= -7.5) { force-=0.5; /* Queda */ } /* Toca a música de fundo */ if(!al_get_sample_instance_playing(instance_theme) && !al_get_sample_instance_playing(instance_mlk)) { al_play_sample_instance(instance_theme); } /* Fechar o display */ al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { quit = true; } /* Evento de quando a tecla eh pressionada */ if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: quit = true; break; case ALLEGRO_KEY_SPACE: keys[KEY_SPACE]=true; break; case ALLEGRO_KEY_UP: keys[KEY_UP] = true; if(jump == false) { jump = true; force = gravity; } break; case ALLEGRO_KEY_LEFT: keys[KEY_RIGHT]=false; keys[KEY_LEFT]=true; break; case ALLEGRO_KEY_RIGHT: keys[KEY_LEFT]=false; keys[KEY_RIGHT]=true; break; case ALLEGRO_KEY_F1: if(!al_get_sample_instance_playing(instance_mlk)) { al_play_sample_instance(instance_mlk); al_stop_sample_instance(instance_theme); } break; case ALLEGRO_KEY_M: if(al_get_sample_instance_playing(instance_mlk)) { al_stop_sample_instance(instance_mlk); } break; } } /* Evento de quando a tecla eh solta */ if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_SPACE: keys[KEY_SPACE]=false; break; case ALLEGRO_KEY_UP: keys[KEY_UP] = false; break; case ALLEGRO_KEY_LEFT: keys[KEY_LEFT]=false; break; case ALLEGRO_KEY_RIGHT: keys[KEY_RIGHT]=false; break; } } if(ev.type == ALLEGRO_EVENT_TIMER) { if(ev.timer.source == timer_0p2) { if((iddle == false) && (keys[KEY_RIGHT] == false) && (keys[KEY_LEFT] == false) && (jump == false)) { iddle = true; } } if(ev.timer.source == timer_1) { stopwatch--; } if(ev.timer.source == timer_60) { /* Posicionamento do player*/ player.y-=force; if(keys[KEY_RIGHT]) { player.direction = 1; player.x+=player.speed; } if(keys[KEY_LEFT]) { player.direction = -1; player.x-=player.speed; } if(keys[KEY_SPACE]) { for(i=0; i<NUM_BULLET; i++) { if(!al_get_sample_instance_playing(instance_playerShoot)) { playerShoot(&player, &playerBullet[i], instance_playerShoot); } } } /*Posicionamento do Inimigo */ for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { if(player.x > enemy1[i][j].x + 40) { enemy1[i][j].direction = 1; } else if(player.x + 40 <= enemy1[i][j].x) { enemy1[i][j].direction = -1; } } } /* ~~Posicionamento do projetil~~ */ /* Chance do Inimigo Atirar */ chance_enemy_shoot = rand() % 40; for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { enemyShoot(&player, &enemy1[i][j], enemyBullet, &bulletID, &bulletCount); } } for(i=0; i<NUM_BULLET; i++) { if(!playerBullet[i].live) { playerBullet[i].direction = player.direction; } if(playerBullet[i].live) { if(playerBullet[i].direction == -1) { playerBullet[i].x-=playerBullet[i].speed; } else if(playerBullet[i].direction == 1) { playerBullet[i].x+=playerBullet[i].speed; } } if(enemyBullet[i].live) { if(enemyBullet[i].direction == -1) { enemyBullet[i].x-=enemyBullet[i].speed; } if(enemyBullet[i].direction == 1) { enemyBullet[i].x+=enemyBullet[i].speed; } } } /* Prende a Camera no Personagem */ cameraX = player.x-(SCREEN_W/2); cameraY = player.y-(SCREEN_H/2); /* Fazer com que a camera nao passe dos limites do mapa */ if (cameraX < 0) cameraX = 0; if (cameraY < 0) cameraY = 0; if (cameraX > WORLD_W - SCREEN_W) cameraX = WORLD_W - SCREEN_W; if (cameraY > WORLD_H - SCREEN_H) cameraY = WORLD_H - SCREEN_H; /* Colisoes + check trap */ for (i = 0; i<LINHA_MAX; i++) { for(j = 0; j<COLUNA_MAX; j++) { for(k=0; k<NUM_BULLET; k++) { collision_bullet_player(&player, &enemyBullet[k], img_enemy_bullet, &bulletCount, 40, 40); } if(block[i][j].live == true) { if(mapa[i][j] == 2) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 3) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 4) { check_trap(&player, &block[i][j], &enemy1[i][j], 4); collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 5) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } for(k=0; k<NUM_BULLET; k++) { collision_bullet_tiles(&playerBullet[k], &block[i][j], img_player_bullet, img_block2, 0, &bulletCount); collision_bullet_tiles(&enemyBullet[k], &block[i][j], img_player_bullet, img_block2, 1, &bulletCount); } } if(block[i][j].live == false) { if(mapa[i][j] == 5) { check_trap(&player, &block[i][j], &enemy1[i][j], 5); } if(mapa[i][j] == 6) { collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 7) { check_trap(&player, &block[i][j], &enemy1[i][j], 7); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 8) { check_trap(&player, &block[i][j], &enemy1[i][j], 8); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 9) { check_trap(&player, &block[i][j], &enemy1[i][j], 9); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } } } } collision_player_wall(&player, &jumping, img_block1); /* ~~Desenha o Background~~ */ al_draw_bitmap(img_background0, 0 - cameraX, 0 - cameraY, 0); /* ~~Animação dos inimigos~~ */ if(++anim_enemy1.frameCount >= anim_enemy1.frameDelay) { if(++anim_enemy1.curFrame >= anim_enemy1.maxFrame) { anim_enemy1.curFrame = 0; } anim_enemy1.frameCount = 0; } /* ~~Desenha os Blocos/Inimigos~~ */ for (i = 0; i<LINHA_MAX; i++) { for(j = 0; j<COLUNA_MAX; j++) { if(mapa[i][j] == 2 && block[i][j].live == true) { al_draw_bitmap(img_block1, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 3 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 4 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 5 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if((mapa[i][j] == 6 || mapa[i][j] == 7 || mapa[i][j] == 8) && (enemy1[i][j].direction == -1) && (enemy1[i][j].live == true)) { al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, 0); } if((mapa[i][j] == 6 || mapa[i][j] == 7 || mapa[i][j] == 8) && (enemy1[i][j].direction == 1) && (enemy1[i][j].live == true)) { al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(mapa[i][j] == 9 && enemy1[i][j].live == true) { al_draw_bitmap_region(img_boss1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, 0); } } } /* ~~Desenho do player~~ */ /* Player parado */ if(iddle == true) { if(++immobile.frameCount >= immobile.frameDelay) { if(++immobile.curFrame >= immobile.maxFrame) { immobile.curFrame = 0; iddle = false; } immobile.frameCount = 0; } } if((keys[KEY_SPACE] == false) && (jump == false) && ((!keys[KEY_LEFT] && player.direction == -1) || player.x == 64)) { al_draw_bitmap_region(img_player_immobile, immobile.curFrame * immobile.frameWidth, 0, immobile.frameWidth, immobile.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if((keys[KEY_SPACE] == false) && (jump == false) && ((!keys[KEY_RIGHT] && player.direction == 1) || player.x == WORLD_W - (64-immobile.frameWidth))) { al_draw_bitmap_region(img_player_immobile, immobile.curFrame * immobile.frameWidth, 0, immobile.frameWidth, immobile.frameHeight, player.x - cameraX, player.y - cameraY, 0); } if((keys[KEY_SPACE] == true) && (jump == false) && ((!keys[KEY_LEFT] && player.direction == -1))) { al_draw_bitmap(img_player_immobile_shoot, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if((keys[KEY_SPACE] == true) && (jump == false) && ((!keys[KEY_RIGHT] && player.direction == 1))) { al_draw_bitmap(img_player_immobile_shoot, player.x - cameraX, player.y - cameraY, 0); } /* Player andando */ if(++walking.frameCount >= walking.frameDelay) { if(++walking.curFrame >= walking.maxFrame) { walking.curFrame = 0; } walking.frameCount = 0; } if(keys[KEY_SPACE] == false) { if(jump == false && keys[KEY_LEFT] && player.direction == -1) { al_draw_bitmap_region(img_player_walking, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(jump == false && keys[KEY_RIGHT] && player.direction == 1) { al_draw_bitmap_region(img_player_walking, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } if(keys[KEY_SPACE] == true) { if(jump == false && keys[KEY_LEFT] && player.direction == -1) { al_draw_bitmap_region(img_player_walking_shoot, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(jump == false && keys[KEY_RIGHT] && player.direction == 1) { al_draw_bitmap_region(img_player_walking_shoot, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } /* Player pulando */ if(jump == true) { if(++jumping.frameCount >= jumping.frameDelay) { if(++jumping.curFrame >= jumping.maxFrame) { jumping.curFrame = 0; } jumping.frameCount = 0; } if(keys[KEY_SPACE] == false) { if(player.direction == -1) { al_draw_bitmap_region(img_player_jump, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(player.direction == 1) { al_draw_bitmap_region(img_player_jump, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } else if(keys[KEY_SPACE] == true) { if(player.direction == -1) { al_draw_bitmap_region(img_player_jump_shoot, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(player.direction == 1) { al_draw_bitmap_region(img_player_jump_shoot, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } } /* ~~Desenho dos projeteis~~ */ for(i=0; i<NUM_BULLET; i++) { if(playerBullet[i].live) { al_draw_bitmap(img_player_bullet, playerBullet[i].x - cameraX, playerBullet[i].y - cameraY, 0); } if(enemyBullet[i].live) { al_draw_bitmap(img_enemy_bullet, enemyBullet[i].x - cameraX, enemyBullet[i].y - cameraY, 0); } } /* Pontuacao e Porcentagem de Vida */ al_draw_bitmap(img_heart, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 20, 0, ALLEGRO_ALIGN_LEFT, ("%03d"), player.life); al_draw_bitmap(img_medal, 64, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 80, 0, ALLEGRO_ALIGN_LEFT, ("%04d"), scores); al_draw_bitmap(img_clock, 144, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 160, 0, ALLEGRO_ALIGN_LEFT, ("%03d"), stopwatch); } /* Termino da Fase */ if(enemyKilled == ENEMY_MAX) /* You Win! */ { scores = scores + (25 * stopwatch) + (10*player.life); gamestate = 2; } if(player.life <= 0 || stopwatch == 0) /* Game Over! */ { gamestate = 3; } /* Troca o display */ al_flip_display(); } break; case 2: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(img_you_win, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(0, 0, 0), SCREEN_W/2, SCREEN_H - 48, ALLEGRO_ALIGN_CENTRE, "Seus pontos: %d", scores); al_draw_textf(fonte16, al_map_rgb(0, 0, 0), SCREEN_W/2, SCREEN_H - 32, ALLEGRO_ALIGN_CENTRE, "Pressione Esc para sair"); al_flip_display(); } } break; case 3: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(img_game_over, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 0, 0), SCREEN_W/2, SCREEN_H - 48, ALLEGRO_ALIGN_CENTRE, "Seus pontos: %d", scores); al_draw_textf(fonte16, al_map_rgb(255, 0, 0), SCREEN_W/2, SCREEN_H - 32, ALLEGRO_ALIGN_CENTRE, "Pressione Esc para sair"); al_flip_display(); } } break; } } /* Destruindo as variaveis */ al_destroy_display(display); al_destroy_event_queue(event_queue); al_destroy_timer(timer_0p2); al_destroy_timer(timer_1); al_destroy_timer(timer_60); al_destroy_bitmap(img_home_screen); al_destroy_bitmap(img_dica_h1n1); al_destroy_bitmap(img_background0); al_destroy_bitmap(img_heart); al_destroy_bitmap(img_medal); al_destroy_bitmap(img_clock); al_destroy_bitmap(img_block1); al_destroy_bitmap(img_block2); al_destroy_bitmap(img_player_walking); al_destroy_bitmap(img_player_walking_shoot); al_destroy_bitmap(img_player_immobile); al_destroy_bitmap(img_player_immobile_shoot); al_destroy_bitmap(img_player_jump); al_destroy_bitmap(img_player_jump_shoot); al_destroy_bitmap(img_player_bullet); al_destroy_bitmap(img_enemy1); al_destroy_bitmap(img_boss1); al_destroy_bitmap(img_enemy_bullet); al_destroy_sample(spl_theme); al_destroy_sample(spl_playerShoot); al_destroy_sample(spl_mlk); return 0; }