Advertisement
Guest User

Allegro bitmap slide thingy

a guest
Mar 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // Allegro turotial.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <allegro5\allegro.h>
  6. #include <allegro5\allegro_image.h>
  7. int main()
  8. {
  9. al_init();
  10. ALLEGRO_DISPLAY * display = al_create_display(640, 480);
  11. ALLEGRO_EVENT_QUEUE * queue;
  12. ALLEGRO_TIMER * timer;
  13. ALLEGRO_BITMAP * bitmap = NULL;
  14.  
  15.  
  16. queue = al_create_event_queue();
  17. timer = al_create_timer(1.0 / 60);
  18. al_install_keyboard();
  19. al_register_event_source(queue, al_get_keyboard_event_source());
  20. al_register_event_source(queue, al_get_display_event_source(display));
  21. al_register_event_source(queue, al_get_timer_event_source(timer));
  22.  
  23. al_init_image_addon();
  24. //haken kruis "as.jpg"
  25. bitmap = al_load_bitmap("haje.jpg");
  26.  
  27. assert(bitmap != NULL);
  28. float x = 0;
  29. bool running = true;
  30. int width = al_get_display_width(display);
  31.  
  32. al_start_timer(timer);
  33. while (running) {
  34. ALLEGRO_EVENT event;
  35. al_wait_for_event(queue, &event);
  36. if (event.type == ALLEGRO_EVENT_KEY_UP || event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
  37. running = false;
  38. if (event.type == ALLEGRO_EVENT_TIMER) {
  39. //rode kleur voor hakenkruis: 221,0,0
  40. al_clear_to_color(al_map_rgb(30, 20, 20));
  41. al_draw_bitmap(bitmap, x += 2, 0, 0);
  42. al_flip_display();
  43. }
  44. if (x > width)
  45. {
  46. x = -al_get_bitmap_width(bitmap);
  47. }
  48. }
  49. al_destroy_timer(timer);
  50. al_destroy_display(display);
  51. al_uninstall_keyboard();
  52. al_destroy_bitmap(bitmap);
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement