Exercise 13.1: Adding player velocity to the bullets

Open up the critterarmed.cpp file and find the cCritterArmedPlayer::shoot method. This shoot method is a compromise between adding in the player's velocity and not adding in the player's velocity; it only adds in velocity that's in the shooting direction. To see the effect of not adding in any velocity at all comment out the line #define PLAYERBULLETSPEEDUP at the start of the file. Run the program and look what happens in the Spacewar game if the player shoots while moving forward. Now, with the #define still switched off, check the effect of adding in the velocity by adding the line pbullet->addVelocity(_velocity) to the cCritterArmedPlayer::shoot method. (Be sure to type in this line outside the scope of the # ifdef .) Now look how the game behaves if you move the player around while shooting. Note that if you shoot perpendicular to the player's current motion, the bullets won't be aligned with the player, which is something most users find too confusing. And look what happens if you shoot in the reverse of the player's motion direction.

Exercise 13.2: Increasing the bullet velocity

Open up the gamestub.cpp file and edit the cCritterStubRivalBullet constructor to have the two lines setMaxSpeed(100.0) , setSpeed(100.0) . Then run the game and look how fast the enemy's bullets move.

Software Engineering and Computer Games
Software Engineering and Computer Games
Year: 2002
Pages: 272

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