Creating and Tracking Enemies
I want to have a base class called cEnemy lets say and a bunch of child classes for different types of enemies. Now I want to make a vector to keep track of all enemies such as for collision testing. Can I make a universal vector of cEnemy or something, I dont want to have to create a seperater vector for each type of enemy. Hope this makes sense. Also if theres a more standard way of doing this Im open to suggestions, thanks.
Jawbreaker
Aye, theoretically you should be able to create a vector for the base class and store any cEnemies you want in there... (am I right on this? I think so) Since any descendants of cEnemy are also a cEnemy itself.
EDIT: Aye, that's a good idea, the pointer idea =)
[edited by - Vthornheart on March 20, 2004 4:11:18 PM]
EDIT: Aye, that's a good idea, the pointer idea =)
[edited by - Vthornheart on March 20, 2004 4:11:18 PM]
quote:Original post by VThornheart
Aye, theoretically you should be able to create a vector for the base class and store any cEnemies you want in there... (am I right on this? I think so) Since any descendants of cEnemy are also a cEnemy itself.
Bad, bad idea. Creating a container that stores a base object by value will lead to slicing.
So basically what you want to do is something like
std::vector< cEnemy* > m_vecEnemies;
You want to store pointers to your base object. Say you have a cRat that inherits from cEnemy. You could add a rat to your list of enemis by doing this:
cRat* pNewRat = new cRat();
// init member variables for your new "rat"
m_vecEnemies.push_back( pNewRat );
Hope this helps,
neneboricua
[edited by - neneboricua19 on March 20, 2004 4:54:23 PM]
std::vector< cEnemy* > m_vecEnemies;
You want to store pointers to your base object. Say you have a cRat that inherits from cEnemy. You could add a rat to your list of enemis by doing this:
cRat* pNewRat = new cRat();
// init member variables for your new "rat"
m_vecEnemies.push_back( pNewRat );
Hope this helps,
neneboricua
[edited by - neneboricua19 on March 20, 2004 4:54:23 PM]
Posts like this would be better off in the Game Programming forum. This has nothing to do with DirectX.
Stay Casual,
Ken
Drunken Hyena
Stay Casual,
Ken
Drunken Hyena
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement