I am currently working on a 2d asteroid game with SDL and I have run into a problem I can't fix. The player controls a ship and shoots lasers. I have a class for the asteroids which move at random speeds and angles, and I have a class for the ship which contains the functions for the lasers and the ship.
I want 6 asteroids on the screen at any given time, and at the moment, when I try to check the collision between the lasers and the asteroids, the lasers will only hit one of the asteroid class objects at a time. There are 3 lasers that can be on the screen at any given time too. When I remove all the instances of the asteroids except for 1, the program appears to run perfectly, when I add more asteroids, only 1 asteroid object is able to collide with the lasers.
here is how I am trying to have the collision work at the moment:
Thanks, I'll remember to use < from now on. The code I provided earlier is supposed to be the collision checker between 3 lasers and 6 asteroids. If the checker returns true, it causes another function to draw the explosion etc... I've gone through line by line with my debugger and it checks to see if each laser hits each asteroid, yet the program still seems ignore the other asteroids. It seems like the checking code is somehow being skipped over, and that it moves on to other functions before running the test for the other asteroids. I would put a call to the collision checker right after each laser is fired, but I don't know how to use certain instances of class objects declared in main() as arguments to a class function.
I think I may have to go back to learning from books to get a better understanding of how the language works before I can continue.
It is pretty much done. For the time being I am going to go back and start learning better c++ fundamentals before I start working on games again though.