Jump to content
  • Advertisement
Sign in to follow this  
ErUs

asteroids! shots, arrays, entity system :o

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a clone of asteroids without the asteroids and the bullets atm. i am wondering what the best was to update everything in the game was? i was thinking aout having an aray of CEntitys and then when someone shoots i have my CShot class that derives from CEntity sort of thing? what do you think?

Share this post


Link to post
Share on other sites
Advertisement
Sounds good to me. Then every frame you would only have to loop through the entity list and let each one render and update themselves.

Share this post


Link to post
Share on other sites
I've also been working on an asteroids clone for a while now and instead of using a vector to manage the memory, I used a std::list. This is because you'll be deleting elements from the unordered memory and don't really need random access. Deleting elements from the middle of a vector is a very slow process.

So, I came up with something like this:

#include <list>

std::list<CEntity*> entityList;

// Helper functions to manage all entities
void UpdateEntities();
void DrawEntities();
void AddAsteroid(int x, int y, ... );
void AddBullet(int x, int y, ... );
//...


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Great site for you:

http://www.bringyou.to/games/

David

Share this post


Link to post
Share on other sites
Trick for quickly deleting an element in the middle of a vector:

*iterator = vector.back();
vector.pop_back();


This works assuming the order of elements doesn't matter. I'm pretty sure it doesn't in this case.

This pretty much becomes: *pointer = *--vector.data_end; It would also normally invoke the destructor, but pointers don't have one. It's so cheap, it's practically free.

Share this post


Link to post
Share on other sites
Quote:
Original post by smart_idiot
Trick for quickly deleting an element in the middle of a vector:

*iterator = vector.back();
vector.pop_back();


This works assuming the order of elements doesn't matter. I'm pretty sure it doesn't in this case.

This pretty much becomes: *pointer = *(--vector.data_end-1); It would also normally invoke the destructor, but pointers don't have one. It's so cheap, it's practically free.

I'm not completely clear on how this deletes something from the middle of the vector.

*edit: stupid upgrade eats tags.

*edit2: Never mind, figured it out. Presumably, iterator already points to the element to be deleted?

CM

Share this post


Link to post
Share on other sites
Quote:
Original post by Conner McCloud
Presumably, iterator already points to the element to be deleted?


That's the assumption. Also, you've quoted my bug where I goofed up combining the two lines. Teh noes!

Share this post


Link to post
Share on other sites
how do i set a custom size for my vector or list
like i only want 100 shots

then i have an int shotnumber and every time i want to create a new shot i so ShotsVector[shotnumber].Init( x, y, angle); shotnumber++; if shots over 100 shots = 1;

(EDIT) sorry i did not see all those other posts hadnt refreshed page in ages

oh and david, http://www.bringyou.to/games/ that asteroid game uses an array of structs and i tried that before but with classes and it didnt work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!