Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Microsoft® XNA® Game Studio 4.0: Learn Programming Now!
Acknowledgments
Introduction
Who This Book Is For
System Requirements
Code Samples
Errata and Book Support
We Want to Hear from You
Stay in Touch
I. Getting Started
1. Computers, C#, XNA, and You
Introduction
Learning to Program
Becoming a Great Programmer
How the Book Works
C# and XNA
Getting Started
Installing the Development Environment and the XNA Framework
Setting Up a PC to Run XNA Games
Setting Up an Xbox 360 to Run XNA Games
App Hub
XNA Game Studio Connect
XNA Game Studio Device Center
Setting up a Windows Phone to run XNA games
Selling Your Windows Phone Games in the Marketplace
Connecting a Windows Phone to a Windows PC
Writing Your First Program
Creating Your First Project
Running Your First Program
Stopping a Program
Storing Games on the Xbox 360 or Windows Phone
Running the Same XNA Game on Different Devices
Creating a Copy of an XNA Project for Another Device
Choosing Between Windows Phone and Emulator
Conclusion
Chapter Review Questions
2. Programs, Data, and Pretty Colors
Introduction
Making a Game Program
Statements in the Draw Method
Working with Colors
Storing Color Values
Setting a Color Value
Controlling Color
Games and Classes
Classes and Behaviors
Drawing and Updating in Games
Sharing Game World Data Between Draw and Update
Classes as Offices
Game World Data
Storing Data in Computer Memory
Drawing by Using Our Color Intensity Variables
Updating Our Colors
Memory Overflow and Data Values
Making a Proper Mood Light
Making Decisions in Your Program
Creating Conditional Statements
Adding an Else Part
Testing Values
The Completed Mood Light
A Proper Funky Mood Light
Finding Program Bugs
Conclusion
Chapter Review Questions
3. Getting Player Input
Introduction
Reading a Gamepad
Gamepads and Classes
Finding a Gamepad
Testing the Gamepad Status
Using the Keyboard
Stopping the Game with the Escape Key
Using a Gamepad and a Keyboard at the Same Time
Adding Vibration
Controlling the Vibration of a Gamepad
Testing Intensity Values
Program Bugs
Conclusion
Chapter Review Questions
II. Images, Sound, and Text
4. Displaying Images
Introduction
Resources and Content
Getting Some Pictures
Content Management Using XNA
Working with Content Using XNA Game Studio
XNA Game Studio Solutions and Projects
Adding Content to a Project
Adding Links to Resources
The XNA Content Pipeline
Using Resources in a Game
Loading XNA Textures
Positioning Your Game Sprite on the Screen
Sprite Drawing with SpriteBatch
Filling the Screen
Intellisense
Conclusion
Chapter Review Questions
5. Writing Text
Introduction
Text and Computers
Text as a Resource
Creating the XNA Clock Project
Adding a Font Resource
The XML File Format
Loading a Font
Drawing with a Font
Changing the Font Properties
Getting the Date and Time
Making a Prettier Clock with 3-D Text
Drawing Multiple Text Strings
Repeating Statements with a for Loop
Other Loop Constructions
Fun with for Loops
Creating Fake 3-D
Creating Shadows Using Transparent Colors
Drawing Images with Transparency
Conclusion
Chapter Review Questions
6. Creating a Multi-Player Game
Introduction
Creating the Button-Bash Game
Button-Bash Game Data
Starting the Button-Bash Game
Displaying the Button-Bash Count Value
Counting Button Presses
Detecting Changes in the Button Position
Level and Edge Detectors
Constructing the Complete Game
Code Design
Adding Test Code
Conclusion
Chapter Review Questions
7. Playing Sounds
Adding Sound
Creating the Drum Pad Project
Capturing Sounds with Audacity
Sounds and File Types
Storing Sounds in Your Project
Using Sounds in an XNA Program
Playing Sounds
Playing Background Music
Creating a RayGun
The SoundEffectInstance Class
Controlling a Sound Effect Instance
Changing Instance Properties
Sound Bugs from Your Younger Brother
Checking for Null References
The XACT Audio Tool
Playing Songs Using the MediaPlayer Class
Conclusion
Chapter Review Questions
8. Creating a Timer
Making Another Game
Reaction Timer Bug
Finding Winners Using Arrays
Creating an Array
Using Data in an Array
Scanning an Array
Using an Array as a Lookup Table
Displaying the Winner
Conclusion
Chapter Review Questions
9. Reading Text Input
Using the Keyboard in XNA
Creating the Message Board Project
Registering Key Presses
Detecting When Keys Are Pressed
The Keys Type
Enumerated Types
Working with Arrays, Objects, and References
Values and References
Arrays as Offices
Say Hello to the Garbage Collector
Using References and Values
Why Do We Have References and Values?
References and GetPressedKeys
Displaying Keys
Detecting Key Presses
Using Break to Improve Performance
Decoding Key Characters
Using the Shift Keys
Editing the Text
Conclusion
Chapter Review Questions
III. Writing Proper Games
10. Using C# Methods to Solve Problems
Introduction
Playing with Images
Zooming In on an Image
Creating a Zoom-Out
Updating the Drawing Rectangle
Creating a Method to Calculate Percentages
Putting a Method into Your Game Class
Calling a Method
Returning Nothing Using void
Creating a getPercentage Method
Testing a Method
Designing Tests for getPercentage
Creating the getPercentage Method Body
Debugging C# Programs
Debugging with Breakpoints
Hitting a Breakpoint
Viewing Variables
Using Floating-Point Numbers in C#
The Compiler and C# Types
Compilers and Casting
Expression Types
Stopping the Zoom
Zooming from the Center
Conclusion
Chapter Review Questions
11. A Game as a C# Program
Introduction
Creating Game Graphics
Projects, Resources, and Classes
XNA Game Studio Solutions and Projects
Projects and Folders
The Game Program Files
The Program.cs File
Namespaces and Programs
Static Classes and Methods
Making Methods Static
Main Method Parameters
The C# Using Statement
The Main Method in an XNA Game
Renaming the Game1 Class
Creating Game Objects
Sprites in Games
Managing the Size of Game Sprites
Working with Floating-Point Values and Integers
Double Precision Floating-Point Values
Drawing and Aspect Ratios
Sprite Sizing
Moving Sprites
Bouncing the Cheese
Dealing with Display Overscan
Conclusion
Chapter Review Questions
12. Games, Objects, and State
Introduction
Adding Bread to Your Game
Using a Structure to Hold Sprite Information
Using the Gamepad Thumbsticks to Control Movement
Improving Programs Using Methods
Value and Reference Parameters
Handling Collisions
Making the Cheese Bounce off the Bat
Strange Bounce Behavior
Strange Edge Behavior
Debugging a Running Program
Adding Tomato Targets
Windows Phone Image Sizes
Tomato Collisions
Controlling Sprite Visibility
Setting the Initial Visibility State
Using the Visible Field When Drawing
Conclusion
Chapter Review Questions
13. Making a Complete Game
Introduction
Making a Finished Game
Adding Scores to a Game
Drawing Text in the Game
Adding Survival
Adding Progression
Improving Code Design
Refactoring by Creating Methods from Code
Refactoring by Changing Identifiers
Creating Code Regions
Creating Useful Comments
Adding a Background
Adding a Title Screen
Games and State
Using the State Values
Building a State Machine
Conclusion
Chapter Review Questions
14. Classes, Objects, and Games
Introduction
Design with Objects
An Object Refresher Course
Cohesion and Objects
Creating a Cohesive BatSpriteStruct
Protecting Data Inside Objects
BatSpriteStruct Behaviors
Objects and Encapsulation
Coupling Between Objects
Creating a Link Between the Bread Bat and the Cheese Ball
Designing Object Interactions
Objects and Messages
Messages and Organization
Container Objects
Background and Title Screen Objects
Classes and Structures
Creating and Using a Structure
Creating and Using an Instance of a Class
References
Multiple References to an Instance
No References to an Instance
Why Bother with References?
Value and Reference Types
Should Our Game Objects Be Classes or Structures?
Game Objects Should Be Structures Managed by Value
Game Objects Should Be Classes Managed by Reference
Creating a Sprite Class Hierarchy
The BaseSprite Class
Using the BaseSprite to Store the Background
Extending the BaseSprite to Produce a TitleSprite
Overriding Methods from a Parent Class
Building a Class Hierarchy
Using Protected Members from a Parent Class
Adding a Deadly Pepper
Creating a DeadlySprite Class
Drawing the Deadly Pepper Sprite
Setting Up the Deadly Pepper Sprite
Updating the Deadly Pepper Sprite
Conclusion
Chapter Review Questions
15. Creating Game Components
Introduction
Objects and Abstraction
Creating an Abstract Class in C#
Extending an Abstract Class
Designing with Abstract Classes
References to Abstract Parent Classes
Constructing Class Instances
Constructors in Structures
Constructors in Class Hierarchies
Constructors in Child Classes
Adding 100 Killer Tangerines
Creating a KillerSprite Class
Positioning the KillerSprites Using Random Numbers
Pseudorandom Numbers
The .NET Random Class
Creating a Static Random Generator for the KillerSprite
Getting a Random Sequence of Numbers
Using Lists of References
Creating a List Collection
Adding Items to a List
Accessing List Elements
Working Through List Elements Using foreach
Setting Up the Game Sprites
Extra List Features
Adding Artificial Intelligence
Chasing the Bread Bat
Using Properties to Read the Bread Bat Position
Creating the KillerSprite-Chasing AI
Hitting the Killer Sprite Tangerines
Adding Game Sounds
From Objects to Components
C# Interfaces
Creating an Interface
Implementing an Interface
References to Interfaces
Linking Bread, Cheese, and Tomatoes
Designing with Interfaces
Conclusion
Chapter Review Questions
16. Creating Multi-Player Networked Games
Introduction
Networks and Computers
Starting with the Signal
Building Up to Packets
Addressing Messages
Routing
Calls and Datagrams
Networks and Protocols
Xbox Live
Gamertags and Xbox Live
System Link and XNA
Bread and Cheese Pong
Managing Gamer Profiles in XNA
Creating a Profile
Automatic Sign-In
Ensuring a Gamer Is Signed In for Network Play
Creating a Game Lobby
Network Games and State
Starting at the Title Screen
Signing In Players
Selecting the Role of Host
Displaying the Contents of the Lobby
Selecting the Role of Player
Waiting for a Host
Playing the Game
Game Topology
Creating the Server Behavior
Creating the Client Behavior
The Completed Game
Conclusion
Chapter Review Questions
IV. Making Mobile Games for Windows Phone 7 with XNA
17. Motion-Sensitive Games
Introduction
The Accelerometer
What Does the Accelerometer Actually Do?
Acceleration and Physics
Making Sense of Accelerometer Readings
Creating a “Cheese Lander” Tipping Game
Game World Objects in “Cheese Lander”
Getting Access to the Accelerometer Class from XNA
Using the Accelerometer in an XNA Game
Starting the Accelerometer
Using Accelerometer Values in a Game
Improving Game Play by Adding Physics
Using Vectors to Express Movement
Adding Friction
Controlling Sounds with Vectors
Detecting Shaking
A Quick Digression About Threads and Synchronization
Conclusion
Chapter Review Questions
18. Exploring Touch Input
Introduction
The Windows Phone Touch Screen
Getting Touch Input
Creating a Panic Button
Reading Touch Events
Touch Location Types
Using the Location of a Touch
Creating a Touch Drumpad
Creating a soundPad Class for Each Drum Sound
Storing soundPad Values in the Game
Drawing the Soundpads
Updating the Soundpads
Making the Soundpads Flash
Creating a Shuffleboard Game
The PuckSprite Class
Updating a Stationary Puck
Dragging the Puck Across the Panel
Puck Movement Across the Board
Emulators and Real Devices
Conclusion
Chapter Review Questions
19. Mobile Game Development
Introduction
The Windows Phone
The Windows Phone Marketplace
Maximizing the Phone Battery Life in XNA Games
Setting the Update Rate of a Game
Dealing with Changes in Phone Orientation
Selecting Orientations in an XNA Game
Getting Messages When the Orientation Changes
Using a Specific Display Size for Windows Phone Games
Hiding the Windows Phone Status Bar
Stopping the Screen Timeout from Turning Off Your Game
Creating a Phone State Machine
Games and States
Creating a Simple Game State Machine
Creating More Complex State Machines
Handing Incoming Phone Calls
Detecting Phone Calls
A Game as a Windows Phone Application
The Windows Phone Back and Start Buttons
Starting New Programs with the Start Button
Using Isolated Storage to Store Game State
Storing Files in Isolated Storage
Connecting Streams Together
Saving the State of a Game
Loading a Saved Game
Exceptions in Number Reading
Erasing Saved Files
Creating a Well-Behaved Game
Getting Your Games into the Marketplace
The Windows Phone Marketplace
Registering for the App Hub
Using a Windows Phone Device
Creating Games for Sale
Conclusion
Chapter Review Questions
A. Answers to the Chapter Review Questions
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
B. About the Author
Rob Miles
Index
About the Author
← Prev
Back
Next →
← Prev
Back
Next →