INTRODUCTION TO PROGRAMMING THROUGH GAME DEVELOPMENT USING MICROSOFT XNA GAME STUDIO LAB 1.1 GETTING STARTED WITH XNA GAME STUDIO This lab contains the following exercises and activities: 1.1 1.2 1.3 1.4 1.5 Making an XNA Game Program................................................................ 1 Deploying an XNA Game ............................................................................. 2 Running an XNA Game Stored on an Xbox 360 ................................. 3 Deploying an XNA Game on a Different Device ................................. 3 Managing XNA Game Deployment.......................................................... 4 SCENARIO You have been employed by a games company as a developer. You will be responsible for creating games based on the ideas that your boss has had. Later, you will be expected to come up with game ideas of your own. The first thing you are required to do is learn how to drive the tools that you will be using to create the games. After completing this lab you will be able to: start XNA Game Studio and use it to create an initial XNA Game Studio project run an XNA game on a Windows PC deploy an XNA game to an Xbox 360 and run it run an XNA game stored on an Xbox 360 hard disk use XNA Game Studio to deploy a single XNA Game Studio solution on multiple devices configure Microsoft Visual Studio to select particular devices for program deployment Estimated lesson time: 50 minutes 1.1 MAKING AN XNA GAME PROGRAM Estimated completion time: 10 minutes In the first exercise you will create an initial XNA Game Studio project and run it on your Windows PC. 1. Start the computer and log on if necessary. 2. Press the Start button and navigate to the "Microsoft XNA Game Studio 3.0" program group. 3. Open the program group and start the version of Visual Studio 2008 held in this group. Note XNA can work with any version of Visual Studio 2008, so the precise version of Visual Studio that you see in the XNA Game Studio 3.0 Introduction to Programming Through Game Development Using Microsoft XNA Game Studio 1 program group will depend on what has been installed on your PC. However, all versions of Visual Studio are used in exactly the same way to write XNA games. 4. If you are using Visual Studio 2008 Express edition select File>New Project to open up the New Project dialog. 5. If you are using any other version of Visual Studio select File>New->Project from the Visual Studio menu to open up the New Project dialog. 6. Select the Windows Game (3.0) template from the XNA Game Studio 3.0 Project types. 7. Set the location for the project to a sensible folder on your machine. 8. Give the project the name FirstGame. 9. Ensure that the "Create directory for solution" checkbox is checked. 10. Click OK to create the project. 11. Select Debug->Start Debugging from the Visual Studio menu to run the game. The initial game project displays a cornflower blue background. 12. Stop the game by closing the form that contains it, or by using Debug->Stop Debugging. You can also stop the game by pressing the Back button on a gamepad connected to the Windows PC. 13. Exit from Visual Studio. 1.2 DEPLOYING AN XNA GAME Estimated completion time: 10 minutes You now know how to run a game on a Windows PC. Now you are going to create a game and run it on an Xbox 360. Note This activity can only be performed if you have an Xbox 360 available which is connected to the PC and an Xbox Live account which is linked to at least a Trial XNA Creators Club membership. Both these systems must be connected to the Internet and the firewall must be open to allow them to contact the Xbox Live service. 1. Start Visual Studio and create a new XNA solution with the Xbox 360 Game template. Give the solution the name XboxGame. 2. Start the Xbox 360 console and log in to Xbox Live with your account. This account must be associated with a working Creators Club membership. 3. Start the XNA Game Studio Connect application on the Xbox 360. Note If this is the first time you have used XNA on your Xbox 360 you will need to download the XNA Game Studio Connect application from Xbox Live and then use the XNA Game Studio Device Center program from the XNA Game Studio 3.0 program group to link your PC and your Xbox. Introduction to Programming Through Game Development Using Microsoft XNA Game Studio 2 4. Select Debug->Run from the Visual Studio menu bar to deploy the program to the Xbox 360 and then run it. When the program runs it should display a blue screen on the Xbox 360. 5. Stop the game by pressing Back on gamepad 1 connected to the Xbox 360 or by selecting Debug->Stop Debugging from the Visual Studio menu bar. 6. Exit from the XNA Game Studio Connect application on the Xbox 360. 7. Exit from Visual Studio on the Windows PC. 1.3 RUNNING AN XNA GAME STORED ON AN XBOX 360 Estimated completion time: 10 minutes Once an XNA game has been deployed to an Xbox 360 it is stored on the hard disk of that device. In this exercise you will see how to find and run such a game. Note This activity can only be completed if you have previously completed Exercises 1.1 and 1.2. It can only be performed if the Xbox 360 to be used is connected to Xbox Live. 1. Use the gamepad to navigate to the Game Library on the Xbox 360 and locate the game that you previously ran. It will have the same name as the project that was created, which was XboxGame. 2. Run the game. Note that it just displays a blue screen. 3. Use the Back button on the gamepad to exit the XNA game. 1.4 DEPLOYING AN XNA GAME ON A DIFFERENT DEVICE Estimated completion time: 10 minutes Note This activity can only be performed if you have an Xbox 360 available which is connected to the PC. An XNA solution can contain a number of projects which share the same program files. Each project can be deployed to a different target device. In this exercise, you will take an existing project and use Visual Studio to make a copy of the project and deploy it to a different platform. 1. Start XNA Game Studio and open the solution FirstGame that you created in Exercise 1.1. If this solution is not available, recreate it using the Windows Game (3.0) template from the XNA Game Studio 3.0 project types. 2. Select Debug->Start Debugging from the Visual Studio menu and run the program on your PC. 3. Select Debug->Stop Debugging from the Visual Studio menu to stop the program. Introduction to Programming Through Game Development Using Microsoft XNA Game Studio 3 4. Now you are going to copy the project and make a version for the Xbox 360. Right-click on the FirstGame project in the Solution Explorer on the right of the Visual Studio display. This should cause a properties menu to appear for the project. 5. Select Create Copy of FirstGame for Xbox 360 from the properties menu. 6. Select Debug->Start Debugging from the Visual Studio menu and note what happens. Question Was this what you were expecting? At the moment, the new project is deployed to the Xbox 360 but does not run. This is because the Startup project for the solution is still the Windows PC one. 7. Right-click on the Xbox 360 Copy of FirstGame project. This should cause a properties menu to appear for this project. 8. Select Set as Startup Project from the properties menu. You should notice that the project Xbox 360 Copy of FirstGame is now displayed in bold in the Solution Explorer. 9. Select Debug->Start Debugging from the Visual Studio menu. The program will now be deployed to the Xbox 360 and run on that device. 10. Select Debug->Stop Debugging from the Visual Studio menu to stop the program. 1.5 MANAGING XNA GAME DEPLOYMENT Estimated completion time: 10 minutes Note This activity makes use of a project which targets a Zune device. However, you do not need to have a Zune device to perform the exercise. You have seen how to create multiple versions of an XNA game which can be deployed and run on different platforms. However, at the moment all the versions are built and deployed irrespective of which device you are actually using. In this exercise you are going to find out how to configure the solution to deploy only to particular devices. Some of the actions referred to in these instructions are described in detail in Exercise 1.1-1.4. 1. Start XNA Game Studio and create a brand new XNA solution called ZuneGame. The solution should be based on the Zune Game (3.0) template from the XNA Game Studio 3.0 project types. Note that you will not be deploying to a Zune, but you will be investigating how to change the target for a deployment. 2. Make a copy of the ZuneGame project to produce a Windows Copy of the ZuneGame project. 3. Select Debug->Start Debugging from the Visual Studio menu. Visual Studio will attempt to deploy the program to a Zune device and run it. This deployment will fail. Introduction to Programming Through Game Development Using Microsoft XNA Game Studio 4 4. Change the startup project to the Windows Copy of ZuneGame project. 5. Select Debug->Start Debugging from the Visual Studio menu. Although the startup project is now your Windows PC, Visual Studio will attempt to deploy the program to a Zune device. This deployment will fail. 6. On the top bar of Visual Studio, the Solutions Platforms combobox will be showing "Mixed Platforms.” This means that when the solution is built Visual Studio will deploy to every platform in the solution. You want to change this so that only the Windows PC project is deployed. Open the combo-box and change the setting to x86 (this is the setting for deployment to Windows PC). 7. Select Debug->Start Debugging from the Visual Studio menu. The game will run on the Windows PC and will not deploy to the Zune. Introduction to Programming Through Game Development Using Microsoft XNA Game Studio 5