Tank Game in Silverlight 2
- posted in:
- Silverlight
I've had a little bit of time to dig deeper into Silverlight 2. Instead of making a RIA that may contain useful information for all, I decided to make a mini tank game! Now this tank game is not intended to be a best hit or anything like that. It is intended as a simple example of how to make a mini game that users can play while waiting for something to load or process in the background. I do hope to expand its features in the future, especially if there is interest which will turn this little mini game into a full blown game that users can play anytime. I have attached the source code so feel free to download it and expand as you wish!
Before I describe this mini tank game, I got my inspiration from Andy Beaulieu and his great game work. Andy demonstrates some excellent best-practices for making simple games in general, but also specifics related to Silverlight. The other inspiration that pushed me into making this game was my love of video games. I've been a gamer all my life and have always wanted to make an actual game. I made a few in the past in different technologies that have been extremely simple, but school always came in the way. Now that I have some time, even just a little bit of time, I have been able to whip up a quick silverlight game.
There is no real object to this game, not yet at least. Currently, the user can create 1 or more tanks and move them around the available area. There is a surrounding boundary and some obstacles in the game that the user will 'bounce' off of if they collide. They can shoot at each other and when their life reaches 0 they die. That's the basic concept. Like I said before, a simple game. This mini tank game has the following features:
- Set your tanks color (TankColor property)
- Can be any brush so one could make a cool gradient brush in Blend and apply that to their tank
- Set your tanks name (TankName property)
- Set your tanks maximum life (MaximumHealth property)
- Set the number of bullets that your tank can spew out in a row (NumberOfBullets property)
- Set how fast you want your tank to turn (AngleSpeed property)
- Set your tanks X and Y position (TankOffsetX and TankOffsetY properties)
- Set your tanks controls to any key on your keyboard (ForwardKey, BackwardKey, LeftKey, RightKey an FireKey properties)
- Forward
- Backward
- Turn Left
- Turn Right
- Fire Bullet
- To set a user's controls to something, enter the string version of the key (ex. 'ctrl' will be the control key)
- Create your own levels by adding / deleting/ moving the green solidblock objects (SolidBlock object)
- Currently available through XAML or Blend
- Can set the width, height and color of the solid block
- Currently available through XAML or Blend
- Multiplayer support by having multiple tanks mapped to different keys on 1 computer
- No internet multiplayer support yet
All the properties that have been described above, denoted by surrounding () can be set in straight XAML syntax or in Blend.
Default Tank Values:
Name: New Tank
Number of Bullets: 1
Maximum Health: 100
Angle Speed: 2
X Position: 10
Y Position: 10
Color: Light Gray
Default Keyboard Values:
Forward: Up arrow
Backward: Down arrow
Turn Left: Left arrow
Turn Right: Right arrow
Fire: Space Bar
Known Bugs:
There have been a couple of bugs in this release that are minor, but worth noting.
The first one is that sometimes when the user holds down 3 or more keys, the last key will not be reflected in the game. This only applies to certain keys and I am not sure why this is the case at the current moment.
If the user is holding down a key and then presses one of the buttons on the bottom of the screen ('Add / Edit Tank' or 'Set Player Controls') then the tank will continue to do the last key action.
Sometimes the collision physics get out of whack and the tank will be sucked into a solid block object. The user can try to wiggle their way out or wait for an enemy to settle the matter for them. The user could also edit the tanks X and Y position to get out of the bind.
One last bug, which is a silverlight bug and has been discussed in further detail here is that setting the visibility on a parent control does not allow that property to propagate to its children correctly. Sure, the elements are not visible, but they retain their physical space so if the user clicks on that space those children grab the focus instead of the intended control.
TODO Features:
There are some things that I would like to gradually improve and some of those things can not be done until Silverlight matures more. Here is my list of features that I would like to accomplish, are there any that you would like to see?
- User clickable way to set position of tank
- Gradient color options for tank color
- level maker
- Saving ability on server for tanks / levels
- Reset the tank when it is destroyed
- Power-ups
- More weapons and the ability for the user to 'make' their own weapons
- Animations
- Explosion when tank is destroyed
- Red 'X' to grow / shrink
- When tank is hit, flash current health and change its color
- When new tank is created, animate it to appear and animate its statistics
- Template listboxItems when a player is in a certain state (alive / dead / spectator)
- Fix the wrappanel to wrap in a scrollviewer control
- New overall layout
Controls:
I have used a couple controls in my application that I want to give credit towards. First is the Color Picker by Page Brooks. Great little utility to customize he color of your tank. The second is the WrapPanel control for silverlight 2 by lneir. Not sure why MS didn't give Silverlight this control, but it's a great control that I use to wrap the statistics of the tanks.
Hope you enjoy the game!
Update:be sure to check out my popfly game, Battle Tank that is a mock up of this game written from scratch in only a couple of hours!
file | file size |
---|---|
Silverlight 2 Tank Game.zip | 717.13 KB |