Introduction
Space Invaders is one of the most famous arcades in the world, and many of us programmers developed our own version of this game in our favourite programming language. I decided to create a version using only WinForms objects, maintaining as many features as possible (primarily, the graphics).
Background
At first, you must know that every label object has got its image property, which can be used as background for a text. Of course, if you set text to empty string, you see nothing but the image itself! So, I decided to use labels for player ship, for aliens and for bullets. For aliens movement, I placed all of them in a panel, so that I can shift the entire armada only by setting the top and left property of the panel. To be right, there are two panels and two armadas, which are shown alternately to change aliens' legs positions.
Using the Code
There is a class for each of the main actors of the game: bullets, invaders and ship. In the main form, a timer is used for checking the keyboard, and another timer for moving the actors. To handle keyboard input smoothly, I didn't use the KeyPress event, but I used GetAsyncKeyState from DDL user32; in this way, there is no delay between the first and second hit of the key.
Note: Use the left and right arrow keys for moving the ship, and space key for shooting.
History
- 17th June, 2008: This is version 0.5. No sound is included. Moreover, invaders' ship (the one passing in the upper side of the screen) is missing. A known bug is that aliens don't bite the bunkers (that means that when the aliens reach the bunkers's position, the aliens pass behind the bunkers).
| You must Sign In to use this message board. |
|
|
 |
|
 |
1. The top right hand ship cannot be shot 2. When I shot all ships except for this last one, and the last one reached one row above the shields, my ship exploded and the game locked
Things I'd like to see:
1. An explanation of the game logic 2. An explanation of how you handle keyboard input smoothly 3. Sounds and the mother ship!
cheers, Chris Maunder CodeProject.com : C++ MVP
|
| Sign In·View Thread·PermaLink | 4.33/5 |
|
|
|
 |
|
 |
I found a similar thing, except once the ships got down to some certain level, I couldn't shoot any of the lowest, or 2nd lowest ships.
I also found that the lowest ships just go straight the barriers. - i missed this bit in your article 
Nicely done though. I'm thinking about trying to see if I can get it working on a smartphone.
"If you're too careful, your whole life can become a f---in' grind." - Mike McD ( Rounders)
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
You are right. I'm managing to solve the bug, which is due to an error in the evaluation of the height of the invaders armada. The ship explodes because the program thinks you have been invaded. I didn't experience the other bug: I'm able to kill all the aliens, without problem. Can you please explain me when does it occur? I would be very happy if this program could be translated to run on cellular phones: please let me know how this translation proceed.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
I did something very similar (using VB!) a while back. Then I changed it so that each alien (and the shields) were drawn individually - resulted in nicer graphics. If you do add sounds, and aren't using something like Direct Sound, then you will get a problem trying to add the master ship sound over the top of the aliens marching/gun shooting sound. You can get around this in XP but may experience problems with Vista due to the changes in the audio.
Finally, if I maximise the screen, the alien missiles go all the way to the bottom (way below the shields) and the invaders continue all the way to the right of the screen - way past the shields!
You can see my (VB) version at
although I think this version has only has one screen of action.
Rich
Edit - having problems getting my url to appear for some reason so I'll type it manually and you can do a cut and paste
[^]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|