int main (int argc, char **argv) { Mario mario; ALLEGRO_BITMAP *mario_spritesheet = NULL; bool tecla[4] = { false, false, false, false }; int sprite_number = 0; srand (time (NULL)); iniciar_allegro (); mario_spritesheet = al_load_bitmap (SPRITESHEET); if (!mario_spritesheet) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } mario.set_dibujo (mario_spritesheet); while (1) { /* Buzz Lightyear */ ALLEGRO_EVENT ev; ALLEGRO_TIMEOUT timeout; al_init_timeout (&timeout, 0.06); bool get_event = al_wait_for_event_until (event_queue, &ev, &timeout); if (get_event) { if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (ev.type == ALLEGRO_EVENT_TIMER) redraw = true; if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: tecla[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: tecla[KEY_DOWN] = true; break; case ALLEGRO_KEY_LEFT: tecla[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: tecla[KEY_RIGHT] = true; break; } } if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: tecla[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: tecla[KEY_DOWN] = false; break; case ALLEGRO_KEY_LEFT: tecla[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: tecla[KEY_RIGHT] = false; break; case ALLEGRO_KEY_LSHIFT: sprite_number++; break; } } } /* Actualizar las coordenadas de la pelota */ if (tecla[KEY_UP]) mario.change_vy(-DELTA); if (tecla[KEY_DOWN]) mario.change_vy(DELTA); if (tecla[KEY_LEFT]) mario.change_vx(-DELTA); if (tecla[KEY_RIGHT]) mario.change_vx(DELTA); mario.actualizate(); if (redraw && al_is_event_queue_empty (event_queue)) { al_clear_to_color (al_map_rgb (0, 0, 0)); for (int i = 0; i < N; i++) al_draw_bitmap (mario.get_dibujo (), mario.get_x () + 450, mario.get_y () + 450, 0); al_flip_display (); redraw = false; } } al_destroy_bitmap (mario_spritesheet); destruir_allegro (); return 0; }
int main (int argc, char **argv) { Pelota pelota[N]; srand (time (NULL)); iniciar_allegro (); for (int i = 0; i < N; i++) pelota[i].set_dibujo (bm); while (1) { /* Buzz Lightyear */ ALLEGRO_EVENT ev; ALLEGRO_TIMEOUT timeout; al_init_timeout (&timeout, 0.06); bool get_event = al_wait_for_event_until (event_queue, &ev, &timeout); if (get_event) { if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (ev.type == ALLEGRO_EVENT_TIMER) redraw = true; if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: tecla[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: tecla[KEY_DOWN] = true; break; case ALLEGRO_KEY_LEFT: tecla[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: tecla[KEY_RIGHT] = true; break; } } if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: tecla[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: tecla[KEY_DOWN] = false; break; case ALLEGRO_KEY_LEFT: tecla[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: tecla[KEY_RIGHT] = false; break; case ALLEGRO_KEY_LSHIFT: sprite_number++; break; } } } /* Actualizar las coordenadas de la pelota */ if (tecla[KEY_UP]) pelota.change_vy (-DELTA); if (tecla[KEY_DOWN]) pelota.change_vy (DELTA); if (tecla[KEY_LEFT]) pelota.change_vx (-DELTA); if (tecla[KEY_RIGHT]) pelota.change_vx (DELTA); for (int i = 0; i < N; i++) pelota[i].actualizate (); if (redraw && al_is_event_queue_empty (event_queue)) { al_clear_to_color (al_map_rgb (0, 0, 0)); al_draw_bitmap (bm2, 0, 0, 0); for (int i = 0; i < N; i++) al_draw_bitmap (pelota[i].get_dibujo (), pelota[i].get_x () + 450, pelota[i].get_y () + 450, 0); al_flip_display (); redraw = false; } } destruir_allegro (); return 0; }
int main (int argc, char **argv) { Prota mi_nave; Nave enemigo; ALLEGRO_BITMAP *xenon_spritesheet = NULL; ALLEGRO_BITMAP *enemy_spritesheet = NULL; ALLEGRO_BITMAP *bg = NULL; bool tecla[4] = { false, false, false, false }; srand (time (NULL)); iniciar_allegro (); xenon_spritesheet = al_load_bitmap (SPRITESHEET); enemy_spritesheet = al_load_bitmap (ENEMY); bg = al_load_bitmap (BG); al_convert_mask_to_alpha(xenon_spritesheet, al_map_rgb(255, 0, 255)); if (!xenon_spritesheet) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } mi_nave.set_dibujo (xenon_spritesheet); al_convert_mask_to_alpha(enemy_spritesheet, al_map_rgb(255, 0, 255)); if (!enemy_spritesheet) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } enemigo.set_dibujo (enemy_spritesheet); al_convert_mask_to_alpha(bg, al_map_rgb(255, 0, 255)); if (!bg) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } while (1) { /* Buzz Lightyear */ ALLEGRO_EVENT ev; ALLEGRO_TIMEOUT timeout; al_init_timeout (&timeout, 0.06); bool get_event = al_wait_for_event_until (event_queue, &ev, &timeout); if (get_event) { if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (ev.type == ALLEGRO_EVENT_TIMER) redraw = true; if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: tecla[KEY_UP] = true; break; case ALLEGRO_KEY_DOWN: tecla[KEY_DOWN] = true; break; case ALLEGRO_KEY_LEFT: tecla[KEY_LEFT] = true; break; case ALLEGRO_KEY_RIGHT: tecla[KEY_RIGHT] = true; break; } } if (ev.type == ALLEGRO_EVENT_KEY_UP) { switch (ev.keyboard.keycode) { case ALLEGRO_KEY_UP: tecla[KEY_UP] = false; break; case ALLEGRO_KEY_DOWN: tecla[KEY_DOWN] = false; break; case ALLEGRO_KEY_LEFT: tecla[KEY_LEFT] = false; break; case ALLEGRO_KEY_RIGHT: tecla[KEY_RIGHT] = false; break; } } } /* Actualizar las coordenadas de la pelota */ if (tecla[KEY_UP]) mi_nave.change_vy(-DELTA); if (tecla[KEY_DOWN]) mi_nave.change_vy(DELTA); if (tecla[KEY_LEFT]) mi_nave.change_vx(-DELTA); if (tecla[KEY_RIGHT]) mi_nave.change_vx(DELTA); mi_nave.actualizate(); if (redraw && al_is_event_queue_empty (event_queue)) { al_clear_to_color (al_map_rgb (0, 0, 0)); al_draw_bitmap_region (bg,0,0,1024,768,0,0,0); al_draw_bitmap_region (mi_nave.get_dibujo (), mi_nave.get_sprite_number() * 33, 99, 32, 27, mi_nave.get_x (), mi_nave.get_y (), 0); enemigo.move(); al_draw_bitmap_region(enemigo.get_dibujo(), enemigo.get_sprite_number() * 1, 33, 32, 32, enemigo.get_x (), enemigo.get_y (), 0); al_flip_display (); redraw = false; } } al_destroy_bitmap (xenon_spritesheet); destruir_allegro (); return 0; }
int main (int argc, char *argv[]) { ALLEGRO_BITMAP *background = NULL; ALLEGRO_BITMAP *title = NULL; ALLEGRO_BITMAP *terrain = NULL; ALLEGRO_BITMAP *play = NULL; ALLEGRO_BITMAP *ranking = NULL; ALLEGRO_BITMAP *footer = NULL; ALLEGRO_BITMAP *playstart = NULL; int pos_x; int pos_y; srand (time (NULL)); iniciar_allegro (); al_install_mouse (); background = al_load_bitmap (SPRITESHEET); title = al_load_bitmap (SPRITESHEET); terrain = al_load_bitmap (SPRITESHEET); play = al_load_bitmap (SPRITESHEET); ranking = al_load_bitmap (SPRITESHEET); footer = al_load_bitmap (SPRITESHEET); playstart = al_load_bitmap (SPRITESHEET); if (!playstart) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del play start n***a", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!background) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del background", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!title) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del titulo", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!terrain) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del terreno", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!play) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del play", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!ranking) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del ranking", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!footer) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del footer", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } while(1){ ALLEGRO_EVENT ev; ALLEGRO_TIMEOUT timeout; al_init_timeout (&timeout, 0.00); bool get_event = al_wait_for_event_until (event_queue, &ev, &timeout); if (get_event){ if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES){ pos_x = ev.mouse.x; pos_y = ev.mouse.y; } if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN){ if(ev.mouse.button & 1) break; } } if(redraw && al_is_event_queue_empty (event_queue)) { al_clear_to_color (al_map_rgb (0, 0, 0)); al_draw_bitmap_region(background, 0, 0, 288, 512, 0, 0, 0); al_draw_bitmap_region(title, 702, 182, 178, 48, 50, 110, 0); al_draw_bitmap_region(terrain, 584, 0 , 288, 112 , 0, 400, 0); al_draw_bitmap_region(playstart, 709, 314, 104, 56, 30, 344, 0); al_draw_bitmap_region(play, 708, 235, 104, 56, 30, 344, 0); al_draw_bitmap_region(ranking, 829, 235, 104, 56, 150, 344, 0); al_draw_bitmap_region(footer, 885, 182, 140, 20, 80, 418, 0); al_flip_display(); redraw = false; } } al_destroy_bitmap (background); al_destroy_bitmap (title); al_destroy_bitmap (terrain); al_destroy_bitmap (play); al_destroy_bitmap (playstart); al_destroy_bitmap (ranking); al_destroy_bitmap (footer); destruir_allegro (); return 0; }