Page 1 of 1

My version of classic Asteroids game

Posted: May 17th, 2019, 9:25 am
by Christian
Dears,

I am new to this Forum.
Thanks a lot to Chilli for his great C++ programming tutorial series. I have been following it for almost a year now (currently mid of intermediate) and learned so much.

As a practicing project I made a version of "Asteroids", which I played a lot as a kid on my Atari.
It's pretty much complete now, only sound is missing.
Please check it out and tell me what you think!

Move the rocket with arrow keys (left and right rotate, up starts engine). To slow down rocket you must apply reverse thrust. Space to fire. Collect power ups if you can.

The game needs quite some ressources (especially in higher levels with many asteroids). Best run in release mode.

https://github.com/ChristianOhm/Asteroids

Best
Christian

Re: My version of classic Asteroids game

Posted: May 17th, 2019, 6:57 pm
by albinopapa
Crashed when about to show scores.

Code: Select all

	std::vector<Entry> entries;
	std::vector<Entry>::iterator newEntry = entries.end();
This is never a good idea because the end will move as the vector grows and shrinks and iterators are based on the address of the element after the last in a vector. So, the end ( newEntry ) is not going to be the same in the beginning of the program as opposed to the point where the scores are shown.

Anyway, the error was that the iterators are not compatible, and I'm thinking this is the reason why.

Oh, also when the vector grows, all previous iterators are invalidated so storing an iterator in general is never a good idea.

Re: My version of classic Asteroids game

Posted: May 17th, 2019, 7:26 pm
by Christian
Strange, why does it work on my computer but not on yours? This makes bugfixing complicated...

newEntry is used to store the player's name while it is typed in. It defaults to entries.end() but is set to new value once new Highscore achieved.

Will look into this tomorrow…

Thanks
Christian

Re: My version of classic Asteroids game

Posted: May 17th, 2019, 8:17 pm
by Christian
Ok, I fixed it.
The error only occured in debug mode, not in release.
Problem was when displaying highscores with no new entry.

Please try again. ;-)

Re: My version of classic Asteroids game

Posted: May 17th, 2019, 9:47 pm
by albinopapa
Yeah, I should have given that information and I kind of figured the debug vs release was going to be what confused the issue. Debug has checks for bounds and such whereas Release does not.