Click here to Skip to main content
13,598,868 members
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 3 Jan 2007
Licenced CPOL

SpaceWarrior - 2D DirectDraw Game - Part II

, 3 Jan 2007
Rate this:
Please Sign up or sign in to vote.
An article on creating a simple 2D DirectDraw game (the game elements).


In the first part of this short game programming tutorial, you have seen how to create the main game window. Now, since we have a game scene, we need a game story, and game actors placed on that scene.

The Story

As we have agreed in the first part, we are going to create a simple 2D scrolling game (the space shooter game), learning that way the things that make up the game. So, the game story will be simple: you will pilot with the starship vessel through the asteroid field and fight against the enemy UFOs which will attack you during the game play. Now, let's see how to build these game elements.

The Player

I have decided to use some 3D modeling software in order to create the player starship and its animation. After some hard work, here is what came out (I am not a modeling expert as you can see):

The Player - Screenshot

Since this is a scrolling shooter, the player will move to left, right, up, or down, or in some combination of these four movements. But, I have created animation just for going left and right. So, what does this image represent at all? It is called tile set image of the game character. In the game, it will be known as a "sprite". If differs from a static image because it has more images that make up an animation when played one by one on the screen. The more the number of images, the smoother the animation will be, but it will take more system memory to hold it.

The Asteroid

I have also modeled the asteroid and came up with the following tile sets:

The Asteroid - Screenshot The Asteroid - Screenshot

The asteroid has a "rotating" animation, and is free to fly to any direction, but in this case, I have decided to make it fall from the top of the screen to the bottom. If it hits the starship enough times, it will destroy it. Also, if the star ship fires a plasma towards the asteroid and hits it, it will be destroyed. So, we need the explosion animation for this.

The Explosion

I found the free "explosion.gif", an animated explosion GIF image, on the Internet, and took out the frames, and got the following:

The Explosion - Screenshot

The explosion will occur in the case the starship hits the asteroid (and destroys it) or vice-versa.


The UFO modeled tile set looks like this:

The UFO - Screenshot

Now, the movement of the UFO will depend on some other things, but we can say in this moment that it can move in any direction. It will attack the player, but can not be damaged by the asteroids nor will it damage them.

The Plasma

The plasma is a simple image, found on the Internet (also free), which looks like this:

The Plasma - Screenshot The Plasma - Screenshot

The plasma is fired by the player starship or UFOs. It can go just up or down, and that is why there are two versions of the same image. Since it travels very fast, I thought it would be very silly to animate something like this.

The Star Field

The game background star field is generated as a different intensity random placed white pixels, like below:

The Starfield - Screenshot


Now, we have modeled, prepared, and explained each game element of interest in our game. You may notice that here is missing the sound part, since I haven't put any sound in the game yet, but I'll write a separate article about that topic when I do. In the next part, we will see how to initialize and shutdown the DirectX sub-system.


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


About the Author

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.

You may also be interested in...

Comments and Discussions

QuestionAsteroid sprite Pin
CushiNomad10-Dec-15 10:56
memberCushiNomad10-Dec-15 10:56 
AnswerRe: Asteroid sprite Pin
darkoman17-Dec-15 20:57
memberdarkoman17-Dec-15 20:57 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.180621.3 | Last Updated 3 Jan 2007
Article Copyright 2007 by darkoman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid