14.3 The Worms game


The Worms game isn't so much a game as it is a wacky-world testing ground for a bunch of tricks.

The most obvious new wrinkle is that, we have 'worms' that are made up by linking together cCritterWormSegment objects with cForceObjectSpringRod forces.

Another visually striking feature is that we're using a cSpriteLoop for the player's sprite; this means that the sprite changes appearance every third of a second. If you comment out the line #define PLAYERSPRITELOOP at the start of the gameworms.cpp file and recompile, the player sprite will now use a cSpriteDirectional that changes its color to match the direction it's pointing in.

The Worms code does some other things. The cCritterWormsRivalBullet objects run away from the player, and they don't view any critters as targets, so they never damage anyone . In fact we want them to act as health- packs , so we change the cCritterWormsPlayer::collide to get health from eating them.

In order to have the player control the collision with the rival bullets, we need to lower the _collidepriority of the rival bullets, so we add this line to the cCritterWormsRivalBullet constructor: _collidepriority = cCollider::CP_CRITTER; .

The Worms game

graphics/14icon02.gif

We play another trick with collidepriority here as well. We want the cCritterWormsRival objects to be reduced in size and possibly killed (when they get too small) by bumping into the cCritterWormSegment objects. So to let the cCritterWormSegment control the collisions, we give them a _collidepriority of cCollider::CP_CRITTER + 1 , which is higher than the priority of the worm segments and the rival bullets, but lower than the priority of the player or the player's bullets.

In the Worms game we also manipulate the size of the cCritterWormsRival objects. The cCritterWormsRival critters grow when hit by the player's bullets, until they reach a certain size and sustain the standard base-class damage (which in fact kills them since their _health is only 1).

 int cCritterWormsRival::damage(int hitstrength)  {      setRadius(radius()*1.3);//Let's swell when hit by a bullet.      if(radius() > 2.0) //Pop when you get too big!      {          playSound("Pop");          return cCritter::damage(hitstrength); //Default behavior.      }      else          return 0;  } 

As yet another variation, in the Worms game, the cCritterWormSegment::damage method reduces the number of sides the polygonal sprite has until it runs out of sides and dies.



Software Engineering and Computer Games
Software Engineering and Computer Games
ISBN: B00406LVDU
EAN: N/A
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net