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
|
#define down 0;
#define left 32;
#define right 64;
#define up 96;
#include <allegro.h>
#include <iostream>
int startup();
int main()
{
startup();
BITMAP *buffer = create_bitmap(800, 600);
BITMAP *bg = load_bitmap("bg.bmp", NULL);
BITMAP *sprite = load_bitmap("player.bmp", NULL);
int x,y;
x = 100;
y = 100;
int imageX = 32;
int imageY = down;
while(!key [KEY_ESC])
{
if(key[KEY_D])
{
imageY = right;
x += 1;
}
else if(key[KEY_A])
{
imageY = left;
x -= 1;
}
else if(key[KEY_W])
{
imageY = up;
y -= 1;
}
else if(key[KEY_S])
{
imageY = down;
y += 1;
}
if(key[KEY_S] && key[KEY_LSHIFT])
y += 1;
else if(key[KEY_W] && key[KEY_LSHIFT])
y -= 1;
else if(key[KEY_D] && key[KEY_LSHIFT])
x += 1;
else if(key[KEY_A] && key[KEY_LSHIFT])
x -= 1;
if(!key [KEY_S] && !key [KEY_W] && !key [KEY_A] && !key [KEY_D])
imageX = 32;
else
{
rest(5);
imageX += 32;
}
if(imageX > 64)
imageX = 0;
blit(bg, buffer,0,0,0,0, bg->w, bg->h);
masked_blit(sprite, buffer, imageX, imageY, x, y, 32, 32);
blit(buffer, screen,0,0,0,0, buffer->w, buffer->h);
clear(buffer);
}
clear(screen);
destroy_bitmap(buffer);
destroy_bitmap(bg);
destroy_bitmap(sprite);
return 0;
}
END_OF_MAIN();
|