Click here to Skip to main content
15,399,373 members
Articles / Multimedia / DirectX
Posted 5 Jan 2002


76 bookmarked

Invasion - A computer game using DirectDraw

Rate me:
Please Sign up or sign in to vote.
4.92/5 (30 votes)
4 Jun 20022 min read
This "Space Invaders"-like game was originally writen in DirectX 6, but I've changed some things so that you can use it with the latest version of the DirecX SDK. It uses just the Windows API and DirectX library (no MFC here). Have fun!

Sample Image - Invasion1.jpg Sample Image - Invasion2.jpg

This was my first attempt writing a computer game using the DirectX library. It was originally written for DirectX 6 library, but I've made some changes that made it work with the latest SDK. The code is based on the Windows API, without any reference to the MFC library. The only thing you need to compile this is VC++ and DirectX SDK, which can be found at

All the processing is done when no messages are available in the application message queue, by calling the UpdateFrame() function. As you see in the code, I haven't used many classes, and almost all the code is based on function calls. The only classes that are available are:

Alpha: this class is used as a reference to draw characters to the screen. This allow us to use a bitmap to draw the letters to the screen (so that the user doesn't need to install extra fonts in the system).

Extra: Defines an "Extra" element in the screen, that can be an Ammo box, an Bonus Box, a Weapon Advance Box or a Shield Charge.

Ovni: This class represents the UFOs that are going to be shot! Just to explain the name of the class... Ovni means UFO in Portuguese. Since I'm a Brazilian and a Portuguese speaker, there are some things in the code that are with my local language (don't worry, the comments are all English :o) )

Bullet: This represents the bullets that fly around the galactic battlefield.

Each one of the classes has a 'built-in' linked list that will be used a lot in the code. Each one of the classes have a common Draw function the is used to draw the specific object on the screen in its current state.

Almost everything in the code is commented, but if you have any trouble just mail me.

Have fun!


4 June 2002: I´ve removed a memory leak (directdraw interface was not being released) and have improved the surface creation function (winmain.cpp, line 3190). Now I try to create every surface on VIDEOMEMORY. If the function returns a DDERR_OUTOFMEMORY, I try to recreate it on SYSTEMMEMORY (winmain.cpp, line 3242).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mauricio Ritter
Web Developer
Brazil Brazil
Mauricio Ritter lives in Brazil, in the city of Porto Alegre. He is working with software development for about 8 years, and most of his work was done at a bank, within a home and office banking system.
Mauricio also holds MCSD, MCSE, MCDBA, MCAD and MCT Microsoft certifications and work as a trainer/consultant in some MS CTEC in his city.
Mauricio also works in his own programming site, aimed to Brazilian Developers:

In his spare time he studys korean language...

Comments and Discussions

QuestionNeed permission to use game resources for my university project.. Of course credit would be provided in the game's GPL license. Pin
VICKYIORI17-Jan-15 17:18
MemberVICKYIORI17-Jan-15 17:18 
QuestionInvasion in XNA for Windows Phone 7 Pin
Dan Colasanti30-Jun-11 20:37
professionalDan Colasanti30-Jun-11 20:37 
General3 Errors Pin
langmain6748917-Feb-07 5:45
Memberlangmain6748917-Feb-07 5:45 
GeneralRe: 3 Errors Pin
Mauricio Ritter19-Feb-07 23:40
MemberMauricio Ritter19-Feb-07 23:40 
GeneralVery helpful! Pin
THE SENSE5-Jan-07 19:26
MemberTHE SENSE5-Jan-07 19:26 
GeneralChanging Resolution Pin
Chrisian_leva3-Dec-05 15:51
MemberChrisian_leva3-Dec-05 15:51 
GeneralRe: Changing Resolution Pin
Steve Maier24-Apr-06 5:52
professionalSteve Maier24-Apr-06 5:52 
Questioncan you explain every method? Pin
winile884812-Nov-05 14:58
Memberwinile884812-Nov-05 14:58 
QuestionHow did you make your image tile sheet. Pin
Gerald McKoy12-Aug-05 8:05
MemberGerald McKoy12-Aug-05 8:05 
Generalhelp diving into the code Pin
sergio_juma_nehama9-Dec-04 0:45
Membersergio_juma_nehama9-Dec-04 0:45 
GeneralHi Mauricio Pin
pushkar_007-May-04 21:28
Memberpushkar_007-May-04 21:28 
GeneralRe: Hi Mauricio Pin
Mauricio Ritter8-May-04 10:33
MemberMauricio Ritter8-May-04 10:33 
GeneralGREAT GAME!! Pin
Ryan McDermott18-Mar-04 7:21
MemberRyan McDermott18-Mar-04 7:21 
General2 Errors buggin the hell outta me! Pin
DeSiPiMp15-Mar-03 5:47
MemberDeSiPiMp15-Mar-03 5:47 
GeneralRe: 2 Errors buggin the hell outta me! Pin
Mauricio Ritter17-Mar-03 4:31
MemberMauricio Ritter17-Mar-03 4:31 
GeneralGraphics Pin
Mario Bros.23-Feb-03 2:33
MemberMario Bros.23-Feb-03 2:33 
GeneralRe: Graphics Pin
Mauricio Ritter23-Feb-03 8:06
MemberMauricio Ritter23-Feb-03 8:06 
GeneralDirectDrawPalette Pin
mehendru13-Dec-02 0:39
Membermehendru13-Dec-02 0:39 
General109 ERRORS! Pin
DeSiPiMp11-Dec-02 7:16
MemberDeSiPiMp11-Dec-02 7:16 
GeneralRe: 109 ERRORS! Pin
DeSiPiMp11-Dec-02 8:33
MemberDeSiPiMp11-Dec-02 8:33 
GeneralRe: 109 ERRORS! Pin
Mauricio Ritter12-Dec-02 3:31
MemberMauricio Ritter12-Dec-02 3:31 
GeneralRe: 109 ERRORS! Pin
DeSiPiMp12-Dec-02 7:25
MemberDeSiPiMp12-Dec-02 7:25 
GeneralRe: 109 ERRORS! Pin
Mauricio Ritter12-Dec-02 7:47
MemberMauricio Ritter12-Dec-02 7:47 
QuestionCould you also post the old version? Pin
Anonymous13-Nov-02 3:11
MemberAnonymous13-Nov-02 3:11 
AnswerRe: Could you also post the old version? Pin
Mauricio Ritter13-Nov-02 3:34
MemberMauricio Ritter13-Nov-02 3:34 

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

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