#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5\allegro_primitives.h>
int main(void)
{
int height = 480, width = 640;
bool done = false;
int posX = width / 2, posY = height / 2;
if (!al_init())
{
al_show_native_message_box(NULL,"Error", "Error", "Failed to initialise the Allegro library!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
if (!event_queue)
{
al_show_native_message_box(NULL, "Error", "Error", "Failed to create event queue!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
display = al_create_display(width, height);
if (!display)
{
al_show_native_message_box(display, "Error", "Error", "Failed to create display!", "Alright", ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_init_primitives_addon();
al_install_keyboard();
event_queue = al_create_event_queue();
al_register_event_source(event_queue, al_get_keyboard_event_source());
while(!done)
{
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
{
switch(ev.keyboard.keycode)
{
case ALLEGRO_KEY_UP:
posY -= 10;
break;
case ALLEGRO_KEY_DOWN:
posY += 10;
break;
case ALLEGRO_KEY_LEFT:
posX -= 10;
break;
case ALLEGRO_KEY_RIGHT:
posX += 10;
break;
}
}
al_draw_filled_rectangle(posX, posY, posX = 30, posY + 30, al_map_rgb(255, 0, 255));
al_flip_display();
al_clear_to_color(al_map_rgb(0, 0, 0));
}
al_destroy_display(display);
return 0;
}
Edited by robbiewoods05, 02 May 2012 - 11:32 AM.






