Im trying to teach myself allegro, but i am already getting stuck. i've built a simple walking engine but when i press the arrow keys it just places a copy of the bmp file next to the original one, instead of moving it. can anyone help me?
main.cpp
#include "basics/initFunctions.h"
void init();
void deinit();
int main() {
init();
while (!key[KEY_ESC]) {
int paused = 0;
int x = 0; int y = 0;
char* src = "images/link.bmp";
if (key[KEY_UP]) y-=10;
else if (key[KEY_DOWN]) y+=10;
else if (key[KEY_RIGHT]) x+=10;
else if (key[KEY_LEFT]) x-=10;
BITMAP *my_pic = NULL;
my_pic = load_bitmap(src, NULL);
blit(my_pic, screen, 0,0,x,y,16,16);
readkey();
destroy_bitmap(my_pic);
}
deinit();
return 0;
}
END_OF_MAIN()
initFunctions.h
// initFunctions begins/ends game
void init();
void deinit();
initFunctions.cpp
#include <allegro.h>
#include "initFunctions.h"
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 563, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}