Chapter 15: Wrapping Up Your 3D Game
Exercise Answer
Create a multishot power-up which, when active, will fire four shots instead of one. Instead of shooting one shot in the center of the camera, when multishot is active shoot one shot from above and right of the camera, one from above and left, one from below and right and one from below and left.
When the player shoots three ships in a row, the game will randomly choose which power-up to activate (rapid fire, or multishot).
You've got all the code fleshed out to create a power-up. You'll now need to take that code and add a new multishot power-up. Start with adding a new value to the
PowerUps enumto represent multishot mode.Once that's done, there are really only two other steps: add code when a power-up is triggered that randomly picks the multishot or rapid fire mode; and add the code to fire multiple shots in multishot mode.
The difficult part will be in the
FireShotsmethod of theGame1class, where you'll need to add the code for multiple shots. Here is one possible solution for that part of the problem:protected void FireShots(GameTime gameTime) { if (shotCountdown <= 0) { // Did player press space bar or left mouse button? if (Keyboard.GetState().IsKeyDown(Keys.Space) || Mouse.GetState().LeftButton == ButtonState.Pressed) { if (currentPowerUp != PowerUps.MULTI_SHOT) { //Normal mode - fire one shot // Add a shot to the model manager modelManager.AddShot( camera.cameraPosition + new Vector3(0, −5, 0), camera.GetCameraDirection ...