Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <allegro5/allegro5.h>
  2. #include <allegro5/allegro_image.h>
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <time.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. al_init();
  11. al_init_image_addon();
  12. al_install_keyboard();
  13. ALLEGRO_DISPLAY* okno = al_create_display(320, 320);
  14. ALLEGRO_KEYBOARD_STATE klawiatura;
  15.  
  16. int mapa[10][10] =
  17. {
  18. 1,1,1,1,1,1,1,1,1,1,
  19. 1,3,1,1,2,1,1,1,1,1,
  20. 1,1,3,1,1,1,1,1,1,1,
  21. 1,1,1,2,1,1,1,1,1,1,
  22. 3,1,1,3,1,1,1,1,1,1,
  23. 1,1,1,3,3,1,1,1,1,1,
  24. 1,1,1,1,1,1,1,1,1,1,
  25. 1,1,3,1,1,1,1,1,1,1,
  26. 1,2,1,1,2,1,1,1,5,5,
  27. 1,1,1,1,1,1,1,5,5,5
  28. };
  29. ALLEGRO_BITMAP* obrazekMapki = al_load_bitmap("mapa.png");
  30. ALLEGRO_BITMAP* ludzik = al_load_bitmap("ludzik.png");
  31. int heroX = 0;
  32. int heroY = 0;
  33. int heroSX = 0;
  34. int heroSY = 0;
  35. enum {N, E, S, W};
  36.  
  37. while(1)
  38. {
  39. al_get_keyboard_state(&klawiatura);
  40. if (al_key_down(&klawiatura, ALLEGRO_KEY_W))
  41. {
  42. heroY-=32;
  43. heroSY = N;
  44. }
  45. if (al_key_down(&klawiatura, ALLEGRO_KEY_S))
  46. {
  47. heroY+=32;
  48. heroSY = S;
  49. }
  50. if (al_key_down(&klawiatura, ALLEGRO_KEY_D))
  51. {
  52. heroX+=32;
  53. heroSY = E;
  54. }
  55. if (al_key_down(&klawiatura, ALLEGRO_KEY_A))
  56. {
  57. heroX-=32;
  58. heroSY = W;
  59. }
  60.  
  61. for (int y = 0; y < 10; y++)
  62. {
  63. for(int x = 0; x < 10; x++)
  64. {
  65. al_draw_bitmap_region(obrazekMapki, mapa[y][x]*32, 0, 32, 32, x*32, y*32, 0);
  66. }
  67. }
  68.  
  69. al_draw_bitmap_region(ludzik, heroSX*32, heroSY*32, 32, 32, heroX, heroY, 0);
  70.  
  71. al_flip_display();
  72. al_rest(0.1);
  73. }
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement