...

View Full Version : Please Help. Re: Array of objects



Stowelly
04-29-2004, 06:57 PM
ok basically this function creates each object within a loop and passes it a pointer to the next object




void cGameWorms::seedCritters()
{

pbiota()->purgeNonPlayerNonWallCritters();
/* Clean out any old non-player non-wall critters. Although we don't have
walls yet, you might want to put some in. */
/* Make some new cCritterWormsRival and some new cCritterWormSegment.*/
for (int i=0; i<_rivalcount; i++)
new cCritterWormsRival(this);
cCritterWormSegment *pwormseg;
cCritterWormSegment *pwormseg_previous; /* This is a special trick for the
follow-the-leader thing we'll set up in the next loop. Not standard. */

for (int k=0; k<cGameWorms::WORMCOUNT; k++)
{
pwormseg_previous = NULL;
for (i=0; i<_seedcount; i++)
{

pwormseg = new cCritterWormSegment(this, pwormseg_previous);
pwormseg_previous = pwormseg;


}
}
}







this function is whats called when creating the object it recieves the pointer to the next object and uses this as the deciding factor on what to do next.

what i need it to do is be able to select any object to decide what to do. if that makes any sense



cCritterWormSegment::cCritterWormSegment(cGame *pownergame, cCritter *ppriorsegment):
cCritter(pownergame)
{
//Set the health and value. Make a sprite and use setSprite to install it.
//randomize(cCritter::MF_POSITION | cCritter::MF_VELOCITY);
cPolygon *pnewpoly = new cPolygon(7);
pnewpoly->randomize( cPolygon::MF_COLOR);
setSprite(pnewpoly);
//Use addForce to add forces.
//Randomize velocity if you like.
//Set a particular radius ifyou like.
setRadius(0.5);
if (!ppriorsegment)
randomize(cCritter::MF_POSITION | cCritter::MF_VELOCITY);
else
{
// ppriorsegment->
Real rodlength = radius()+ppriorsegment->radius();
addForce(new cForceObjectSpringRod(
ppriorsegment, rodlength, cGameWorms::SPRINGFORCE));
addForce(new cForceObjectSeek(ppriorsegment, cGameWorms::SPRINGFORCE));
moveTo(ppriorsegment->position()- rodlength * ppriorsegment->tangent());
setVelocity(ppriorsegment->velocity());

}



}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum