This post is a portion of Part 5 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- 5.0 – Our First Game
- 5.1 – Our First Game: The Player
- 5.2 – Our First Game: Timing and Movement
- 5.3 – Our First Game: The Projectiles
- 5.4 – Our First Game: The Enemies
- 5.5 – Our First Game: Collision Detection
- 5.6 – Our First Game: Game Logic
- 5.7 – Our First Game: Conclusion
We look at the last object in our game, the comet, and get it integrated. After this it is just collision and game logic remaining.
Full source can be found here.
Notice that the source code is slightly different from the video? Here is why.

Is there a part in your tutorials where you’ll teach us about using gamepads? I’m trying to use the xbox 360 controller right now, and the documentation is so awful it’s just a guessing game for me.
I could do that in a future video. I have a few other things to work on first though.
Awesome tutorials!
Just one question, is it really good to use global constants for stuff like width, or number of comets? Wouldn’t #define macros be better?
Oh yes. Using globals is generally never a great idea, If they are constant it usually isn’t a problem though. Mostly, I was going for the quickest and easiest implementation for the people learning. I didn’t want to bother getting into macros.
I disagree, even though globals are generally not a good idea, they are at least part of the language itself and not preprocessor macro bullshit.
Const stuff is the way to go, macros are just as global and have many inherent problems, just use them when you really need token expansion. (That’s like almost never)
Hi, I’m not native english so I have some difficulties understanding when you explain these 3 lines:
if(rand() % 500 == 0)
comets[i].y = 30 + rand() % (HEIGHT – 60);
srand(time(NULL));
Can you teach me here? Thanks.