asteroids! shots, arrays, entity system :o

Started by
9 comments, last by GameDev.net 18 years, 12 months ago
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?
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )
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.
____________________________________________________________Programmers Resource Central
any example code how to make an array of a class ?
i tried and failed
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )
You could have a std::vector of the base class pointers.
#include <vector>...std::vector<*CEntity> entityList;


Look here for vector methods.
____________________________________________________________Programmers Resource Central
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 entitiesvoid UpdateEntities();void DrawEntities();void AddAsteroid(int x, int y, ... );void AddBullet(int x, int y, ... );//...
Rob Loach [Website] [Projects] [Contact]
Great site for you:

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

David
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.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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
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!
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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.
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )

This topic is closed to new replies.

Advertisement