How to fix the Alien Game Lab for Windows Phone

Alien Game on Windows Phone 7 built with XNATonight I went off to the very first Windows Phone 7 User Group meeting in Toronto, Ontario. There were a number of Rock Star presenters, including Joey DeVilla, Mark Arteaga, Anthony “The Mobile Situation” Bartolo, Mike Temporale; showing off the Features and Experience of the Phone, as well as a number of different apps.

While sitting in the Audience I worked away on a presentation that I’m going to be doing on XNA Game Programming on the Windows Phone. Which includes a demo of building a game, ensure the source code is provided in a timely fashion I opted to use the Alien Game Lab from Channel 9.

While running through the initial build of the game I noticed there were a few things which were slightly off in terms of how the game is supposed to function. Luckily it didn’t take much time to walk through the code and find the misbehaving code blocks.

Game Tombstoning

The “Back Button” is one of the three required hardware buttons on any Windows Phone 7 Device, it is required as it is supposed to provide a guaranteed User Experience that a User can rely on. The current download at the time of this blog post does not provide a good back button experience, in fact, the back button doesn’t do anything at all unless the current Game Session is Over (no lives remaining).

To handle this in accordance to the specifications as outlined in section 5.2.4 in the Windows Phone 7 Application Certification Requirements, add a Pause Menu to the Solution.

Opening a Pause Menu

The first option is to display the main menu which is Section 5.2.4 Stipulation ‘d’ which reads:

For games, when the Back button is pressed during gameplay, the game can choose to present a pause context menu or dialog or navigate the user to the prior menu screen. Pressing the Back button again while in a paused context menu or dialog closes the menu or dialog.

This can be achieved by modifying the MainMenuScreen.cs file, or how I did it, by introducing a new “Paused” Screen. The implementation is really up to you, this was just the simplest implementation without touching too much of the existing code.

if (input.PauseGame)
     if (gameOver == true)
          // Pull up another screen over the Game
          ScreenManager.AddScreen(new PausedScreen()); 

There will be a zip file of at the end of this entry where you will be able to download the final source for this solution.

Accelerometer Support

With the accelerometer being the only input device on the Phone for movement, it’s rather important for this functionality to be fixed in order to make the game entertaining. It seems like this application may have been ported to the Windows Phone, while maintaining the existing code which is supposed to allow Xbox Controller and Keyboard support for the Game. This feature could also be handled in two different ways in which I’ll only expand on one with code.

Compilation Symbols

The first article I had ever written on Development was a piece explaining Pre-processor Directives. These play a large role in multi-platform targeting [which is what XNA is all about]. Compilation symbols can be added to the Build Section of your Projects Properties, pairing compilation symbols with the #if directive allows the compiler to include only sections of code that are relevant for a particular platform that the code is being compiled against. Managing users input should be abstracted away from your logic as each platform has different input types and none of them are remotely similar [with the exception of the Zune and Windows Phone].

After Abstracting the input types into different classes you can surround the input handler creation with a pre-processor #if statement and have only the relevant code compile into your solution.

Remove Default Movement Assignment

After a little poking and prodding around the Accelerometer code I noticed that the Keyboard Support [which can be found after the Accelerometer Code Block] contained an if block, which had an else statement. This else statement was re-assigning the values for the movement variable which was set within the Accelerometer code. To get around this issue you can simply comment out [or remove] the else block.

//This section handles tank movement.  We only allow one "movement" action
//to occur at once so that touchpad devices don't get double hits.
KeyboardState keyState = Keyboard.GetState();

if (input.CurrentGamePadStates[0].DPad.Left == ButtonState.Pressed || keyState.IsKeyDown(Keys.Left))
    player.Velocity.X = -1.0f;
else if (input.CurrentGamePadStates[0].DPad.Right == ButtonState.Pressed || keyState.IsKeyDown(Keys.Right))
    player.Velocity.X = 1.0f;
//player.Velocity.X = MathHelper.Min(input.CurrentGamePadStates[0].ThumbSticks.Left.X * 2.0f, 1.0f);

Obviously this is a work around solution for the phone, if you plan on supporting all 3 platforms, I would suggest spending a little bit more time on this ensuring that this doesn’t break functionality in the Windows or Xbox Versions.


I know how hard it is as a developer to stop yourself from jumping directly into the code, but there is a lot to keep in mind when building a game, especially when there are requirements set for User Experience in order to publish your game on a device.

My biggest piece of advice is to read the Application Certification Requirements for Windows Phone 7 before you even prototype your game, and yes, you will want to Prototype your game.

Shameless Self-Promotion

If you’re in the Toronto area please come out to see my talk on December 2nd in Mississauga or December 9th in Toronto. For more information please see the Canadian Developer Connection Blog Entry.

Download The Updated Alien Game Lab Solution