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
Wrapping up the functionality of our game, this video covers the remaining game logic that still needs put in place.
Full source can be found here.
Notice that the source code is slightly different from the video? Here is why.
Very good tutorails, I already knew the basics of allegro, but u have explained some details to me I’ve never understand before,thanks!
Also I got a question:
I programmed a little game, after compiling multiple times it began slightly to drop the fps rate the more i compiled it the more it lagged. I figured out there must be some kind of memory leak in my Projekt and what I’ve found out is,you have to call:
al_destroy_timer(timer);
al_destroy_event_queue(event_queue);
at the end of the Game, if u used a timer and a event_queue.
So I just wanted to ask u if u could write the whole destroy functions for ur game, so that nobody gets any kind of memory leaks. Because it’s really hard for a beginner to find all the destroy-functions he needs for all modules of Allegro he uses.
Good luck and success with ur Tutorials 😀
Wow, that is a good point. I can’t believe I forgot to do that. Time to clean some stuff up.
Hi, I have a problem. So I decided to go ahead and implement a class based version of this project instead of go along with your structured base one. I have encountered a problem with updating the lives portion to trigger the loops which end the game. I am positive I could solve the problem, if only I could debug normally. However I don’t know how to do that using Allegro. Any suggestions?
Nevermind, I found the problem by commenting out certain sections. Apparently the al_draw_textf has some serious issue with my program. Haven’t found the solution, but hopefully everything will just work.
Feel free to post or email your code. Also, what do you mean by “debug normally”?
I got it to work, I just undid everything until I got to my last runnable build, then re-entered in the code.
And I mean I put in break points to look at what my code was doing at certain points, and they did not work as intended. I pressed F5 to continue after the break point was triggered and it just looped that break point and my game timer in the Allegro window stopped so nothing was moving.
Hello, after I finished this video seemed to start to have problems with the comets going dead after I hit them with the bullet, instead of going dead right when I hit them they go dead out of nowhere the next time they pop up on the screen after they hit the left side.
This is the code for the CollideBullet function:
void CollideBullet(Bullet bullet[], int bSize, Comet comets[], int cSize, SpaceShip &ship)
{
for(int i = 0; i < bSize; i++)
{
if(bullet[i].live)
{
for(int j = 0; j (comets[j].x - comets[j].bound_x) &&
bullet[i].x (comets[i].y - comets[j].bound_y) &&
bullet[i].y < (comets[i].y + comets[j].bound_y))
{
bullet[i].live = false;
comets[j].live = false;
ship.score++;
}
}
}
}
}
}
Your second for loop is a mess. You need to go through the comet array one by one to check for live comet. Only then can do collision detection.
I have a problem to. The more i compile it, it more lagged. How can I fix this ?
So I was curious to see if you were still monitoring this site. I am fairly new to programming, but I get it done usually. I have to say VERY good tutorial, I have only been looking at the source code because my internet sucks, but all went well up to this point. I read in another post that they were having problems with the al_draw_textf so they decided to comment it out. Before I did this it would start up the window but not draw anything to it and it would tell me this “Unhandled exception at 0x5c18fba0 in SideShooter.exe: 0xC0000005: Access violation reading location 0x00000008.” So I tried commenting out those lines. When I compiled it and ran it, it would run for about 3 seconds then the Allegro screen would go black, if anyone has any suggestions they would be greatly appreciated, also if you would like me to e-mail the code just let me know
Is the font in the correct folder? The access violation is probably due to your font not loading correctly, which is only a problem when you attempt to use it. Check that. If you are still having problems, email me your code.
Hi awesome tutorials,this is helping a lot with my studies. My app was running fine until i got to this video and started adding font to the app! 🙁 i keep getting this error :
Debug Error!
Program: M:game_2dDebuggame_2d.exe
R6010
-abort() has been called
(press Retry to debug the application)
Have you got any suggestions?
Chances are that your font is in the wrong place.
Thanks for the quick reply, i will look into that and let you know, do you have any video tutorials about 3D gaming in c++?
turns out it was the font file, i just dragged and dropped in the solutions folder in the IDE, thinking that would work obviously not lol ;-D. its working now looking forward to the next tutorials.
thanks for you help 🙂
I am currently making videos on Unity for Unity Technologies. You can find them on YouTube.
Hi Mike,
I have got the source code of Animation. Thanks!. I read the part serveral times, I can see youbute video in China. The source code for this part can not be download either. Could you help me to send the source code to my email 2521137394@qq.com. Your article is excellent, and easy understand. It help me to pick allegro and game developing skill very quckly.
Regards & Thanks!