CRE ATIN G YOUR FIRS T 2 D GA ME in Font

Make PDF417 in Font CRE ATIN G YOUR FIRS T 2 D GA ME

CHAPTER 3 CRE ATIN G YOUR FIRS T 2 D GA ME
Create PDF-417 2d Barcode In None
Using Barcode generator for Font Control to generate, create PDF417 image in Font applications.
www.OnBarcode.com
EAN128 Drawer In None
Using Barcode printer for Font Control to generate, create GS1-128 image in Font applications.
www.OnBarcode.com
Figure 3-1. Final look of Rock Rain From a game programmer s point of view, things like spaceships, meteors, and scores are objects in your game. You should also detail these objects before you start programming anything. Each object in the game has its own characteristics and behavior: the rocks fall, the player controls the spaceship, the score grows with the meteor count, and so on. The correct definition of the behavior and the state control of the game s objects are the most challenging tasks in game programming. That s why your game should be well thought out before you start to build anything. You also need to consider the audio portions for the game. For Rock Rain, you ll have only three sound effects: music that plays while the game is active, a sound that plays when a new meteor is added to the game, and an explosion sound that plays when the player collides with a meteor. And as another feature, when a collision occurs, you ll make the player s Xbox 360 gamepad shake, to give an impact effect.
Data Matrix Generator In None
Using Barcode encoder for Font Control to generate, create DataMatrix image in Font applications.
www.OnBarcode.com
Code-128 Drawer In None
Using Barcode encoder for Font Control to generate, create Code 128A image in Font applications.
www.OnBarcode.com
Let s Get to It
Barcode Generator In None
Using Barcode creator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
UPC-A Supplement 5 Printer In None
Using Barcode creator for Font Control to generate, create UPC-A Supplement 5 image in Font applications.
www.OnBarcode.com
As you might have guessed, your first game is created as an XNA Windows Game project, which you ve explored in the previous chapters. So, start by opening Visual Studio and creating a new Windows Game project called RockRain. The Solution Explorer window will look like Figure 3-2.
PDF-417 2d Barcode Printer In None
Using Barcode generation for Font Control to generate, create PDF417 image in Font applications.
www.OnBarcode.com
Make Code 11 In None
Using Barcode printer for Font Control to generate, create USD8 image in Font applications.
www.OnBarcode.com
C HA PTER 3 C REAT I NG YOUR F IR ST 2D GAME
Encode PDF417 In None
Using Barcode maker for Software Control to generate, create PDF417 image in Software applications.
www.OnBarcode.com
Paint PDF 417 In Visual Basic .NET
Using Barcode encoder for .NET Control to generate, create PDF417 image in .NET framework applications.
www.OnBarcode.com
Figure 3-2. The Solution Explorer window after creating the Rock Rain project As explained in 1, the Content folder is a special item in XNA projects. In this folder, you ll place all the game s assets, such as images, sounds, and so on everything that should be loaded through the Content Pipeline. You can download all the files used in this project from the book s details page at the Apress web site (http://www.apress.com).
Generating Barcode In Java
Using Barcode drawer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
GS1 128 Creation In None
Using Barcode creator for Software Control to generate, create UCC.EAN - 128 image in Software applications.
www.OnBarcode.com
Drawing the Background
Recognizing Barcode In Visual C#.NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
GS1 - 13 Drawer In .NET
Using Barcode creator for Reporting Service Control to generate, create EAN-13 image in Reporting Service applications.
www.OnBarcode.com
Start by putting a background in your game. For a space game, nothing is better than an image of a galaxy! Add the file SpaceBackground.dds to the Content folder. You should load this texture so that it fits the whole screen of the game. First, define the texture in your code. Add this attribute to your Game1 class: // Background texture private Texture2D backgroundTexture; As you saw in the previous chapter, you ll load this texture and initialize the spriteBatch object in the LoadContent method: // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Load all textures backgroundTexture = content.Load<Texture2D>(" SpaceBackground"); } You need to load the texture using the spriteBatch object. Declare it in the Game1 class: private SpriteBatch spriteBatch = null; Now you can draw the background. Add the following code in the Draw method of the Game1 class:
GS1 - 13 Creation In Java
Using Barcode drawer for Java Control to generate, create EAN 13 image in Java applications.
www.OnBarcode.com
QR Generation In Objective-C
Using Barcode generation for iPhone Control to generate, create QR Code JIS X 0510 image in iPhone applications.
www.OnBarcode.com
CHAPTER 3 CRE ATIN G YOUR FIRS T 2 D GA ME
create qr code using excel
Using Barcode creation for Office Excel Control to generate, create QR Code JIS X 0510 image in Office Excel applications. barcode generator excel 2010 free create qr code using excel
www.OnBarcode.com
Paint PDF417 In Java
Using Barcode drawer for Java Control to generate, create PDF417 image in Java applications.
www.OnBarcode.com
// Draw background texture in a separate pass. spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture,new Rectangle(0, 0, graphics.GraphicsDevice.DisplayMode.Width, graphics.GraphicsDevice.DisplayMode.Height), Color.LightGray); spriteBatch.End(); Run the game by pressing F5. If everything is correct, the result will look like Figure 3-3.
Creating UCC-128 In VB.NET
Using Barcode generation for VS .NET Control to generate, create EAN128 image in Visual Studio .NET applications.
www.OnBarcode.com
Paint Barcode In None
Using Barcode drawer for Office Excel Control to generate, create Barcode image in Microsoft Excel applications.
www.OnBarcode.com
Figure 3-3. Rock Rain background
Creating the Player s Game Component
The player is represented in the game as a small spaceship that can be controlled using an Xbox 360 gamepad or a PC keyboard. The image of this spaceship is in the RockRain.png file. Add it to the project inside the Content folder. This texture contains the image of the player s spaceship and also the meteors that the player must avoid (see Figure 3-4).
C HA PTER 3 C REAT I NG YOUR F IR ST 2D GAME
Figure 3-4. Player and meteor texture As you did for the background, first declare the texture in the Game1 class: private Texture2D meteorTexture; Then load it in the LoadContent method immediately after loading the background texture: meteorTexture = content.Load<Texture2D>(" RockRain");
Note The graphics in this chapter and the next were built using SpriteLIB GPL, available from http://
www.flyingyogi.com/fun/spritelib.html. SpriteLib GPL is a collection of static and animated graphic objects (also commonly known as sprites).
Now you ll create a class that represents the player in the game. Add a new GameComponent to the project, name the file Ship.cs (as in Figure 3-5), and click OK. The new file added to the project contains a class that derives from GameComponent. This game component will be visible in the game; therefore, it must be drawn. Derive from DrawableGameComponent so that you have a Draw method you can use to draw in the game. This game component copies the texture region that contains the picture of the spaceship in the specified position. To accomplish that, it needs the texture where this picture is, the coordinates of the picture in this texture, and the coordinates on the screen where the picture must be rendered.
Copyright © OnBarcode.com . All rights reserved.