Hi
I am a noob and learning C++ and DGDK. I am trying to figure out how to use pointers and dynamic memory things.
I was wondering if this is possible, or how I should go about it:
Say I have a class for making a monster (in this case a sphere for example sake) in a game:
class CMonster {
public:
int object;
CMonster (float xpos, float zpos)
{
object = GetFreeObject(500); // a fuction I use to get a free object slot
dbMakeObjectSphere(object,40);
dbPositionObject (object,xpos,0,zpos);
}
void run()
{
dbMoveObject(object,5);}
}
};
now to make a monster I can say : CMonster monster(100,100);
and to run its moving code : monster.run();
I know I can have an array without the constructer:
CMonster monster[50];
monster.setup(100,100);
and then use: monster[1].run()
Here is my question: If I use the array, I am limited to how many "monsters" I can make in my program. What I want to know is: is it possible to use dynamic memory stuff to make new "monsters" and run them whenever I need to (e.g. a RTS game)? something like:
new CMonster (100,100);
and then also to use the monster.run() command.
Is this possible or am I missing the plot and being silly? And how would you point to the new "monsters"? Is there a simpler way I am not seeing?
Thanks