Click here to Skip to main content
13,558,902 members
Click here to Skip to main content
Add your own
alternative version


38 bookmarked
Posted 19 May 2006

DirectX Tutorial Part II: Using the CDirectXDialog class in a pinball game

, 19 May 2006
Rate this:
Please Sign up or sign in to vote.
CDirectXDialog is a base class for dialog classes in which you want to use DirectX. This example gives a profound describtion about the features of this class.


The second part of this tutorial is a working example of the features, which were introduced by CDirectXDialog. In 1999, I participated on the annual programming competition, held by the department of software-engineering of the University of Bochum. With a colleague of mine, we designed this game and implemented all of the tools needed for editing the collision map and the game itself. The original version was completely implemented in pure Java using the AWT framework. It was a big surprise and we were extremely delighted, when this game made it to the first rank at the end of the competition. I decided to rewrite this game in C++ using my CDirectXDialog class, to give a good starting point for other projects in which you can use this class. When I have some more free time, I hope to publish the editor for designing other pinball levels.

  • DirectX tutorial part I: DirectX Dialog Template
  • DirectX tutorial part II: Using the CDirectXDialog class in a pinball game
  • DirectX tutorial part III: Basic 3D mathematics
  • DirectX tutorial part IV: Using the Vector class in a Vectorballs scroller
  • DirectX tutorial part V: Lambert and Gouraud polygon fillers from scratch
  • DirectX tutorial part VI: Doing it the Direct3D way...

The pinball level structure

Due to its origin, the architecture and design of this game aims at reducing redundancy in the level data. The level graphics data file, for example, contains only those base elements from which the whole level can be built. For this creation process, we build our own level editor. The data structure created for a level can be compared with a data cube, where front dimension corresponds to the level width and height, whereby the actual level is rasterized by boxes of 8x8 pixels. For each box in the front dimension (x- and y-axis), the level editor stores an unlimited amount of additional information in the z-axis of the data cube. For instance, the first two important pieces of information are the x and y offsets of the graphic element in the level graphics data file, which can be found in the illustration above.

Unfortunately, the GUI labels of the level editor are completely in German. But, if you look at the dialog box called "Kästcheninformationen", which can be found at the following screenshot, you will notice all of the information needed to calculate the collisions and invoke the corresponding methods when the ball hits some element in the level. The attributes "KAttribut", "OrtsVX", and "OrtsVY" are used to define the vector based lines or circle by which the element boundaries can be defined. Finally, to optimize the collision detection code, we only look at those boxes which are the nearest neighbors of the ball's current location. The rest of the calculation can be summed up as the application of the conservation of momentum and energy theorem.


If you want to start a new game, please press the right mouse button and click on "New Game". Then, you have to compress the spring by holding the down cursor key. By releasing it, the ball is pushed into the game.

In this example, I just wanted to explain that the CDirectXDialog class can not only be used to access the DirectX surface memory, but also as a good starting point for other DirectX based development. If you are interested in the original Java version, please contact me. You can find the Java Applet on this page.


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

Doga Arinir
Chief Technology Officer W3L
Germany Germany
-Since 1th August 2007: Chief Technology Officer of W3L
-2002/08/01-2007/07/31: PhD student
-1997/10/15-2002/07/31: Studied Electrical Engineering and Computer Science

You may also be interested in...


Comments and Discussions

Member 870389717-Apr-13 5:44
memberMember 870389717-Apr-13 5:44 
QuestionCant find "ddutil.h" Pin
KarstenK3-Sep-07 0:50
memberKarstenK3-Sep-07 0:50 
GeneralVery Interesting Pin
Rick York19-May-06 18:15
memberRick York19-May-06 18:15 

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 | Terms of Use | Mobile
Web04 | 2.8.180515.1 | Last Updated 19 May 2006
Article Copyright 2006 by Doga Arinir
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid