Space Defender : A Complete XNA Game by Ghoshehsoft
Update: Game updated to XNA GS4.0 , Download links added!
This was my first XNA game! It’s a cool 2D Game..
Unlike most space games, this game takes place in the atmosphere! not in the outer space 🙂
You have to defeat the invaders as they increase in number, you’ll also come across mother ships which are more advanced enemies that will chase you and fire energy pulses at you!. Play for some time and you’ll confront the Main Mother Ship…you think you’re up to it???
You have two weapons to stop your enemies : a rail gun that will fire small rapid bullets , and a missile launcher that fires missiles causing massive damage to your enemies!
The player can choose one of three Space Ships to play the game with… each space ship has it’s special ability : Rapid Fire, Turbo Ship, Heavy Armor…and if the player beats the game twice with two different ships, The ultimate ship will be unlocked!
You can play the game with your mouse ( I like to sit back and destroy the invaders just with my mouse 😀 ) OR with your keyboard
Instructions on how to play the game can be found under the How To Play window in the game.
Taking the repairs box is always a good idea!! a small white repairs box will show up from time to time! take it to regain health.
You can control the speed of your ship in the game, See How To Play for more instructions
Enough Talk! Let’s Play!
Full source code link at the bottom of the article
If you don’t have the XNA 3.1 SDK installed on your computer, you’ll have to install the XNA Redistributable 3.1, download it here for free.
If you like the game please let me know! my email is email@example.com
Some images of the game:
For XNA Developers:
Let’s talk a little about the game code & structure…
I programmed this game using XNA Game Studio 3.1 & C# 2008
Game Dialogs : since I couldn’t find XNA compatible classes to use for dialog boxes, I had to write my own, so I started with programming the Button class which almost simulates a Windows button.
Next comes the Label class , its main function is to display text after specifying the font,position… and it allows text wrapping which means you can specify the number of characters per line so your text might be displayed in more than one line…
There’s also the Animation class which is a picture box that displays an animation that can be used as a button! it’s a simple one though…
I used the former three classes to build some special dialog boxes..
I should have used Events to best manipulate the controls classes but I didn’t know much about Events handling back then 😦
The main classes of the game are:
Sprite : which is an abstract class which all the ships,invaders inherit from , it’s a very common class..
Explosion : an explosion with properties such as radius,damage,duration,visible
Explosion Manager : This class the the only thing responsible for damaging ships/invaders… when a missile hits a ship it doesn’t damage it directly, it asks the explosion manager to create an explosion in the location of the impact , then each object in the game checks the explosion manager for near explosions to get damage from! even bullets/ships colliding with each other creates explosions…. writing this explosion manager has really made things easier for me! 🙂
Cloud : a simple class that represents a cloud with a size,speed and a position… the cloud will move automatically each time its Update method is called
Cloud Manager : a class the manipulates several clouds to give the effect of the cloudy sky, It creates clouds with random positions,sizes and speeds. I created two instances of this class, one is drawn behind the scene, the other is in front of it! which adds a really cool effect to the sky!
Enemy Manager : This class manipulates the enemies, it’s the one that spawns enemies of different types and updates,draws them. you can think of this class as a game level… the game is now a one level game but with some modifications this class can read a level from a file and send enemies according to the level
accurate collision detection is not much needed in this game so many ships has circles as their collision bounds others have a rectangle for collision
I used XACT 3 it’s a really cool tool 🙂
sprite sheets : found them on the internet…I don’t really remember where!
sounds : various sources and small games
backgrounds : Google Images 🙂
The game will automatically switch to full screen mode
Here you’ll find the full source code : a Visual Studio 2008 Solution, Have fun!
The code is well commented 🙂
You’re free to copy/modify any part of the code as long as you don’t claim the game for your self 🙂
Please note : source code was updated, if at compile time you receive an error saying “Unable to find manifest signing certificate in the certificate store” then please re-download the code or do the following : Project->Space Defender Properties->Signing->Create Test Certificate
Enter any password and the project should compile correctly!
Comments Are Always Welcome 🙂