It's been about a thousands years (well many seconds at least...) since our last XNA post, it's been ages since we've had a game (well since a few posts ago) and a good while since we've done Windows Phone 7... well... um... err.... um... okay, okay... fine.
Still I thought this was a cool XNA game for the Windows Phone that talked about something I've not seen covered much, the conversion from a much older Windows version using Managed DirectX to Windows Phone 7 and XNA. Also I liked how this project showed off the "standing on shoulders of giants" concept with how it leveraged some other open source code snips.
And who doesn't want to play an Invasion game on your Windows Phone 7.x where you have all the source?
Invasion is a UFO-shooter game, originally designed by Mauricio Ritter. This article describes my port of the Invasion game for Windows (in C# and Managed-DirectX) to Windows Phone 7 (C# and XNA 4.0). The full source code is provided.
Back in 2002, Mauricio Ritter posted his "Invasion" UFO-shooter 2D game on CodeProject. It was written in C++ and used the DirectDraw APIs in DirectX 7 that Microsoft removed in DirectX 8. The following year, Steve Maier ported the game to C# with Managed DirectX and also posted it here on CodeProject. Managed DirectX went away after 2005 and was replaced by XNA. Both of those legacy versions ran on Windows XP. This article describes my 2011 week-long port of Steve's Managed DirectX version to Windows Phone 7 using XNA 4.0.
I had some goals for porting this game beyond "just get it working on Windows Phone 7". Specifically, they were:
- Redesign the code into more manageable classes
- Make the code more readable so that beginners could understand it
- Simplify the code by using more C# language features and XNA framework classes
- Polish the game so that I could release it on the Windows Phone Marketplace
- Keep it free and Open-Source
- But still finish the port within a week!
Considering my timeframe (which I extended by a few days), I was only somewhat successful. I submitted v1.0 to the Marketplace today and consider it a "work-in-progress".
I had mentioned other open source projects?
Borrowed Open Source Code
There were some features that I wanted to add to the game and fortunately had some already-made code files that made adding them quick and easy. You can find these files in the
Systemprojects. Don't let the namespace fool you though, this code is free Open-Source and my company (ImproviSoft) didn't write much of it. The files contain comments with their source indicated - primarily Microsoft's XNA team, XNAWiki.com, and Elbert Perez of OccasionalGamer.com. So thank them for it! Here's a list of those files:
- FrameRateCounter.cs - displays the frames/second onscreen for debugging purposes, from Shawn Hargreaves (Microsoft XNA team).
- SimpleShapes.cs - class for drawing 2D primitives (e.g., a
Rectangle), from XNAWiki.com (although probably named something else there).
- Accelerometer.cs - class for handling accelerometer input, from create.msdn.com (Microsoft XNA team).
- Camera2D.cs - class for handling a 2D camera (to make the screen shake!), from Elbert Perez of OccasionalGamer.com - thanks, Elbert!
- InputState.cs - class for handling all sorts of input devices, including the touch-screen, from create.msdn.com (Microsoft XNA team).
- MusicManager.cs - class for playing background music, from create.msdn.com (Microsoft XNA team).
- RandomManager.cs - simple class for generating random numbers - OK, I possibly wrote this and it took just two minutes.
- SoundManager.cs - simple class to wrap
SoundEffect.Playcalls for sounds with adjusted maximum-volume.
- VibrationManager.cs - class for making the phone vibrate on command (for force-feedback effect), from create.msdn.com (Microsoft XNA team).
Here's a snap of the Solution;
And finally a snap of it running in the emulator...