Advertisement
Guest User

Untitled

a guest
Feb 17th, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <allegro5/allegro.h>
  4. #include <allegro5/allegro_image.h>
  5.  
  6. ALLEGRO_DISPLAY *display = NULL;
  7. const int SCREEN_W = 640,
  8.         SCREEN_H = 480;
  9.  
  10. void quit(bool condition, const char* quitMessage) {
  11.     if (condition) {
  12.         fprintf(stderr, quitMessage);
  13.         al_destroy_display(display);
  14.         exit(-1);
  15.     }
  16. }
  17.  
  18. int main(int argc, char **argv) {
  19.  
  20.     ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  21.     ALLEGRO_BITMAP *bg = NULL;
  22.     ALLEGRO_BITMAP *tile = NULL;
  23.     ALLEGRO_BITMAP *tilebmp = NULL;
  24.  
  25.     quit(!al_init(),
  26.             "failed to initialize allegro!\n");
  27.     quit(!(display = al_create_display(SCREEN_W, SCREEN_H)),
  28.             "failed to create display!\n");
  29.     quit(!(event_queue = al_create_event_queue()),
  30.             "failed to create event_queue!\n");
  31.     quit(!al_init_image_addon(),
  32.             "failed to initialize image addon!\n");
  33.     quit(!(bg = al_load_bitmap("resources\\bg.png")),
  34.             "failed to load image!\n");
  35.     quit(!(tile = al_load_bitmap("resources\\tile.png")),
  36.             "failed to load image!\n");
  37.     quit(!(tilebmp = al_load_bitmap("resources\\tile.bmp")),
  38.             "failed to load image!\n");
  39.  
  40.     al_register_event_source(event_queue, al_get_display_event_source(display));
  41.  
  42.     al_clear_to_color(al_map_rgb(0,0,0));
  43.     al_flip_display();
  44.  
  45.     while(1) {
  46.         ALLEGRO_EVENT ev;
  47.         ALLEGRO_TIMEOUT timeout;
  48.         al_init_timeout(&timeout, 0.06);
  49.  
  50.         bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
  51.  
  52.         if (get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
  53.         break;
  54.         }
  55.  
  56.         al_clear_to_color(al_map_rgb(255,255,255));
  57.         al_draw_bitmap(tile,32,32,0);
  58.         al_draw_bitmap(tilebmp,128,32,0);
  59.         al_flip_display();
  60.     }
  61.  
  62.     al_destroy_display(display);
  63.     al_destroy_event_queue(event_queue);
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement