Writing My 1st Zune HD Game - Inertia

All RIGHT! Today is 9/17 and my Zune HD is out for delivery. Naturally I’ve already started making a game for the thing. Well, actually, I’ve started writing the blog post – i’ll keep the post going as I build the game.

Because I don’t have a lot of brainpower left for creativity, I’m going to make the first app anyone builds for a device with an accelerometer, which is the one where you move the ball through a maze and try to avoid going down a hole. Now there are not many kid-friendly titles that you can make with the words “balls” and “hole,” so I am going to tentatively call this game Inertia.

The first thing I’m going to do is make the game project in Visual C# 2008 Express.

Prerequisites (install in this order)

 

Creating The Zune HD Game Project

  1. Open Visual C# Express 2008
  2. File –> New Project –> Zune Game (3.1) (as shown)
    image

OK, so that was really easy. Now I’m going to create some content.

Making Content

I’ll make a ball, and a background. My thought process at this point is how am I going to make the maze? And the answer to that is to make a tile-based game. Tiles are squares, and the Zune HD’s screen resolution is 480x272, both of which have a common factor of 16. So my tile grid will be 30 tiles by 17 tiles. Kind of an odd number but OK.

First I’m going to use a graphic design tool to make a background of some sort. Maybe something cool and icy. I’ll make a new folder called Textures under the Content folder and save it as background.png.

background

Next, I’ll make a ball. This should be really easy. It has to fit in any given tile at any time, so it has to be less than 16 by 16. Let’s make it 14x14 just so it stays an even number.

 image

Now I am going to make a single block which I will use as my walls. I will use transparency to make this less ugly in the game.

block

Remember that we have a grid of 30 by 17 tiles. So let’s mock up a quick level, which we will make into a readable format later. I printed off my grid of 30x17 and penciled in a quick level. The X’s represent holes. The S and E are start and end tiles. I will actually rotate this 90 degrees so that it’s easier to draw on the screen and it overlays the background nicely.

image image

Next I am going to put this into a text format that can be parsed by a content processor. I will use certain characters to denote elements for the tiles:

  • _ : blank space
  • X : hole
  • * : block
  • S : start
  • E : end

The result looks like this:

image

I saved it as Level1.dat under my content folder in a subfolder called Levels.

In the next post we’ll start bringing a lot of this content together. But before we do that I want to do one last thing: create a Windows copy of the project so we don’t have to deploy to Zune all the time.

Creating a Windows Copy of the Game

The purpose of the Window copy is really to verify layout and other things that are not device dependent. Obviously we can’t very well test playability on a PC, but this will definitely come in handy.

  • Right-click the Inertia Zune project (not the solution) and choose Create Copy of Project for Windows.

  • Go to Game1.cs and find the constructor for Game1. Add the code on lines 6-8. This will force the Windows game to be the same dimensions as the Zune game.

        1: public Game1()
        2: {
        3:     graphics = new GraphicsDeviceManager(this);
        4:     Content.RootDirectory = "Content";
        5:  
        6:     graphics.PreferredBackBufferHeight = 480;
        7:     graphics.PreferredBackBufferWidth = 272;
        8:     graphics.ApplyChanges();
        9:  
       10:     // Frame rate is 30 fps by default for Zune.
       11:     TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);
       12: }
    

 

That’s it for now – next post, we’ll make a little more progress on this game.