1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <allegro.h>
#include <cstdlib>
#include <iostream>
int x = 100;
int y = 100;
int tempx = 100;
int tempy = 100;
int dir = 1;
void moveball();
int main(int argc, char *argv[])
{
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
while ( !key[KEY_ESC])
{moveball();}
return EXIT_SUCCESS;
}
void moveball()
{
tempx = x;
tempy = y;
if(dir ==1 && x !=20 && y !=20)
{--x;
--y;}
else if (dir == 2 && x !=20 && y !=460)
{--x;
++y;}
else if (dir == 3 && x !=620 && y !=20)
{++x;
--y;}
else if (dir == 4 && x !=620 && y !=460)
{++x;
++y;}
else
{dir = rand() % 4 + 1;}
acquire_screen();
circlefill (screen, tempx, tempy, 20, makecol(0,0,0));
circlefill (screen, x, y, 20, makecol(225, 50, 225));
release_screen();
rest(10);
}
|