Introduction

XNA Game Studio 4.0 for Xbox 360 Developers is an intermediate-level book with an emphasis on programming in the C# language and targeting primarily the Xbox 360 platform. XNA Game Studio is Microsoft’s gift to game developers, of both the professional and hobby persuasion. Independent (“indie”) developers make up a particularly large group that benefits from XNA Game Studio due to Microsoft’s very appealing publishing royalty terms on the Xbox Live Indie Arcade (XBLIA) service, which makes their indie games available to the general public via Xbox Live.

This book was originally intended to be a comprehensive reference on the XNA Framework library. When XNA Game Studio 4.0 was announced in early 2010, work shifted from an XNA 3.1 reference to a more comprehensive applied book on XNA 4.0. Part II, “XNA Framework Library,” is only a quick reference to the XNA Framework, with simple examples, not a large and complex one. Although the reference information is comprehensive—covering every namespace—it is not overly detailed. Not every overloaded method is listed. Constructors and method parameters are not expanded in detail; we have MSDN resources online for that. The purpose of this book, then, is to provide a quick reference of the XNA Framework as it applies to the Xbox 360, and for C# programmers primarily interested in creating games for this platform.

XNA Game Studio 4.0

XNA Game Studio makes it possible to create games for the popular Xbox 360 video-game console system! This is the most significant platform of note. When XNA Game Studio 1.0 was released to developers in 2006, it marked the first time a video-game–console manufacturer released development tools for their system free to the public, without requiring an expensive license agreement. XNA Game Studio also targets the Windows platform. This might seem like a no-brainer, a foregone conclusion, to those already experienced with XNA. But it’s not at all common for a console-development tool to support both the console and the development PC platform! What this means is, you can compile and run your game code on your Windows PC for Windows or for Xbox 360, and then run it on either platform.

But that’s not all! Not to sound like an infomercial, but the latest version of XNA Game Studio, which is now up to version 4.0, also supports the mobile platform called Windows Phone 7. This is a hot new device that’s comparable to (and competitive with) Apple’s iPhone and Google’s Android mobile smart phones. Both Apple and Google provide free developer tools for the iPhone and Android, respectively, so Microsoft is on board with support for Windows Phone 7 in the new XNA Game Studio 4.0. Admittedly, this is the most significant reason for the new version, since XNA Game Studio 3.1 was released just about a year and a half earlier (in mid-2009), and 4.0 leverages Windows Phone 7 rather heavily. As a result of this new mobile device, the XNA team decided to sacrifice support for the Zune mobile media/music player. This is somewhat understandable, because Windows Phone 7 trumps Zune by supporting the same media playback capabilities in addition to smart-phone features comparable to the iPhone. There’s no compelling reason on the technical side to abandon Zune, so it must have been an issue of marketing, branding, and product placement, as well as slagging sales for the Zune platform.

Although the code in this book in general will compile and run on all platforms, we do cover the specific features available only on the Xbox 360. These features (such as Xbox Live Avatars) are not available on the other platforms such as Windows Phone 7.

Licensing and Memberships

On the Xbox 360 platform, you can compile and run your code on a retail Xbox 360! This is extremely exciting for game developers and video-game fans! Imagine seeing your own game running on your friend’s Xbox 360! Of course, there is a cost, because this is a huge benefit, but the cost is meager compared to the price of a full-blown Xbox Development Kit (XDK), which is used by professional game studios. To make this happen, you will need a membership for the XNA Creators Club, which has been renamed to App Hub. The cost is approximately $100 per year. You will also want an Xbox Live Gold account for best results, which is an additional cost of approximately $60 per year. These prices might be high for a student, but they are more than reasonable for an indie developer since the development tools are free!

This membership fee gives you the ability to publish your game online for others to purchase using Microsoft Points—the same currency used to buy expansions and other downloadable content (DLC) on Xbox Live! As an App Hub developer, your game will be listed in a special section of the Xbox Live Arcade (XBLA) called the Xbox Live Indie Arcade (XBLIA). Anyone on Xbox Live can download your game, presumably first as a demo version, and if they like it, they will buy your full version at the price you set. (Typical cost for a quality indie game is about 400 points, or about $5.) This is a great way to share your games with the world and make a decent living at it—if you have the talent and technical know-how to make a great game. The former is up to you, but this book will certainly help you with the latter!

We don’t get into account management, licensing terms, uploading games for review, and receiving royalties in this book, because frankly, the terms and conditions of those things change often. If you make your way to the last chapter and have a great idea for a game, then getting it up on XBLIA will be the easy part.

What Will You Learn?

This book teaches the beginning to intermediate C# programmer how to use XNA Game Studio 4.0 with Visual C# 2010 to create games primarily for the Xbox 360. Although most of the source code presented in these chapters can be adapted for the other platforms supported by XNA, the emphasis is on the Xbox 360 and Xbox Live. The first two chapters will help the reader get started with the new versions of these tools. Numerous chapters provide reference information for the XNA Framework. The latter chapters culminate in a networked multiplayer game called Tank Battle. This game, featured in the last chapter of the book, includes the networking code to allow two players to host or connect to each other (repeatedly) to drive their tanks around and shoot at each other. Granted, it’s not a highly polished game, and could use quite a bit of creative souping up, but it’s a good technical example of networking a sprite-based game with the most important features you will need to make your own game.

It’s true that we don’t spend much time on 3D rendering in this book. The reason is simple: We are focusing on the XNA Framework as a whole, and the Xbox 360 features in particular, which means coverage of the Xbox 360 controller, playing audio, and using features of Xbox Live—especially networking via system link and online. Chapter 12, “Avatars,” shows how to render a gamer avatar, which is a 3D character representing the player online. We also explore the loading and rendering of meshes in Chapter 15, “Meshes,” with the associated 3D camera and lighting code needed to make it work. These are very lightweight issues in rendering—just the absolute basics really—but then this book is not focused on rendering. Because XNA Game Studio 4.0 is based on DirectX 9, any book or reference on High Level Shader Language (HLSL) 3.0 will provide useful shader examples that will also work in XNA—including the same FX files.

There are scores of such books on DirectX 9 available. If you like this author’s writing style, I recommend his Multi-Threaded Game Engine Design (Course Technology PTR, 2010). This book covers basic shader theory, per-pixel lighting, surface detail effects like bump mapping and specular reflection (which add realism to a textured surface), heightmap terrain, skyboxes, and more—and the FX files in this book will work in your XNA projects. If you are looking for additional references, see Appendix, “Resources for Further Study,” for a list.

Prerequisites

The goal of this book is to teach you how to use the latest version of XNA Game Studio. You will benefit from a basic knowledge of Visual C# in advance, because we don’t really cover the language at all. Programming a game for the Xbox 360 is a challenge for an experienced developer, let alone a beginner. But by paying attention and studying the examples, even a beginner should be able to get through the book without too much difficulty, because the examples are on the small side for the most part.

Required Software

This book supports Visual C# 2010, which should be installed first—before XNA Game Studio 4.0. I recommend that you download the free version of Visual C# 2010 Express Edition. The URL is http://www.microsoft.com/express/Windows/. Because Web links change frequently, you may need to Google for “Visual C# 2010 Express download.” There may still be links to the 2008 version as well, but 2010 is required for XNA Game Studio 4.0.

Tip

You may continue to use XNA 3.1 with Visual C# 2008 simultaneously with the newer tools without any problems. This may be desirable if you need to continue to support Zune projects.

Another option is to install the Windows Phone 7 developer tools, which include both Visual C# 2010 Express and XNA Game Studio 4.0. Although some extra tools are included that you may not need, such as Silverlight, these are good tools to have anyway should you wish to delve into Windows Phone 7 development. The URL is http://www.microsoft.com/express/Phone/.

Downloading the Sources

My Web site is at http://www.jharbour.com. There is information about this book and links to the sources that you may download. Most visitors join the forum to discuss their game projects and ask questions. If you have any problems working through this book, stop by the forum to chat. Since the book ships without a CD, you will need to download the resource files, which includes the source code for all of the projects in the book. The URL is http://www.cengage.com/downloads. The aforementioned Web forum also provides links to the sources at http://www.jharbour.com/forum.

Contents

The book is divided into three major parts:

  • Part I, “Introduction and Primer.”This part includes two chapters that will help get you started programming in XNA, with an introduction to the new features in XNA 4.0 as well as coverage of the XNA Framework and how to create new projects with Visual C# 2010. It includes the following chapters:

    • Chapter 1: “Introduction to XNA Game Studio 4.0”

    • Chapter 2: “Peeking Under the Hood”

  • Part II, “XNA Framework Library.”This part includes nine chapters that provide a reference for the XNA Framework with sample code to show how each namespace in the XNA Framework can be used in a game project. Chapters in this part are as follows:

  • Part III, “Xbox Live.”This part includes six applied chapters covering the major features of Xbox Live that can be utilized in an XNA 4.0 project, including coverage of avatars and multiplayer networking. The final chapter culminates in a multiplayer Tank Battle game that demonstrates the networking capabilities of XNA and acts as a rudimentary networked game engine for your own projects. Chapters 12 and 15 both cover 3D programming, loading a mesh, and rendering it using a basic shader.

Conventions Used in This Book

Source code is presented in fixed-width font for easy readability.

// This is how source code will be formatted in the text
public void Hello()
{
     Console.WriteLine("Hello World");
}

The following styles are used in this book to highlight portions of text that are important. You will find note boxes here and there throughout the book.

Note

Notes offer additional pointers on the current subject being covered or additional details and information about a subject that should help the reader get the most out of the situation.

Sidebar

A sidebar is an often lengthy paragraph about a related but off-topic subject, set apart so as to avoid interrupting the flow of thought on the main thread of the chapter.

Companion Web Site Downloads

You may download the companion Web site files from www.courseptr.com/downloads. Please note that you will be redirected to our Cengage Learning site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.210