You are previewing Professional XNA™ Programming: Building Games for Xbox 360™ and Windows® with XNA Game Studio 2.0, Second Edition.
O'Reilly logo
Professional XNA™ Programming: Building Games for Xbox 360™ and Windows® with XNA Game Studio 2.0, Second Edition

Book Description

This improved and updated edition of the bestseller will get you up and running quickly with building games for Xbox 360 and the Windows platform. Professional game developer and Microsoft MVP Benjamin Nitschke begins by explaining how to install the free XNA Game Studio 2.0 and then goes on to share essential advice for using it in a productive way.

Before you know it, each successive chapter will have you developing small games that increase in difficulty. By using the chapters as building blocks, you'll evolve from 2D programming to 3D, and you'll ultimately create a full-blown graphics engine that can be used for more advanced game projects. Plus, you'll get an inside look at six fully functional games, including the popular Racing Game and the new Dungeon Quest.

What you will learn from this book

  • Tips for adding music and sound with XACT

  • Techniques for creating unique visual effects through Shaders

  • Ways to access keyboard, mouse, and Xbox controllers with XInput

  • How to write your own XNA graphics engine and create a game engine

  • How to manage content in XNA

  • Myriad ways of fine-tuning, debugging, and troubleshooting

  • How to make sure games run on the Xbox 360

  • Ways to generate landscapes and tracks

  • How to take advantage of XNA's new networking APIs

Who this book is for

This book is for anyone who wants to create games on the Xbox 360 and Windows platforms. Experience with C# or a similar .NET language is necessary, but previous game programming is not required.

Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help pxsrogrammers do a better job

Examples link provided by the publisher.Errata link provided by the publisher.

Table of Contents

  1. Copyright
  2. About the Author
  3. About the Technical Editor
  4. Credits
  5. Acknowledgments
  6. Introduction
    1. Whom This Book Is For
    2. What This Book Covers and How It's Structured
    3. Source Code
    4. Errata
  7. I. XNA Framework Basics
    1. 1. Introducing XNA
      1. 1.1. Introduction to the XNA Framework
        1. 1.1.1. XNA Game Studio Express
        2. 1.1.2. Application Model
        3. 1.1.3. Content Pipeline
      2. 1.2. Get the Free XNA Game Studio Express
        1. 1.2.1. Requirements
        2. 1.2.2. Installing
        3. 1.2.3. What About Visual Studio 2005 Professional?
        4. 1.2.4. Configuring Your Xbox 360
      3. 1.3. Getting Started
        1. 1.3.1. Your First Project
        2. 1.3.2. F5 and Go
        3. 1.3.3. Changing the Code
      4. 1.4. Notes about XNA
        1. 1.4.1. Important Links
        2. 1.4.2. Is C# Good for Game Development?
        3. 1.4.3. Getting Used to the Content Pipeline
        4. 1.4.4. Differences with MDX
        5. 1.4.5. Additional Tools and Tips
        6. 1.4.6. Changes in XNA 2.0
      5. 1.5. Troubleshooting
      6. 1.6. Summary
    2. 2. Creating Your First Game: Pong
      1. 2.1. Game Ideas
        1. 2.1.1. Write Down Your Ideas!
          1. 2.1.1.1. Game Idea: Pong
          2. 2.1.1.2. Features and Game Play
          3. 2.1.1.3. Technology
        2. 2.1.2. Agile Methodology
        3. 2.1.3. Solving Initial Difficulties
        4. 2.1.4. Creating Some Textures
      2. 2.2. Let's Write Pong
        1. 2.2.1. Sprites
        2. 2.2.2. Unit Testing in Games
        3. 2.2.3. Adding the Ball and Paddles
        4. 2.2.4. Handling Player Input
        5. 2.2.5. Collision Testing
        6. 2.2.6. Adding Sound
      3. 2.3. How This Looks on the Xbox 360
      4. 2.4. Challenge: Improve the Pong Game
      5. 2.5. Troubleshooting
      6. 2.6. Summary
    3. 3. Helper Classes
      1. 3.1. Managing the Content Pipeline
        1. 3.1.1. Supported File Formats
        2. 3.1.2. Advantages and Disadvantages
        3. 3.1.3. Handling Content Directories
        4. 3.1.4. Importing and Accessing Content
      2. 3.2. Logging Error Messages
      3. 3.3. Unit Testing in XNA
        1. 3.3.1. NUnit and TestDriven.Net
        2. 3.3.2. Starting Unit Tests
        3. 3.3.3. Golden Rules
      4. 3.4. RandomHelper Class
        1. 3.4.1. Generate Random Vectors
      5. 3.5. StringHelper Class
        1. 3.5.1. Extracting Filenames
        2. 3.5.2. Writing Lists
      6. 3.6. Other Helpers
        1. 3.6.1. SpriteHelper Class
        2. 3.6.2. EnumHelper Class
        3. 3.6.3. ColorHelper Class
      7. 3.7. The Breakout Game
        1. 3.7.1. Unit Testing in Breakout
        2. 3.7.2. Breakout Levels
        3. 3.7.3. The Game Loop
        4. 3.7.4. Drawing Breakout
        5. 3.7.5. Collision Testing
      8. 3.8. Challenge: Improve the Breakout Game
      9. 3.9. Summary
    4. 4. Game Components
      1. 4.1. The Game Class
      2. 4.2. Game Components
      3. 4.3. More Helper Classes
        1. 4.3.1. TextureFont Class
        2. 4.3.2. Input Class
        3. 4.3.3. Sound Class
      4. 4.4. Tetris, Tetris, Tetris!
        1. 4.4.1. Rendering the Background
        2. 4.4.2. Handling the Grid
        3. 4.4.3. Block Types
        4. 4.4.4. Gravity
        5. 4.4.5. Handling Input
        6. 4.4.6. Testing
      5. 4.5. Challenge: Create the NextBlock Game Component
      6. 4.6. Summary
  8. II. Basic Graphics Engine
    1. 5. Writing Your Own XNA Graphics Engine
      1. 5.1. What Should Your Engine Be Able to Do?
        1. 5.1.1. The Engine Unit Test
        2. 5.1.2. 3D Models
        3. 5.1.3. Rendering of Textures
        4. 5.1.4. Line Rendering
      2. 5.2. 3D Programming
        1. 5.2.1. Model Unit Test
        2. 5.2.2. Testing Other Models
      3. 5.3. Plugging in More Game Components
        1. 5.3.1. Simple Camera Class
        2. 5.3.2. ScreenshotCapturer Class
      4. 5.4. Making Sure Games Run on the Xbox 360
        1. 5.4.1. Downloading the XNA Game Launcher
        2. 5.4.2. Xbox 360 Setup and Deploying Games
        3. 5.4.3. Console Debugging and Tools
      5. 5.5. Challenge: Write a Game Component
      6. 5.6. Summary
    2. 6. Shader Management
      1. 6.1. Shader Overview
        1. 6.1.1. History
        2. 6.1.2. Shaders Everywhere in XNA
        3. 6.1.3. Example Games
      2. 6.2. Step-by-Step Shader Tutorial
        1. 6.2.1. FX Composer
        2. 6.2.2. FX File Layout
        3. 6.2.3. Parameters
        4. 6.2.4. Vertex Input Format
        5. 6.2.5. Vertex Shader
        6. 6.2.6. Pixel Shader
      3. 6.3. Importing the Shader into Your Engine
        1. 6.3.1. Compiling Shaders
        2. 6.3.2. Using Parameters
        3. 6.3.3. Vertex Formats
        4. 6.3.4. Rendering with Shaders
        5. 6.3.5. Testing the Shader
      4. 6.4. Challenge
      5. 6.5. Summary
    3. 7. Realism Through Normal Mapping
      1. 7.1. Adding Detail to Objects
        1. 7.1.1. Problems
        2. 7.1.2. Asteroids! Wrong Game or What?
      2. 7.2. So How Do Shaders Work?
        1. 7.2.1. Vertex Shaders and Matrices
        2. 7.2.2. Pixel Shader and Optimizations
      3. 7.3. ShaderEffect Class
        1. 7.3.1. TangentVertex Format
        2. 7.3.2. Normal Mapping Unit Test
        3. 7.3.3. Adding Tangent Data with a Custom Processor
        4. 7.3.4. Final Asteroid Unit Test
      4. 7.4. More Shaders
        1. 7.4.1. Offset Mapping
        2. 7.4.2. Glass Shader
        3. 7.4.3. Reflection and Water
      5. 7.5. Challenge: Add Parallax Mapping
      6. 7.6. Summary
    4. 8. Post-Screen Shaders and the Rocket Commander Game
      1. 8.1. Handling Post-Screen Shaders
        1. 8.1.1. Pre-Screen Sky Cube Mapping
        2. 8.1.2. Writing a Simple Post-Screen Shader
        3. 8.1.3. Improvements
      2. 8.2. Implementing Post-Screen Shaders
        1. 8.2.1. RenderToTexture Class
        2. 8.2.2. PostScreenDarkenBorder Class
        3. 8.2.3. Unit Test Result
      3. 8.3. More Post-Screen Shaders
        1. 8.3.1. Motion Blur
        2. 8.3.2. Color Correction
        3. 8.3.3. Menu Effects
      4. 8.4. Rocket Commander Game
        1. 8.4.1. Performance in XNA
        2. 8.4.2. Moving from MDX to XNA
        3. 8.4.3. Using Threads to Improve Performance
        4. 8.4.4. Result and Screenshots
      5. 8.5. Challenge: Write an Edge Detection Shader
      6. 8.6. Summary
  9. III. Improving Your Game Engine
    1. 9. Adding Sound with XACT
      1. 9.1. No DirectSound
        1. 9.1.1. Handling .wav Files
      2. 9.2. Using XACT
        1. 9.2.1. Creating Projects
        2. 9.2.2. Creating Your Wave Bank
        3. 9.2.3. Compressing Music Data
        4. 9.2.4. Sound Banks
        5. 9.2.5. Cue Variables
        6. 9.2.6. Other Effects
        7. 9.2.7. Changes in XNA 2.0
      3. 9.3. Sound Class
        1. 9.3.1. Rocket Motor Sound
        2. 9.3.2. Whoosh, What Was That?
        3. 9.3.3. Menu Sounds
      4. 9.4. Challenge: Create Your XACT Project
      5. 9.5. Summary
    2. 10. Player Input and the User Interface
      1. 10.1. Input Class
        1. 10.1.1. The Update Method in the Input Class
        2. 10.1.2. Mouse Rectangles
        3. 10.1.3. Entering Text in XNA
      2. 10.2. Game Screens
        1. 10.2.1. Help Screen
        2. 10.2.2. In-Game User Interface
        3. 10.2.3. Tips
      3. 10.3. Cameras
      4. 10.4. Space Camera
      5. 10.5. Challenge: Write a Free Camera Class
      6. 10.6. Summary
    3. 11. Creating XNA Shooter
      1. 11.1. Putting It All Together
        1. 11.1.1. Sounds
        2. 11.1.2. User Interface
        3. 11.1.3. Textures
        4. 11.1.4. 3D Models
        5. 11.1.5. Animated Textures
        6. 11.1.6. Billboards
      2. 11.2. Landscape Rendering
        1. 11.2.1. Base Texture and Normal Map
        2. 11.2.2. Height Map
        3. 11.2.3. Adding Objects
      3. 11.3. XNA Shooter Game
        1. 11.3.1. Game Logic
        2. 11.3.2. 3D Effects
        3. 11.3.3. Unit Class
        4. 11.3.4. Projectile Class
        5. 11.3.5. Item Class
        6. 11.3.6. Final Screenshot
      4. 11.4. Challenge: Write a Game with Your Engine
      5. 11.5. Summary
  10. IV. Writing a Racing Game
    1. 12. Generating Landscapes and Tracks
      1. 12.1. Game Comparisons
        1. 12.1.1. Gran Tourismo
        2. 12.1.2. Need for Speed
        3. 12.1.3. Trackmania
        4. 12.1.4. XNA Racing Game
      2. 12.2. Landscape Rendering
        1. 12.2.1. Textures
        2. 12.2.2. Rendering
        3. 12.2.3. Optimizing Tips
      3. 12.3. Tracks
        1. 12.3.1. Unit Testing to the Rescue
        2. 12.3.2. Interpolating Splines
        3. 12.3.3. More Complex Tracks
        4. 12.3.4. Importing the Track Data
        5. 12.3.5. Generating Vertices from the Track Data
        6. 12.3.6. Final Result
      4. 12.4. Challenge: Create a New Unit Test Track
      5. 12.5. Summary
    2. 13. Physics
      1. 13.1. Newton's Laws of Motion
        1. 13.1.1. Keep It Simple
        2. 13.1.2. Gravitation
      2. 13.2. Physics Engines
        1. 13.2.1. Ageia PhysX
        2. 13.2.2. Havok
        3. 13.2.3. ODE
        4. 13.2.4. Other
      3. 13.3. Implementing Physics
        1. 13.3.1. Handling Loopings
        2. 13.3.2. Spring Physics
        3. 13.3.3. Collision Detection
        4. 13.3.4. PhysicsAsteroidManager
        5. 13.3.5. Car Collision
      4. 13.4. Challenge: Figure Out the Road Collision
      5. 13.5. Summary
    3. 14. Fine-Tuning and "Modding" the Racing Game
      1. 14.1. Game Concept
        1. 14.1.1. Game Idea
        2. 14.1.2. Additional Features
      2. 14.2. Game Screens
        1. 14.2.1. Splash Screen
        2. 14.2.2. Main Menu
        3. 14.2.3. Game Screen
        4. 14.2.4. Highscores
      3. 14.3. Final Unit Testing and Tweaking
        1. 14.3.1. Tweaking the Track
        2. 14.3.2. Shadow Mapping
        3. 14.3.3. Final Testing on Windows
        4. 14.3.4. Final Testing on the Xbox 360
      4. 14.4. Additional Ideas
        1. 14.4.1. More Cars
        2. 14.4.2. Online Highscore List
        3. 14.4.3. More Shaders and Effects
        4. 14.4.4. More Game Modes
        5. 14.4.5. Multiplayer Mode
      5. 14.5. Challenge: Write Your Own Mod!
        1. 14.5.1. Example Game: Speedy Racer
          1. 14.5.1.1. Step 1: Changing the Car Model
          2. 14.5.1.2. Step 2: Menu Changes
          3. 14.5.1.3. Step 3: New Landscape and Objects
          4. 14.5.1.4. Step 4: Driving Faster
          5. 14.5.1.5. Step 5: Adding Items and New Sounds
      6. 14.6. Summary
  11. V. Writing Multiplayer Games
    1. 15. Multiplayer and Xbox Live
      1. 15.1. What's New in XNA 2.0
        1. 15.1.1. Overview About Networking in XNA 2.0
        2. 15.1.2. TCP Versus UDP
        3. 15.1.3. Firewalls and Punching Through NATs
      2. 15.2. Network Architecture
        1. 15.2.1. Sending UDP Data
        2. 15.2.2. Connecting Two Players
        3. 15.2.3. Network Messages
        4. 15.2.4. Server Game List
      3. 15.3. Writing a Chat Application
        1. 15.3.1. Game Screens
        2. 15.3.2. Handling Chat Messages
        3. 15.3.3. The Final Chat Application
      4. 15.4. Challenge: Write a Multiplayer Application
      5. 15.5. Summary
    2. 16. Role-Playing Games
      1. 16.1. Types of Role-Playing Games
        1. 16.1.1. "Hack and Slash" Role-Playing Games
        2. 16.1.2. Massively Multiplayer Role-Playing Games
      2. 16.2. Designing Dungeon Quest
      3. 16.3. Ideas
      4. 16.4. Scenario
      5. 16.5. Story
      6. 16.6. Characters
      7. 16.7. Enemies
      8. 16.8. Weapons and Items
      9. 16.9. Abilities and Spells
        1. 16.9.1. Abilities
        2. 16.9.2. Spells
          1. 16.9.2.1. Barbarian Spells
          2. 16.9.2.2. Priest Spells
          3. 16.9.2.3. Mage Spells
          4. 16.9.2.4. Hunter Spells
        3. 16.9.3. Leveling System
      10. 16.10. Challenge: Improve the Leveling System
      11. 16.11. Summary
    3. 17. Dungeon Quest
      1. 17.1. Creating the Engine
        1. 17.1.1. Changes to the Graphic Engine
        2. 17.1.2. Using Collada Model Files
        3. 17.1.3. Handling Many Point Lights
        4. 17.1.4. Adding AI
        5. 17.1.5. Path-Finding
        6. 17.1.6. Alert-System via Cries
      2. 17.2. Multiplayer Support
        1. 17.2.1. Network Messages
        2. 17.2.2. Xbox LIVE Support
      3. 17.3. The Dungeon Quest Editor
      4. 17.4. Summary
  12. A. Resources
    1. A.1. Links
    2. A.2. Code Download Structure
    3. A.3. Books
      1. A.3.1. Graphics and Shader Technologies
      2. A.3.2. AI Programming
      3. A.3.3. General Development and Programming
      4. A.3.4. Another Useful Title
    4. A.4. Tips and Golden Rules
      1. A.4.1. Tips
      2. A.4.2. Golden Rules
    5. A.5. Class Overviews