Introduction
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.
Conclusions
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.