I'd like to spend the next few weeks learning the basics of Allegro 5 (I think it's finally time to say goodbye to Allegro 4). I know A5 is event based unlike A4, so the basic game loop is going to be different.
I won't have much spare time between paid work and moving so I don't want to spend too much time reinventing wheels, and as I learn best from dissecting code rather than from tutorials, I'm hoping someone could give me an example of a basic event driven gameloop. Just something simple like looping a large background image over a smaller window would be good to get me started I think. I can add extra functionality (input etc, from there).
Thanks in advance.
edit:
This is the code I tried to do the above, but I seem to have missed something somewhere, as I'm trying to increment an x value which represents the position on the larger bitmap to draw from, but x never seems to increment. I tried it without using the timer and just increased x each loop and that worked, but I want it to run at a set rate.
Where is al_start_timer ?
Where is al_start_timer ?
I knew I'd missed something really obvious.
I honestly can't recall the issues I had with Allegro 5 when i first switched. It was just a matter of getting used to the events, which was trivial.
The only thing that popped into my head was where I added in a function similar to A4's to check if a key was pressed, and wrote my own wait for keypress function. Otherwise... it's pretty simple and honestly quite nice. The benefits outweigh any nitpicks I ever had (like the sound system, and some minor joystick issues I forget about now).
This was handy as I was used to having a similar function in A4...
// Returns whether or not a specified key is being pressed bool key_pressed(int key) { ALLEGRO_KEYBOARD_STATE s; al_get_keyboard_state(&s); return al_key_down(&s, key); }
This was a function I wrote for Deluxe Pacman 2 to wait for a keypress or xxxx amount of milliseconds before continuing (this is the trimmed down version)...
Looks nice!
I'm thinking about writing a side-scrolling shooter and having this as the background.