Click here to Skip to main content
Licence CPOL
First Posted 17 Jun 2008
Views 20,162
Downloads 475
Bookmarked 27 times

C# Space Invaders using WinForms Objects

By GCalcerano | 17 Jun 2008
Create the famous game using only labels, panels and pictures

1
1 vote, 8.3%
2
1 vote, 8.3%
3
5 votes, 41.7%
4
5 votes, 41.7%
5
4.53/5 - 12 votes
1 removed
μ 4.08, σa 1.72 [?]

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).

ScreenShot

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).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

GCalcerano



Italy Italy

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberMr.Desolator3:14 12 Sep '11  
GeneralYay (and bug) PinadminChris Maunder5:19 17 Jun '08  
GeneralRe: Yay (and bug) PinmemberJubjub10:34 17 Jun '08  
GeneralRe: Yay (and bug) PinmemberGCalcerano21:26 17 Jun '08  
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.
GeneralRe: Yay (and bug) PinmemberRich Leyshon5:22 24 Jun '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 17 Jun 2008
Article Copyright 2008 by GCalcerano
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid