Click here to Skip to main content
15,860,972 members
Articles / Multimedia / DirectX
Article

SpaceWarrior - A 2D DirectDraw Game

Rate me:
Please Sign up or sign in to vote.
1.82/5 (17 votes)
21 Dec 2006CPOL3 min read 73.6K   2.8K   26   14
An article on a simple 2D space shooting game under DirectDraw.

SpaceWarrior screenshot

Introduction

Ever read/heard of the "Tricks of the Windows game programming gurus", a book by Andre Lamothe?

Well, having that book in my hands (or in my computer) allowed me to dive into the secrets and tricks of Windows game development. The author of this book decided to share his 20-year experience as a Windows game developer and a programmer.

In this book, he covers Windows GDI and DirectX (DirectDraw, DirectPlay, and DirectSound) fundamentals, and shows to the readers how to build fast and simple 2D game engines under DirectX.

Piece by piece, according to the book, I have built a DirectX wrapper library as a base part of a future full-featured 2D game engine.

Background

The background for my search for the ultimate game book I took some time ago can be found in the secret wish of any "real programmer" - we all want to build the game at last. And we want it to be good...

You will find a lot more information in the book regarding the following:

  • Win32 applications basics
  • COM and DirectX basics
  • Vector rasterization and 2D transformations
  • Force Feedback joysticks
  • Sounds and music
  • Algorithms, data structures, memory management, and multithreading
  • Computer AI basics
  • Physics basics

And this is just a part of the contents of the book! It covers a lot of ground, and it may take months to be understood, but still it must be used as a reminder of how something can be (and is being) done in the "world of game developers".

Using the code (if you can call it this way)

There are the DXEngine.h and DXEngine.cpp files that should be added to the Win32 project (not the MFC project). Also, the latest DirectX SDK does not support MS Visual Studio 6.0 any longer, so you must use the MS Visual Studio .NET environment.

Basically, it goes like this (but, don't laugh please):

DXEngine_Init();    // Loads DirectX modules

DXEngine_Render();    // Your game code

DXEngine_Deinit();    // Unloads DirectX modules

There is a number of DXEngine functions that you can use for:

  • Image loading (bitmaps)
  • Pixel drawing
  • Vector graphics drawing (lines, polygons)
  • Filling vector shapes (filled polygons)
  • Text drawing
  • 2D transformations (translation, rotation, scaling)

However, there is no sound support implemented yet! Why? I don't know... I didn't want it for now.

There is a lot of code you must write down yourself, but it is your game, right? Please, download the sample project and go through the source, it is the only way to understand the game development issue. I'm not kidding at all. There is no way to write an article that will teach you to be a game programmer.

And get the book as soon as possible (if you don't like my game), and write your own! It will be a good one for sure, I know.

Points of Interest

I have learned many interesting/fun/annoying things while I was writing the code, and I have seen clever/wild/zany things for the rest of my life. Kidding... I have just started to have fun!!!

Happy New Year, my friend...

History

In this release of the Space Warrior game I have added UFO enemies and another asteroid type.

License

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


Written By
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

 
GeneralMissing Variable Errors Pin
armage225-Apr-08 4:22
armage225-Apr-08 4:22 
Questionhow to use on vc++ 6 Pin
tedkidane29-May-07 5:08
tedkidane29-May-07 5:08 
QuestionRepair?? Pin
descartes25-Jan-07 7:58
descartes25-Jan-07 7:58 
AnswerRe: Repair?? Pin
darkoman25-Jan-07 20:24
darkoman25-Jan-07 20:24 
GeneralHangs & Crashes Pin
Polymorpher10-Jan-07 13:52
Polymorpher10-Jan-07 13:52 
GeneralRe: Hangs & Crashes Pin
darkoman10-Jan-07 20:14
darkoman10-Jan-07 20:14 
GeneralCode Dump Pin
Gokalp Peker19-Dec-06 4:04
Gokalp Peker19-Dec-06 4:04 
GeneralRe: Code Dump Pin
darkoman19-Dec-06 4:20
darkoman19-Dec-06 4:20 
GeneralRe: Code Dump Pin
Gokalp Peker19-Dec-06 19:52
Gokalp Peker19-Dec-06 19:52 
GeneralRe: Code Dump Pin
darkoman19-Dec-06 20:58
darkoman19-Dec-06 20:58 
GeneralRe: Code Dump Pin
Gokalp Peker19-Dec-06 21:10
Gokalp Peker19-Dec-06 21:10 
GeneralRe: Code Dump Pin
darkoman19-Dec-06 21:40
darkoman19-Dec-06 21:40 
GeneralRe: Code Dump Pin
Gokalp Peker19-Dec-06 22:40
Gokalp Peker19-Dec-06 22:40 
GeneralRe: Code Dump Pin
darkoman19-Dec-06 22:53
darkoman19-Dec-06 22:53 

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.