My version of classic Asteroids game

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Christian
Posts: 3
Joined: February 20th, 2019, 8:30 pm

My version of classic Asteroids game

Post by Christian » May 17th, 2019, 9:25 am

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
Attachments
Asteroids.zip
(1.4 MiB) Downloaded 147 times
Last edited by Christian on May 17th, 2019, 8:22 pm, edited 2 times in total.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: My version of classic Asteroids game

Post by albinopapa » May 17th, 2019, 6:57 pm

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Christian
Posts: 3
Joined: February 20th, 2019, 8:30 pm

Re: My version of classic Asteroids game

Post by Christian » May 17th, 2019, 7:26 pm

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

Christian
Posts: 3
Joined: February 20th, 2019, 8:30 pm

Re: My version of classic Asteroids game

Post by Christian » May 17th, 2019, 8:17 pm

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. ;-)

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: My version of classic Asteroids game

Post by albinopapa » May 17th, 2019, 9:47 pm

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply