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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <allegro.h>
#define Down 0
#define Left 32
#define Right 64
#define Up 96
volatile bool Close = false;
void Handler () {Close = true;}
volatile long speed_counter = 0;
void increment_speed_counter(){speed_counter++;}
int main()
{
allegro_init();
install_timer();
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED,1280,720,0,0);
LOCK_FUNCTION(Handler);
LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
BITMAP *Buffer = create_bitmap(1280,720);
BITMAP *Hero_char = load_bitmap("hero_char.bmp", NULL);
BITMAP *one = load_bitmap("1.bmp", NULL);
int x=0, y=0;
int x1=0, y1=0;
int imgx=32 , imgy=Down;
set_close_button_callback (Handler);
while (!Close)
{
while(speed_counter > 0)
{
if (key [KEY_ESC])
Close = true;
if (key [KEY_UP])
{
imgy=Up;
y -= 5;
}
if (key [KEY_DOWN])
{
imgy=Down;
y += 5;
}
if (key [KEY_RIGHT])
{
imgy=Right;
x += 5;
}
if (key [KEY_LEFT])
{
imgy=Left;
x -= 5;
}
speed_counter --;
if (!key [KEY_UP] && !key [KEY_DOWN] && !key [KEY_RIGHT] && !key [KEY_LEFT])
imgx=32;
else
imgx +=32;
if (imgx > 64)
imgx = 0;
}
//screen collision
if (x>=1250)
x = 1250;
if (x<=-1)
x = -1;
if (y>=690)
y = 690;
if (y<=-1)
y = -1;
//End of screen collision
masked_blit (Hero_char , Buffer , imgx , imgy , x, y , 32 , 32);
masked_blit (one , Buffer ,x1 , y1, x1+200 , y1+200, 32 , 32);
blit(Buffer, screen, 0, 0, 0, 0, 1280, 720);
clear_bitmap(Buffer);
}
destroy_bitmap(Hero_char);
destroy_bitmap(Buffer);
return 0;
}
END_OF_MAIN()
|