Original Post
Hello guys! I've just started playing with Allegro and, with some tutorial, I've managed to create this little program with some "addiction" to try something new. I'm playing with functions and pointers and I think that I made some mistake while managing them.
Here's the source code (the debugger [VS2010] says that the code is broken in al_wait_for_event())
Let me know what you think about it!
Here's the source code (the debugger [VS2010] says that the code is broken in al_wait_for_event())
#include <stdio.h>
#include <allegro5\allegro5.h>
#include <allegro5\allegro_primitives.h>
#define WIDTH 800
#define HEIGHT 600
int init (ALLEGRO_DISPLAY *, ALLEGRO_EVENT_QUEUE *);
void loop (ALLEGRO_DISPLAY *, ALLEGRO_EVENT_QUEUE *, bool *, int *, int *, int *);
void destroy (ALLEGRO_DISPLAY *, ALLEGRO_EVENT_QUEUE *);
int main (int argc, char * argv[])
{
ALLEGRO_DISPLAY * display = NULL;
ALLEGRO_EVENT_QUEUE * event_queue = NULL;
bool done;
int pos_x, pos_y, mov;
done = false;
pos_x = 0;
pos_y = 0;
mov = 10;
if (!init(display, event_queue))
{
loop(display, event_queue, &done, &pos_x, &pos_y, &mov);
destroy(display, event_queue);
}
return 0;
}
int init (ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE * event_queue)
{
if (!al_init())
return 1;
if (!(display = al_create_display(WIDTH, HEIGHT)))
return 1;
if (!al_install_keyboard())
return 1;
if (!al_init_primitives_addon())
return 1;
if (!(event_queue = al_create_event_queue()))
return 1;
al_register_event_source(event_queue, al_get_keyboard_event_source());
return 0;
}
void loop (ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE * event_queue, bool * done, int * pos_x, int * pos_y, int * mov)
{
ALLEGRO_EVENT ev;
while (!(*done))
{
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
switch (ev.keyboard.keycode)
{
case ALLEGRO_KEY_UP:
* pos_y -= * mov;
break;
case ALLEGRO_KEY_DOWN:
* pos_y += * mov;
break;
case ALLEGRO_KEY_LEFT:
* pos_x -= * mov;
break;
case ALLEGRO_KEY_RIGHT:
* pos_x += * mov;
break;
case ALLEGRO_KEY_X:
* mov += 5;
break;
case ALLEGRO_KEY_Q:
* done = true;
break;
}
al_draw_filled_circle(* pos_x, * pos_y, 5, al_map_rgb(255,0,0));
al_flip_display();
al_clear_to_color(al_map_rgb(0,0,0));
}
return;
}
void destroy (ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE * event_queue)
{
al_destroy_display(display);
al_destroy_event_queue(event_queue);
return;
}Let me know what you think about it!