Book Image

XNA 4.0 Game Development by Example: Beginner's Guide

By : Kurt Jaegers
Book Image

XNA 4.0 Game Development by Example: Beginner's Guide

By: Kurt Jaegers

Overview of this book

XNA Game Studio enables hobbyists and independent game developers to easily create video games. It gives you the power to bring your creations to life on Windows, the Xbox 360, the Zune, and the Windows Phone platforms. But before you give life to your creativity with XNA, you need to gain a solid understanding of some game development concepts.This book covers both the concepts and the implementations necessary to get you started on bringing your own creations to life with XNA. It details the creation of four games, all in different styles, from start to finish using the Microsoft XNA Framework, including a puzzler, space shooter, multi-axis shoot-'em-up, and a jump-and-run platform game. Each game introduces new concepts and techniques to build a solid foundation for your own ideas and creativity. Beginning with the basics of drawing images to the screen, the book then incrementally introduces sprite animation, particles, sound effects, tile-based maps, and path finding. It then explores combining XNA with Windows Forms to build an interactive map editor, and builds a platform-style game using the editor-generated maps. Finally, the book covers the considerations necessary for deploying your games to the Xbox 360 platform.By the end of the book, you will have a solid foundation of game development concepts and techniques as well as working sample games to extend and innovate upon. You will have the knowledge necessary to create games that you can complete without an army of fellow game developers at your back.
Table of Contents (15 chapters)
XNA 4.0 Game Development by Example Beginner's Guide
Credits
About the Author
About the Reviewers
Preface
4
Asteroid Belt Assault – Lost in Space
Index

Preface

The Microsoft XNA Framework provides a powerful set of tools to allow development teams of any size, from the individual developer to larger independent teams, to rapidly develop high performance quality games for multiple Microsoft-related platforms.

This book will present a series of video games, utilizing XNA Game Studio and the XNA Framework to delve into the world of 2D game development targeting the Microsoft Windows environment. We will utilize XNA's 2D graphics capabilities to present our games to the player, and look at the fundamental systems behind several game design challenges, such as path-finding, collision detection, special effects, and more.

Each of the four games in this book cover a new gaming style, and introduce progressively more advanced techniques and systems to provide a foundation for bringing your own creations to life.

What this book covers

Chapter 1, Introducing XNA Game Studio begins by looking at the history of the XNA Framework and its predecessors, and installing the Windows Phone Development Tools package that includes the version 4.0 release of the XNA tools. We wrap up this chapter by looking at the building blocks of an XNA game and putting together an XNA mini-game called SquareChase.

Chapter 2, Flood Control – Underwater Puzzling introduces a board-based puzzle game called Flood Control. We introduce the XNA Content Pipeline, and build a recursive function to determine the state of the game board while playing.

Chapter 3, Flood Control – Smoothing out the Rough Edges refines and completes the Flood Control game, adding animated rotation, movement, and fading of game pieces. We will implement a scoring system and cover displaying text to the screen.

Chapter 4, Asteroid Belt Assault – Lost in Space begins developing our second game. This time we put together a space-based shooter. We will create a basic moving star field using a simple particle system, and introduce frame-based sprite animation. We will add moving asteroids to our star field and examine how to detect collisions between asteroids and make them respond realistically. We add a player-controlled spaceship, and enemies that can fly across the screen following pre-defined waypoints.

Chapter 5, Asteroid Belt Assault – Special Effects wraps up Asteroid Belt Assault. We implement collision detection between the player, enemies, asteroids, and bullets and create particle-based explosions. Finally, we will look at loading and playing sound effects to bring life to our in-game events.

Chapter 6, Robot Rampage – Multi-Axis Mayhem begins the construction of a tank-based game in which the player can move and fire independently using either an Xbox 360 controller or the keyboard. We build a tile-map based game world and a camera class to view a screen-sized area of the larger world, and implement player collision with the walls of the tile map.

Chapter 7, Robot Rampage – Lots and Lots of Bullets completes Robot Rampage by expanding on our particle-based explosion system, and adding enemies, player goals, and weapon upgrades to our tile map. We allow the player to fire at the enemies with several different weapons. Finally, we create an implementation of the A* path-finding algorithm to allow the enemy tanks to track down the player.

Chapter 8, Gemstone Hunter – Put on your Platform Shoes introduces a side-scrolling, jump-and-run platform game. We start by evolving our tile-based mapping system to allow multiple layers of tiles, and look at combining XNA and Windows Forms to produce a map editor for Gemstone Hunter. As part of this process, we will look at building more complex solutions that contain multiple projects, and separate our game's tile engine into a Game Library project.

Chapter 9, Gemstone Hunter – Standing on Your Own Two Pixels concludes the Gemstone Hunter project by examining an alternative method for frame-based sprite animation using player and enemy graphics from the XNA Platform Starter Kit. We implement platform physics and bring the game together by loading levels and reacting to their embedded code values.

What you need for this book

In order to install and use the Microsoft XNA 4.0 tools, you will need a Windows PC with either Microsoft Windows Vista or Microsoft Windows 7, and a video card supporting DirectX 9 or later. Shader Model 1.1 is required for XNA, but it is highly recommended that your video card support Shader Model 2.0 or later, as many of the XNA samples available online require 2.0 support.

Who this book is for

If you are an aspiring game developer who wants to take a shot at creating games for the Microsoft Windows platform with the XNA Framework, then this book is for you. Using this book, you can get started with creating games without any game development experience. A basic knowledge of C# would be helpful to kick start your game development, but it's not essential.

Conventions

In this book, you will find several headings appearing frequently.

To give clear instructions of how to complete a procedure or task, we use:

Time for action – heading

  1. Action 1

  2. Action 2

  3. Action 3

Instructions often need some extra explanation so that they make sense, so they are followed with:

What just happened?

This heading explains the working of tasks or instructions that you have just completed.

You will also find some other learning aids in the book, including:

Have a go hero – heading

These set practical challenges and give you ideas for experimenting with what you have learned.

You will also find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "If the mouse reports that the left button is pressed, the code checks with the currentSquare object by calling its Contains() method to determine if the mouse's coordinates fall within its area."

A block of code is set as follows:

spriteBatch.Begin();
spriteBatch.Draw(
    squareTexture,
    currentSquare,
    colors[playerScore % 3]);
spriteBatch.End();

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Run your game by clicking on Start Debugging from the Debug menu".

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.