Click here to Skip to main content
11,933,905 members (57,593 online)
Click here to Skip to main content
Add your own
alternative version


76 bookmarked

Invasion - A computer game using DirectDraw

, 4 Jun 2002
Rate this:
Please Sign up or sign in to vote.
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!
<!-- Download Links --> <!-- Article image -->

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

<!-- Add the rest of your HTML here -->

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 Blush | :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...

You may also be interested in...

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 18:18
memberVICKYIORI17-Jan-15 18:18 
QuestionInvasion in XNA for Windows Phone 7 Pin
Dan Colasanti30-Jun-11 21:37
memberDan Colasanti30-Jun-11 21:37 
General3 Errors Pin
langmain6748917-Feb-07 6:45
memberlangmain6748917-Feb-07 6:45 
GeneralRe: 3 Errors Pin
Mauricio Ritter20-Feb-07 0:40
memberMauricio Ritter20-Feb-07 0:40 
GeneralVery helpful! Pin
THE SENSE5-Jan-07 20:26
memberTHE SENSE5-Jan-07 20:26 
GeneralChanging Resolution Pin
Chrisian_leva3-Dec-05 16:51
memberChrisian_leva3-Dec-05 16:51 
GeneralRe: Changing Resolution Pin
Steve Maier24-Apr-06 6:52
memberSteve Maier24-Apr-06 6:52 
Questioncan you explain every method? Pin
winile884812-Nov-05 15:58
memberwinile884812-Nov-05 15:58 
QuestionHow did you make your image tile sheet. Pin
Gerald McKoy12-Aug-05 9:05
memberGerald McKoy12-Aug-05 9:05 
Generalhelp diving into the code Pin
sergio_juma_nehama9-Dec-04 1:45
membersergio_juma_nehama9-Dec-04 1:45 
GeneralHi Mauricio Pin
pushkar_007-May-04 22:28
memberpushkar_007-May-04 22:28 
GeneralRe: Hi Mauricio Pin
Mauricio Ritter8-May-04 11:33
memberMauricio Ritter8-May-04 11:33 
GeneralGREAT GAME!! Pin
Ryan McDermott18-Mar-04 8:21
memberRyan McDermott18-Mar-04 8:21 
General2 Errors buggin the hell outta me! Pin
DeSiPiMp15-Mar-03 6:47
memberDeSiPiMp15-Mar-03 6:47 
GeneralRe: 2 Errors buggin the hell outta me! Pin
Mauricio Ritter17-Mar-03 5:31
memberMauricio Ritter17-Mar-03 5:31 
GeneralGraphics Pin
Mario Bros.23-Feb-03 3:33
memberMario Bros.23-Feb-03 3:33 
GeneralRe: Graphics Pin
Mauricio Ritter23-Feb-03 9:06
memberMauricio Ritter23-Feb-03 9:06 
GeneralDirectDrawPalette Pin
mehendru13-Dec-02 1:39
membermehendru13-Dec-02 1:39 
General109 ERRORS! Pin
DeSiPiMp11-Dec-02 8:16
memberDeSiPiMp11-Dec-02 8:16 
GeneralRe: 109 ERRORS! Pin
DeSiPiMp11-Dec-02 9:33
memberDeSiPiMp11-Dec-02 9:33 
oh i read the other thread.. i got it.. but i'm still gettin 2 more errors.. I don't know whats up with these errors:

Winmain.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw7
Debug/Invasion2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Invasion2.exe - 2 error(s), 0 warning(s)

Can somebody explain what's wrong with this?
GeneralRe: 109 ERRORS! Pin
Mauricio Ritter12-Dec-02 4:31
memberMauricio Ritter12-Dec-02 4:31 
GeneralRe: 109 ERRORS! Pin
DeSiPiMp12-Dec-02 8:25
memberDeSiPiMp12-Dec-02 8:25 
GeneralRe: 109 ERRORS! Pin
Mauricio Ritter12-Dec-02 8:47
memberMauricio Ritter12-Dec-02 8:47 
QuestionCould you also post the old version? Pin
Anonymous13-Nov-02 4:11
sussAnonymous13-Nov-02 4:11 
AnswerRe: Could you also post the old version? Pin
Mauricio Ritter13-Nov-02 4:34
memberMauricio Ritter13-Nov-02 4:34 
GeneralVery Damn Cool Pin
Brian Delahunty1-Sep-02 8:27
editorBrian Delahunty1-Sep-02 8:27 
GeneralRequest Pin
Rama Krishna9-Jun-02 10:47
memberRama Krishna9-Jun-02 10:47 
GeneralRe: Request Pin
Mauricio Ritter9-Jun-02 15:12
memberMauricio Ritter9-Jun-02 15:12 
GeneralRe: Request Pin
Brian Delahunty1-Sep-02 8:28
editorBrian Delahunty1-Sep-02 8:28 
GeneralMy Space Invaders Pin
Anonymous6-Jun-02 17:27
memberAnonymous6-Jun-02 17:27 
GeneralRe: My Space Invaders Pin
The Eclypse7-Jun-02 1:26
memberThe Eclypse7-Jun-02 1:26 
GeneralRe: My Space Invaders Pin
Cardinal Darek5-Nov-03 7:07
memberCardinal Darek5-Nov-03 7:07 
GeneralRe: My Space Invaders Pin
Paulo4911-Nov-03 8:16
memberPaulo4911-Nov-03 8:16 
GeneralRe: My Space Invaders Pin
Yoshua8-Feb-04 21:27
memberYoshua8-Feb-04 21:27 
GeneralCompile errors under DirectX 8.1... Pin
Mike Janzen5-Jun-02 9:31
memberMike Janzen5-Jun-02 9:31 
GeneralRe: Compile errors under DirectX 8.1... Pin
Mauricio Ritter5-Jun-02 14:06
memberMauricio Ritter5-Jun-02 14:06 
GeneralRe: Compile errors under DirectX 8.1... Pin
Anonymous7-Jun-02 14:30
memberAnonymous7-Jun-02 14:30 
GeneralRe: Compile errors under DirectX 8.1... Pin
Mauricio Ritter8-Jun-02 5:13
memberMauricio Ritter8-Jun-02 5:13 
GeneralRe: Compile errors under DirectX 8.1... Pin
Cardinal Darek9-Nov-03 22:50
memberCardinal Darek9-Nov-03 22:50 
GeneralI wish more people put full games on here.. Pin
LiquidKnight9-Mar-02 17:05
memberLiquidKnight9-Mar-02 17:05 
GeneralRe: I wish more people put full games on here.. Pin
Nish [BusterBoy]9-Mar-02 18:40
memberNish [BusterBoy]9-Mar-02 18:40 
GeneralRe: I wish more people put full games on here.. Pin
Mauricio Ritter11-Mar-02 0:34
memberMauricio Ritter11-Mar-02 0:34 
GeneralRe: I wish more people put full games on here.. Pin
Mauricio Ritter11-Mar-02 0:32
memberMauricio Ritter11-Mar-02 0:32 
GeneralI was wondering.. Pin
LiquidKnight26-Mar-02 12:01
memberLiquidKnight26-Mar-02 12:01 
GeneralRe: I was wondering.. Pin
Mauricio Ritter26-Mar-02 17:01
memberMauricio Ritter26-Mar-02 17:01 
GeneralRe: I was wondering.. Pin
Selevercin25-May-02 18:16
memberSelevercin25-May-02 18:16 
GeneralRe: I was wondering.. Pin
Mauricio Ritter26-May-02 2:52
memberMauricio Ritter26-May-02 2:52 
GeneralRe: I was wondering.. Pin
Selevercin1-Jun-02 13:23
memberSelevercin1-Jun-02 13:23 
GeneralRe: I wish more people put full games on here.. Pin
Anonymous1-Sep-02 8:42
sussAnonymous1-Sep-02 8:42 
GeneralMore Fun with Invasion Pin
Matt Philmon21-Feb-02 4:34
memberMatt Philmon21-Feb-02 4: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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 5 Jun 2002
Article Copyright 2002 by Mauricio Ritter
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid