Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <allegro5/allegro5.h>
- #include <allegro5/allegro_image.h>
- #include <allegro5/allegro_primitives.h>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- al_init();
- al_init_image_addon();
- al_init_primitives_addon();
- ALLEGRO_DISPLAY* okienko = al_create_display(320,320);
- al_set_window_position(okienko, 0, 0);
- al_set_window_title(okienko, "ALLEGRO5");
- al_install_keyboard();
- ALLEGRO_KEYBOARD_STATE klawiatura;
- ALLEGRO_BITMAP* itemy = al_load_bitmap("przedmioty.png");
- ALLEGRO_BITMAP* ludzik = al_load_bitmap("ludzik.png");
- ALLEGRO_BITMAP* tlo = al_load_bitmap("mapa.png");
- int heroX = 0;
- int heroY = 0;
- int zwrot = 0;
- int animacja = 0;
- int maxklatek = 4;
- int mapa[10][10] = {
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,
- };
- while(!al_key_down(&klawiatura, ALLEGRO_KEY_ESCAPE)){
- al_get_keyboard_state(&klawiatura);
- al_draw_bitmap_region(ludzik, animacja*32, zwrot*32, 32, 32, heroX, heroY, 0);
- al_flip_display();
- int y = 0;
- while (y != 10){
- int x = 0;
- while (x != 10){
- al_draw_bitmap_region(tlo, mapa[y][x]*32, 0, 32, 32, x*32, y*32,0);
- x++;
- }
- y++;
- }
- if (al_key_down(&klawiatura, ALLEGRO_KEY_W)){
- heroY -= 32;
- animacja++;
- zwrot = 0;
- }
- else if (al_key_down(&klawiatura, ALLEGRO_KEY_S)){
- heroY += 32;
- animacja++;
- zwrot = 2;
- }
- else if (al_key_down(&klawiatura, ALLEGRO_KEY_D)){
- heroX += 32;
- animacja++;
- zwrot = 1;
- }
- else if (al_key_down(&klawiatura, ALLEGRO_KEY_A)){
- heroX -= 32;
- animacja++;
- zwrot = 3;
- }
- if (animacja == maxklatek)
- animacja = 0;
- al_rest(0.1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement