You are previewing Microsoft XNA Unleashed: Graphics and Game Programming for Xbox 360 and Windows.
O'Reilly logo
Microsoft XNA Unleashed: Graphics and Game Programming for Xbox 360 and Windows

Book Description

Foreword by Tom Miller

Developer, XNA Game Studio Express, Microsoft Corporation

Microsoft XNA Unleashed provides comprehensive coverage and solid instruction on how to leverage the XNA Framework to create high quality games for Windows and the Xbox 360. The author shows you how to take full advantage of the many features the XNA Framework provides; you will learn the intricacies of important tasks such as adding sound and music to games, as well as creating, loading, and texturing 3D objects. In addition to providing coverage of 2D programming, the author shows you how to create sophisticated 3D games. All the important topics such as physics, artificial intelligence, and special effects are covered in detail. Chad Carter is the CTO at Robertson Marketing Group. Many Fortune 500 companies use the ecommerce system he architected and developed from the ground up for the promotional business sector. He has been creating DirectX applications since 1996 and has developed games using Managed DirectX. Chad created a 3D locomotive simulator for Norfolk Southern that is used to teach children to obey railroad crossings signals. Chad’s website devoted to the XNA Framework can be found at www.xnaessentials.com.

  Learn how to install and use XNA Game Studio Express

  Discover how to build, deploy, and debug games for the Xbox 360 and Windows

  Examine the XNA Framework in depth: 2D, 3D, sound, input, and HLSL

  Learn how to create game components and game services

  Delve into performance tuning techniques

  Discover how to extend the Content Pipeline

  Learn how to use the Microsoft Cross-Platform Audio Creation Tool (XACT) to add sound and music to games

  Create a full 2D parallax side-scroller game

  Discover how to use sprite batches

  Learn to make the most of sprite fonts

  Create 2D components such as splash screens and progress bars

  Examine the different sprite batch blending modes

  Discover 2D cel animation

  Examine the High Level Shader Language (HLSL) in detail covering basic HLSL as well as vertex deformations and post-processing effects

  Create a full 3D game that includes a 2D radar in the Heads Up Display (HUD), and much, much more

CD-ROM includes

• All C# examples and source code presented in this book.

• Explosion Generator tool for generating explosion animations.

Introduction                 

Part I      Get Up and Running with XNA on Your PC and Xbox 360

1              Introducing XNA and XNA Game Studio Express                       

2              XNA and the Xbox 360              

3              Performance Considerations    

Part II     Understanding XNA Basics

4              Creating 3D Objects                      

5              Input Devices and Cameras     

Part III    Content Pipeline

6              Loading and Texturing 3D Objects             

7              Sound and Music     

8              Extending the Content Pipeline                  

Part IV   2D in XNA

9              2D Basics                       

10           2D Effects                     

11           Creating a 2D Game               

Part V    High Level Shader Language

12           HLSL Basics          

13           Advanced HLSL    

Part VI   Physics and Artificial Intelligence

14           Physics Basics 

15           Finite State Machines and Game State Management  

16           AI Algorithms 

Part VII  3D Effects

17           Advanced Texturing Techniques

18           Special Effects 

19           Particle System

Part VIII Putting It Into Practice

20           Creating a 3D Game 

21           Improving the Game

22           Finishing Touches

Index

Table of Contents

  1. Copyright
    1. Dedication
  2. Foreword
  3. About the Author
  4. Acknowledgments
  5. We Want to Hear From You!
  6. Introduction
    1. Who Should Read This Book?
    2. Hardware and Software Requirements
      1. Supported Operating Systems
      2. Hardware Requirements
      3. Software Requirements
    3. Code Examples
  7. I. Get Up and Running with XNA on Your PC and Xbox 360
    1. 1. Introducing the XNA Framework and XNA Game Studio Express
      1. What Is the XNA Framework?
        1. The Foundation of the XNA Framework
        2. XNA Today
      2. Installing Visual C# Express
      3. Installing the DirectX Runtime
      4. Installing XNA Game Studio Express
      5. Creating Spacewar Windows Project
      6. Compiling and Running Spacewar
      7. Summary
    2. 2. XNA and the Xbox 360
      1. Creating Spacewar Xbox 360 Project
      2. Buying the XNA Creators Club Subscription
      3. Connecting the Xbox 360 to the PC
      4. Deploying on the Xbox 360
      5. Debugging on the Xbox 360
      6. Creating a Test Demo for the Xbox 360
      7. Programming for Dual Platforms
      8. The .NET Compact Framework on the Xbox 360
      9. Summary
    3. 3. Performance Considerations
      1. Measure, Measure, Measure
        1. The 80–20 Rule
        2. Creating a Benchmark
        3. Monitoring Performance on the Xbox 360
      2. Managing Memory
      3. Understanding the Garbage Collector
        1. On the .NET Framework (Windows)
        2. On the .NET Compact Framework (Xbox 360)
      4. Optimization Suggestions
        1. Creating a Micro-Benchmark Framework
        2. Sealing Virtual Methods
        3. Collections
      5. Summary
  8. II. Understanding XNA Basics
    1. 4. Creating 3D Objects
      1. Vertices
      2. Vectors
      3. Matrices
      4. Transformations
        1. Translation
        2. Scaling
        3. Rotation
      5. Transformations Reloaded
      6. Creating a Camera
        1. Projection
        2. View
        3. World
      7. Vertex Buffers
      8. Effects
      9. Textures
      10. Index Buffers
      11. XNA Game Components
      12. Checking Performance
        1. DrawUserIndexedPrimitives vs. DrawIndexedPrimitives
      13. Transformations Revolutions
      14. Summary
    2. 5. Input Devices and Cameras
      1. Creating a Game Service
      2. Starting a Library
      3. Working with Input Devices
        1. Keyboard
        2. Game Pad
        3. Mouse (Windows Only)
      4. Creating a Stationary Camera
      5. Creating a First Person Camera
      6. Creating a Split Screen
      7. Summary
  9. III. Content Pipeline
    1. 6. Loading and Texturing 3D Objects
      1. Understanding the Content Pipeline
      2. Loading 3D Models
      3. Texturing 3D Models
      4. Summary
    2. 7. Sounds and Music
      1. Microsoft Cross-Platform Audio Creation Tool (XACT)
      2. Wave Banks
      3. Sound Banks
      4. Understanding Variations
      5. Updating Our Input Handler
      6. Plugging in Our Sound Manager
      7. Creating a Sound Demo
      8. Summary
    3. 8. Extending the Content Pipeline
      1. Creating a Skybox
        1. Creating the Skybox Content Object
        2. Creating the Skybox Processor
        3. Creating the Skybox Compiler
        4. Creating the Skybox Reader
      2. Using the Skybox
      3. Debugging the Content Pipeline Extension
      4. Summary
  10. IV. 2D in XNA
    1. 9. 2D Basics
      1. Sprite Batches
        1. Sprite Blend Modes
        2. Sprite Sort Modes
        3. Save State Modes
      2. Practical Sprite Batches
        1. Splash or Loading Screen Demo
        2. Drawing Multiple Sprites from One Texture Demo
        3. Sprite Batch Blend and Sort Mode Demo
        4. Progress Bar Demo
      3. Using Sprite Fonts
        1. Importing TrueType Fonts
        2. Creating Bitmap Fonts
        3. Drawing 2D Text
      4. Summary
    2. 10. 2D Effects
      1. Cel Animation
      2. Rotating and Scaling
      3. Blending Mode Example
      4. Fade to Color
      5. Making Fire Old School Style
      6. Explosions
      7. Summary
    3. 11. Creating a 2D Game
      1. Setting Up the Game Skeleton
      2. Creating Parallax Scrolling
      3. Switching States
      4. Drawing Our Hero
      5. Drawing Our Enemies
      6. Handling Collision Detection
      7. Winning and Losing
      8. Adding Transitions
      9. Adding Explosions
      10. Adding Sounds
      11. Summary
  11. V. High Level Shader Language
    1. 12. HLSL Basics
      1. Understanding the Shader Process
      2. HLSL Syntax
        1. Variable Types
        2. Semantics
        3. Structs
        4. Intrinsic Functions
        5. Loops and Conditions
      3. Vertex Shaders
      4. Pixel Shaders
      5. Techniques
      6. Passes
      7. Passing Application Data to the GPU
      8. HLSL Demo
      9. Summary
    2. 13. Advanced HLSL
      1. Vertex Displacement
      2. Postprocessing
        1. Setting Up Our Game Code
        2. Setting Up Our Effect Code
      3. More Postprocessing Examples
        1. Negative Image
        2. Switching RGB Values
        3. Sharpening the Image
        4. Blurring an Image
        5. Embossed
        6. Grayscale
        7. Chalk
        8. Wavy
      4. Summary
  12. VI. Physics and Artificial Intelligence
    1. 14. Physics Basics
      1. Kinematics
        1. Velocity
        2. Acceleration
      2. Force
      3. Collisions
        1. Momentum
        2. Impulse
        3. Conservation of Momentum
        4. Kinetic Energy
        5. Coefficient of Restitution
        6. Conservation of Kinetic Energy
        7. Solving Our Final Velocities
        8. Creating a Collision Response Demo
      4. Summary
    2. 15. Finite State Machines and Game State Management
      1. Finite State Machine
      2. Object-Oriented Design
      3. Managing Game States
      4. Managing Game States Demo
      5. Summary
    3. 16. AI Algorithms
      1. Setting Up Our Demo
      2. Chase Algorithm
      3. A Better Chase Algorithm
      4. Evading Algorithm
      5. Random Movement
      6. Creating a Finite State Machine
      7. Summary
  13. VII. 3D Effects
    1. 17. Advanced Texturing Techniques
      1. 3D Lighting
        1. Creating a Custom Vertex Format
        2. Creating the Demo
        3. Ambient Lighting
        4. Directional Lighting
      2. Bump Mapping
      3. Normal Mapping
      4. Parallax Mapping
      5. Relief Mapping
      6. Texture Animation
      7. Summary
    2. 18. Special Effects
      1. Transitions
        1. Cross-Fade (Dissolve)
        2. Directional Wipes
      2. Making Fire
      3. Summary
    3. 19. Particle System
      1. Particle System Defined
      2. Point Sprite Defined
      3. Creating the Particle Class
      4. Creating the VertexPointSprite Struct
      5. Creating the Particle System Engine
      6. Point Sprite Effect File
      7. Particle System Demo
      8. Creating Particle Effects
        1. Rain
        2. Bubbles
        3. Laser Shield
        4. Laser Scanner
          1. Poisonous Gas
          2. The Colorful Effect
      9. Summary
  14. VIII. Putting It Into Practice
    1. 20. Creating a 3D Game
      1. Creating the Tunnel Vision Game
        1. Creating the Game States
        2. Adding a Skybox to Our Game
        3. Compiling the Game
      2. Creating the Game Logic
      3. Creating the Crosshair
      4. Creating the Game-Specific Camera
      5. Summary
    2. 21. Improving the Game
      1. Creating the Radar
      2. Creating the Tunnel
      3. Creating the Level Timer
      4. Creating the HUD
      5. Adding Scoring
      6. Keeping Track of High Scores
      7. Summary
    3. 22. Finishing Touches
      1. Updating the Title Screen
      2. Updating the Start Menu
      3. Creating the High Score Screen
      4. Updating the Options Menu
      5. Updating the Remaining States
      6. Using the Particle System
      7. Adding Sound
      8. Suggested Improvements
      9. Summary