Windows Phone 7 Platformer Starter Kit for XNA Studio 4.0 April Refresh

In this previous article, I’ve shown you how to migrate the code of the Indiana Jones like platformer game from XNA 3.1 to XNA 4.0 for Windows Phone 7.

In the meantime, the SDK has been updated to a version named “April Refresh”. You’ll then find the final project updated for this new intermediate version at the end of this post.

However, in this current build, we’ve lost temporally the keyboard usage from the host machine within the Windows Phone emulator when you’re inside an XNA application (this does work however inside a Silverlight application). Well, this is a bit embarrassing as my game becomes… completely useless. ;-)

Still, between 2 customers’ visits, I’ve found amusing to take it as a chance to test one of the available solution on the web to simulate an accelerometer. I’ve then decided to use this one: https://www.robmiles.com/windowsphonefaq/2010/4/1/how-do-i-use-the-accelerometer-in-the-windows-phone-emulator.html

The goal is to build a mini HTTP server sending back the current state of an Xbox 360 gamepad. This mini-server will be consumed by the Windows Phone application through the WebClient object of Silverlight. We’ll then be into an experimental phase but this could be useful as a first mean to debug. Please note also that this is introducing an important concept: we can do HTTP calls from an XNA application thanks to the System.Net library of Silverlight. This is then a good example of how both frameworks could interact together in a smart way.

You’ll find the mini-HTTP server source code in the ZIP archive file available of the end of this post with the source code of the platformer updated for this refresh. You will then have to compile the “GamePadHostServer” project et launch it as an “Administrator” to make it works. You’ll need also a Xbox 360 gamepad connected to your PC hosting this mini-server. You’ll have this kind of output:

GamePadHostServer

You’ll then be able to verify that your gamepad is properly configured and that the values retrieved that will be pushed through HTTP to the emulator are consistent.

Finally, open the “WindowsPhonePlatformer” project and locate the “PlatformerGame.cs” file to change the following line of code:

 static string url = https://davrous8go:8080;

With the Netbios name of your hosting machine. Launch the game and you should then be able to play the game with the Xbox 360 gamepad. However, even if the game magically becomes less useless…. it now becomes totally unplayable! :-) This is linked to the fact that there is a micro delay between the moment where the XNA application asks for the state inside the update() method and when it receives it from the HTTP server via the async callback handled by Silverlight. But well… This is definitely funny.

In summary, we have the following “architecture” in place:

ArchiXNAGPAcceleroWP7

And here is the final solution to download if you’d like to test it on your own machine:

Have fun with XNA !

David