#include <allegro.h>

/* function prototype */
void respondToKeyboard(void);

BITMAP *guy;    /* pointer to guy bitmap */
BITMAP *buffer; /* pointer to the buffer */
int guy_x;  /* the guy x-coordinate */
int guy_y;  /* the guy y-coordinate */
int guy_direction; /* the guys direction */

int main(void)
{
    allegro_init(); /* initialise allegro */
    install_keyboard(); /* install keyboard */
    set_color_depth(desktop_color_depth());    /* set the color depth */
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); /* set graphics mode */
    buffer = create_bitmap(SCREEN_W, SCREEN_H); /* create buffer */
    guy = load_bitmap("kid.bmp", NULL); /* load the bitmap character */
    guy_x = 0;  /* give the guy initial x-coordinate */
    guy_y = 0;  /* give the guy initial y-coordinate */
    while(!key[KEY_ESC])
    {
        respondToKeyboard();    /* allow keyboard input */
        /* clear color to green using buffer */
        clear_to_color(buffer, makecol(0, 255, 0));
        blit(guy, buffer, 0, 0, guy_x, guy_y, guy->w, guy->h);
        blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
        clear_bitmap(buffer);   /* clear the buffer */
    }

    destroy_bitmap(guy);
    destroy_bitmap(buffer);
    return 0;
}
END_OF_MAIN()

void respondToKeyboard()
{
    if (key[KEY_UP])
        guy_y -= 5;
    if (key[KEY_DOWN])
        guy_y += 5;
    if (key[KEY_LEFT])
        guy_x -= 5;
    if (key[KEY_RIGHT])
        guy_x += 5;
}
