#include <cmath>
#include <allegro.h>

#define PI 3.14159265

int main() {

   allegro_init();
    install_keyboard();

    set_color_depth(desktop_color_depth());
    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) {

        allegro_message("Couldn't set graphics mode: 640x480.\n");
        return 1;

    }

    int x=100, y=100, angle=105, lenght=0;
    //  next x=110, next y = 110
    lenght=10;

    BITMAP *bmp=load_bitmap("pic.bmp",NULL);

    rotate_sprite(screen, bmp, x, y, itofix(angle/1.40625));
    x=x+lenght*cos(angle*PI/180);
    y=y+lenght*sin(angle*PI/180);

    while(!key[KEY_ESC]) {
    if(key[KEY_RIGHT]||key[KEY_LEFT]||key[KEY_UP]||key[KEY_DOWN]) {
        if(key[KEY_UP]) {
         x=x+lenght*cos(angle*PI/180);
         y=y+lenght*sin(angle*PI/180);
         clear_to_color(screen,makecol(0,0,0));
        rotate_sprite(screen, bmp, x, y, itofix(angle/1.40625));
        }


        if(key[KEY_DOWN]){
         x=x-lenght*cos(angle*PI/180);
         y=y-lenght*sin(angle*PI/180);
          clear_to_color(screen,makecol(0,0,0));
        rotate_sprite(screen, bmp, x, y, itofix(angle/1.40625));
        }


        }
    rest(10);
    }

    return 0;

}
END_OF_MAIN()
