Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <allegro5/allegro5.h>
  3. #include <allegro5/allegro_image.h>
  4. #include <allegro5/allegro_primitives.h>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. al_init();
  12. al_init_image_addon();
  13. al_init_primitives_addon();
  14. ALLEGRO_DISPLAY* okienko = al_create_display(320,320);
  15. al_set_window_position(okienko, 0, 0);
  16. al_set_window_title(okienko, "ALLEGRO5");
  17.  
  18. al_install_keyboard();
  19. ALLEGRO_KEYBOARD_STATE klawiatura;
  20.  
  21. ALLEGRO_BITMAP* itemy = al_load_bitmap("przedmioty.png");
  22. ALLEGRO_BITMAP* ludzik = al_load_bitmap("ludzik.png");
  23. ALLEGRO_BITMAP* tlo = al_load_bitmap("mapa.png");
  24.  
  25. int heroX = 0;
  26. int heroY = 0;
  27. int zwrot = 0;
  28. int animacja = 0;
  29. int maxklatek = 4;
  30.  
  31. int mapa[10][10] = {
  32. 5,5,5,5,5,5,5,5,5,5,
  33. 5,5,5,5,5,5,5,5,5,5,
  34. 5,5,5,5,5,5,5,5,5,5,
  35. 5,5,5,5,5,5,5,5,5,5,
  36. 5,5,5,5,5,5,5,5,5,5,
  37. 5,5,5,5,5,5,5,5,5,5,
  38. 5,5,5,5,5,5,5,5,5,5,
  39. 5,5,5,5,5,5,5,5,5,5,
  40. 5,5,5,5,5,5,5,5,5,5,
  41. 5,5,5,5,5,5,5,5,5,5,
  42. };
  43.  
  44. while(!al_key_down(&klawiatura, ALLEGRO_KEY_ESCAPE)){
  45. al_get_keyboard_state(&klawiatura);
  46. al_draw_bitmap_region(ludzik, animacja*32, zwrot*32, 32, 32, heroX, heroY, 0);
  47. al_flip_display();
  48.  
  49. int y = 0;
  50. while (y != 10){
  51. int x = 0;
  52. while (x != 10){
  53. al_draw_bitmap_region(tlo, mapa[y][x]*32, 0, 32, 32, x*32, y*32,0);
  54. x++;
  55. }
  56. y++;
  57. }
  58.  
  59. if (al_key_down(&klawiatura, ALLEGRO_KEY_W)){
  60. heroY -= 32;
  61. animacja++;
  62. zwrot = 0;
  63. }
  64.  
  65. else if (al_key_down(&klawiatura, ALLEGRO_KEY_S)){
  66. heroY += 32;
  67. animacja++;
  68. zwrot = 2;
  69. }
  70.  
  71. else if (al_key_down(&klawiatura, ALLEGRO_KEY_D)){
  72. heroX += 32;
  73. animacja++;
  74. zwrot = 1;
  75. }
  76.  
  77. else if (al_key_down(&klawiatura, ALLEGRO_KEY_A)){
  78. heroX -= 32;
  79. animacja++;
  80. zwrot = 3;
  81. }
  82.  
  83. if (animacja == maxklatek)
  84. animacja = 0;
  85.  
  86. al_rest(0.1);
  87.  
  88. }
  89.  
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement