Chapter 15: Wrapping Up Your 3D Game

Exercise Answer

  1. 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 enum to 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 FireShots method of the Game1 class, 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 ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.