Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro5/allegro5.h>
- #include <allegro5/allegro_image.h>
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int main()
- {
- al_init();
- al_init_image_addon();
- al_install_keyboard();
- ALLEGRO_DISPLAY* okno = al_create_display(320, 320);
- ALLEGRO_KEYBOARD_STATE klawiatura;
- int mapa[10][10] =
- {
- 1,1,1,1,1,1,1,1,1,1,
- 1,3,1,1,2,1,1,1,1,1,
- 1,1,3,1,1,1,1,1,1,1,
- 1,1,1,2,1,1,1,1,1,1,
- 3,1,1,3,1,1,1,1,1,1,
- 1,1,1,3,3,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,1,1,
- 1,1,3,1,1,1,1,1,1,1,
- 1,2,1,1,2,1,1,1,5,5,
- 1,1,1,1,1,1,1,5,5,5
- };
- ALLEGRO_BITMAP* obrazekMapki = al_load_bitmap("mapa.png");
- ALLEGRO_BITMAP* ludzik = al_load_bitmap("ludzik.png");
- int heroX = 0;
- int heroY = 0;
- int heroSX = 0;
- int heroSY = 0;
- enum {N, E, S, W};
- while(1)
- {
- al_get_keyboard_state(&klawiatura);
- if (al_key_down(&klawiatura, ALLEGRO_KEY_W))
- {
- heroY-=32;
- heroSY = N;
- }
- if (al_key_down(&klawiatura, ALLEGRO_KEY_S))
- {
- heroY+=32;
- heroSY = S;
- }
- if (al_key_down(&klawiatura, ALLEGRO_KEY_D))
- {
- heroX+=32;
- heroSY = E;
- }
- if (al_key_down(&klawiatura, ALLEGRO_KEY_A))
- {
- heroX-=32;
- heroSY = W;
- }
- for (int y = 0; y < 10; y++)
- {
- for(int x = 0; x < 10; x++)
- {
- al_draw_bitmap_region(obrazekMapki, mapa[y][x]*32, 0, 32, 32, x*32, y*32, 0);
- }
- }
- al_draw_bitmap_region(ludzik, heroSX*32, heroSY*32, 32, 32, heroX, heroY, 0);
- al_flip_display();
- al_rest(0.1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement