Click here to Skip to main content
15,867,594 members
Articles / Multimedia / DirectX
Article

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 378.5K   7.6K   76   86
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 http://www.microsoft.com/directx.

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!

Updates

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

License

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


Written By
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: http://www.dotnetmaniacs.com.br

In his spare time he studys korean language...

Comments and Discussions

 
General2 Errors buggin the hell outta me! Pin
DeSiPiMp15-Mar-03 5:47
DeSiPiMp15-Mar-03 5:47 
GeneralRe: 2 Errors buggin the hell outta me! Pin
Mauricio Ritter17-Mar-03 4:31
Mauricio Ritter17-Mar-03 4:31 
GeneralGraphics Pin
Mario Bros.23-Feb-03 2:33
Mario Bros.23-Feb-03 2:33 
GeneralRe: Graphics Pin
Mauricio Ritter23-Feb-03 8:06
Mauricio Ritter23-Feb-03 8:06 
GeneralDirectDrawPalette Pin
mehendru13-Dec-02 0:39
mehendru13-Dec-02 0:39 
General109 ERRORS! Pin
DeSiPiMp11-Dec-02 7:16
DeSiPiMp11-Dec-02 7:16 
GeneralRe: 109 ERRORS! Pin
DeSiPiMp11-Dec-02 8:33
DeSiPiMp11-Dec-02 8:33 
GeneralRe: 109 ERRORS! Pin
Mauricio Ritter12-Dec-02 3:31
Mauricio Ritter12-Dec-02 3:31 
GeneralRe: 109 ERRORS! Pin
DeSiPiMp12-Dec-02 7:25
DeSiPiMp12-Dec-02 7:25 
GeneralRe: 109 ERRORS! Pin
Mauricio Ritter12-Dec-02 7:47
Mauricio Ritter12-Dec-02 7:47 
QuestionCould you also post the old version? Pin
Anonymous13-Nov-02 3:11
Anonymous13-Nov-02 3:11 
AnswerRe: Could you also post the old version? Pin
Mauricio Ritter13-Nov-02 3:34
Mauricio Ritter13-Nov-02 3:34 
GeneralVery Damn Cool Pin
Brian Delahunty1-Sep-02 7:27
Brian Delahunty1-Sep-02 7:27 
GeneralRequest Pin
Rama Krishna Vavilala9-Jun-02 9:47
Rama Krishna Vavilala9-Jun-02 9:47 
GeneralRe: Request Pin
Mauricio Ritter9-Jun-02 14:12
Mauricio Ritter9-Jun-02 14:12 
GeneralRe: Request Pin
Brian Delahunty1-Sep-02 7:28
Brian Delahunty1-Sep-02 7:28 
GeneralMy Space Invaders Pin
6-Jun-02 16:27
suss6-Jun-02 16:27 
GeneralRe: My Space Invaders Pin
Nnamdi Onyeyiri7-Jun-02 0:26
Nnamdi Onyeyiri7-Jun-02 0:26 
GeneralRe: My Space Invaders Pin
Member 6776345-Nov-03 6:07
Member 6776345-Nov-03 6:07 
GeneralRe: My Space Invaders Pin
Paulo4911-Nov-03 7:16
Paulo4911-Nov-03 7:16 
GeneralRe: My Space Invaders Pin
Yoshua8-Feb-04 20:27
Yoshua8-Feb-04 20:27 
GeneralCompile errors under DirectX 8.1... Pin
Mike Janzen5-Jun-02 8:31
Mike Janzen5-Jun-02 8:31 
GeneralRe: Compile errors under DirectX 8.1... Pin
Mauricio Ritter5-Jun-02 13:06
Mauricio Ritter5-Jun-02 13:06 
GeneralRe: Compile errors under DirectX 8.1... Pin
7-Jun-02 13:30
suss7-Jun-02 13:30 
GeneralRe: Compile errors under DirectX 8.1... Pin
Mauricio Ritter8-Jun-02 4:13
Mauricio Ritter8-Jun-02 4:13 

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.