Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page