allegro 5, gra, problem ze setrowaniem graczem- pozostawia po sobie sciezke

0

mam problem bo po uruchomieniu gry gdy poruszam ludikiem to zostawia po sobie slady

#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_image.h>
//#include <allegro5/allegro_tff.h>//!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include<iostream>

#define ScreenHeight 1090
#define ScreenWidth 637

int main()
{       al_init();
        al_install_keyboard();

        const float FPS=60.0;
        enum Direction {DOWN, RIGHT, LEFT, UP}; //KIERUNKI zmienne zdefiniowane przeze mnie, wyliczenia

        al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); //mozliwosc zmiany recznej rozmiaru ekranu
        ALLEGRO_DISPLAY *display = al_create_display(ScreenWidth,ScreenHeight);//rozmiar
         al_set_window_position(display, 200,100); //pozycja ekranu
        al_set_window_title(display, "ICE CLIMBER"); //tytul gry

    al_flip_display();

    al_rest(2.0);

        bool done = false, draw=true, active = false;
        float x = 50, y = 50, moveSpeed = 5;

        int dir =DOWN, sourceX = 32, sourceY = 25 ;

        al_init_image_addon();  //// ZEZWOLENIE NA DODANIE ODBRAZU
        al_init_primitives_addon();
        al_install_keyboard;
        al_install_audio();
        al_init_acodec_addon();

         al_reserve_samples(2);

        ALLEGRO_SAMPLE *soundEffect = al_load_sample("soundEffect.wav");
        ALLEGRO_SAMPLE *song = al_load_sample("music.ogg");

        ALLEGRO_SAMPLE_INSTANCE *songInstance = al_create_sample_instance(song);
        al_set_sample_instance_playmode(songInstance, ALLEGRO_PLAYMODE_LOOP);
        al_attach_sample_instance_to_mixer(songInstance, al_get_default_mixer());

        ALLEGRO_BITMAP  *player[4];
                        player[0] = al_load_bitmap("1.png");
                        player[1] = al_load_bitmap("2.png");
                        player[2] = al_load_bitmap("3.png");
                        player[3] = al_load_bitmap("4.png");

       ALLEGRO_BITMAP *background = al_load_bitmap("backgr.png");

        ALLEGRO_KEYBOARD_STATE keyState;

        ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); //timer plynnosc

        ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();

        al_register_event_source(event_queue, al_get_keyboard_event_source());
        al_register_event_source(event_queue, al_get_timer_event_source(timer));
        al_register_event_source(event_queue, al_get_display_event_source(display));
        //poruszanie

        //int state=NULL;
            al_play_sample_instance(songInstance);
            al_start_timer(timer);

                            al_draw_bitmap (background,0,0,0);
                            al_draw_bitmap( player[0], x+32, y+32, 0 );
                            al_flip_display();

        while (!done)
        {
            ALLEGRO_EVENT events;
            al_wait_for_event(event_queue, &events); //czeka az zostanie nacisniety przycisk
            al_get_keyboard_state(&keyState);

            if (events.type == ALLEGRO_EVENT_KEY_DOWN)
            {
                switch(events.keyboard.keycode)
                {

                    case ALLEGRO_KEY_ESCAPE:
                        done = true;
                            break;
                }
            }
                active=true;

            if (events.type == ALLEGRO_EVENT_TIMER)
            {

                   if (al_key_down(&keyState, ALLEGRO_KEY_DOWN))                                                  //PANEL STEROWANIA
                        {y += moveSpeed;
                         dir = DOWN;

                            al_draw_bitmap (background,0,0,0);
                            al_draw_bitmap( player[0], x+32, y+32, 0 );
                            al_flip_display();

                         al_play_sample(soundEffect, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
                        }

                    else if (al_key_down(&keyState, ALLEGRO_KEY_UP))
                         {y -= moveSpeed;
                          dir = UP;
                          al_draw_bitmap (background,0,0,0);
                            al_draw_bitmap( player[3], x+32, y+32, 0 );
                            al_flip_display();
                          al_play_sample(soundEffect, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
                         }

                    else if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT))
                          {x+= moveSpeed;
                            dir = RIGHT;
                            al_draw_bitmap (background,0,0,0);
                            al_draw_bitmap( player[2], x+32, y+32, 0 );
                            al_flip_display();
                            al_play_sample(soundEffect, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
                          }
                    else if (al_key_down(&keyState, ALLEGRO_KEY_LEFT))
                         {x -= moveSpeed;
                           dir =LEFT;
                            al_draw_bitmap (background,0,0,0);
                            al_draw_bitmap( player[1], x+32, y+32, 0 );
                            al_flip_display();

                           al_play_sample(soundEffect, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
                         }
                    else
                    {

                        active = false;
                     al_draw_bitmap (background,0,0,0);
                            al_draw_bitmap( player[0], x+32, y+32, 0 );
                            al_flip_display();
                    }

            if (draw)
            {

                al_flip_display();
                al_draw_bitmap (background,0,0,0);
            }
        }
        }
        al_destroy_display(display);
        al_destroy_timer(timer);
        al_destroy_bitmap(background);
        al_destroy_bitmap(player[4]);

        al_destroy_sample(soundEffect);
        al_destroy_sample(song);
        al_destroy_sample_instance(songInstance);
        al_destroy_event_queue(event_queue);

return 0;
}
1

NIe znam tej biblioteki, ale zapewne brakuje Ci jakiejś funkcji w pętli głównej do czyszczenia ekranu co każdą klatkę. Szukaj w tym kierunku.

0

wlasnie to ogarnelam, takze wszystko dziala :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1