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
|
#include <allegro.h>
#include <fstream>
#include <iostream>
#include <string>
#define Down 0
#define Left 32
#define Right 64
#define Up 96
using namespace std;
int main()
{
allegro_init();
install_keyboard();
install_mouse();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
clear_to_color(screen, makecol(0, 0, 0));
set_window_title("Game");
BITMAP *Buffer = create_bitmap(640, 480);
BITMAP *GrantCity = load_bitmap("Testmap.bmp", NULL);
BITMAP *Player = load_bitmap("Player.bmp", NULL);
bool done = false;
int x, y;
x = 0, y = 400;
int ImageX = 32, ImageY = Down;
while(done == false){
if(key[KEY_ESC])
done = true;
if(key[KEY_RIGHT]){
ImageY = Right;
x += 5;
}
else if(key[KEY_LEFT]){
ImageY = Left;
x -= 5;
}
else if(key[KEY_DOWN]){
ImageY = Down;
y += 5;
}
else if(key[KEY_UP]){
ImageY = Up;
y -= 5;
}
if(!key [KEY_RIGHT] && !key [KEY_LEFT] && !key [KEY_UP] && !key [KEY_DOWN])
ImageX = 32;
else
ImageX += 32;
if(ImageX > 64)
ImageX = 0;
blit(GrantCity, Buffer, 0, 0, 0, 0, 640, 480);
masked_blit(Player, Buffer, ImageX, ImageY, x, y, 32, 32);
blit(Buffer, screen, 0, 0, 0, 0, 640, 480);
//rest(40);
//clear_bitmap(Buffer);
}
return 0;
}
END_OF_MAIN()
|