|
Page 4 of 4
Modding
The "Dr. Dobb's Challenge" Visual Studio 2008 project source code can easily be modified, in a number of ways. "Partial conversion" mods, in which the game remains largely the same but gameplay tweaks and graphic changes are made, are simplest and will be explained first. "Total conversion" mods, in which the game logic is discarded and the engine is used to make an entirely different game, are more difficult and will be explained last.
To alter the game's graphics in a partial conversion mod, simply open the game directory's "images" subfolder, and modify the image files using your favorite image editing software. However, when increasing or decreasing the total number of frames of animation, changing the names of the files, altering the animation frame rate, or altering the image dimensions, you will need to make some simple code changes. For example, say that you would like to alter the Dr. Dobbs running animation to decrease the total number of frames from 11 to 6, change the file names from dobbsLRun-X.png to ninjaLRun-X.png, drop the frame rate by one-half, and decrease the image's pixel dimensions, you would have to edit these lines of code in entityPlayer.cpp:
pSpriteLRun = new CSprite(25,30,SPRITE_TYPE_DOBB,1);
pSpriteLRun->AddImage("dobbsLRun-",0,10,".png");
pSpriteRRun = new CSprite(35,30,SPRITE_TYPE_DOBB,1);
pSpriteRRun->AddImage("dobbsRRun-",0,10,".png");
To become:
pSpriteLRun = new CSprite(12,15,SPRITE_TYPE_DOBB,2);
pSpriteLRun->AddImage("ninjaLRun-",0,5,".png");
pSpriteRRun = new CSprite(17,15,SPRITE_TYPE_DOBB,2);
pSpriteRRun->AddImage("ninjaRRun-",0,5,".png");
First, when calling the CSprite constructor, you must pass X and Y center offsets for the first two parameters. These reference where you'd like the effective "center" of the image to be, for the purposes of positioning it on screen. Since the image's pixel dimensions have decreased, these numbers would also have to be changed appropriately.
The final parameter passed to the CSprite constructor dictates the frame rate of the animation. A value of "1" indicates that you would like the sprite's animation to progress each frame. The new value of "2" indicates that you would like the sprite's animation to progress only on every second frame; this effectively halves the frame rate at which the sprite animation is rendered.
Second, when calling the CSprite "AddImage" method, you must pass the new filename string, as well as the range of frame numbers. Since we have decreased the number of frames from 11 to 6, we pass the values 0,5 instead of the previous values of 0,10.
Also, be aware that when altering images or creating entirely new ones, you should ensure that the dimensions for the image canvas are always powers of 2. For example, if the left-running ninja image defined above has a center offset of (12,15), then the ninja image itself is likely a 24x30 pixel image placed in the upper-left corner of a 32x32 pixel canvas. This extra padding is required by DirectX to handle 3D manipulations and, although we're strictly dealing with 2D image manipulations, DirectX will stretch the image to the closest power-of-2 dimension if it is not already.
To tweak the game's gameplay values, simple code changes are required. At the top of the entityPlayer.cpp file, you will find the following lines:
#define DOBB_SPEED_GRASS 7 // Running speed on grass
#define DOBB_SPEED_GLUE 2 // Running speed on glue
#define DOBB_GRAVITY_DELAY 2 // Gravity delay
#define DOBB_GRAVITY_ACCEL 2.5 // Gravity acceleration
#define DOBB_GRAVITY_MAX 15.0 // Terminal velocity
#define DOBB_JUMP0 19.0 // Initial jump speed
#define DOBB_JUMP_COUNT_MAX 2 // Maximum jump count
You can freely edit these physics constants to make changes to the feel of the gameplay. You can increase gravity, allow quadruple jumps, etc.
And lastly, you can of course edit the level files to create your own game levels. Only a text editor is needed, so this is one of the simplest methods of modding the game. Simply open level1.txt in your text editor, and follow the instructions contained within it. It is a simple matter of placing some "G" characters for grass, "P" for the player, "T" for a token, etc.
To perform a total conversion mod, you would discard all of the game logic code described in the "GAME LOGIC" section above (but do keep it around, for reference!), and retain only the game engine code files.
Note: To perform this type of mod, you do not need to understand any of the underlying DirectX code! The DirectX calls are encapsulated within the engine itself, and would only need to be edited in order to add new engine features (such as the ability to play music files, for example). As long as your game uses simple 2D sprites, WAV sound effects, and keyboard and mouse input, the underlying engine code will not need to be changed.
Using the engine's capabilities, as described above, you can make any 2D game you wish! You'll need to create your own game and menu classes, as demonstrated by the "Dr. Dobb's Challenge" game code, and use those classes to control your own set of "entities". For example, if you'd like to make an RPG, you'll want to define your own entityPlayerCharacter, entityNonPlayerCharacter, and entityEnemy classes. Or, if you'd like to create a space shooter, you'll want to define your own entityPlayerShip, entityEnemyShip, and entityBulletclasses, etc. Each of the "entity" classes you create will need to use the sprite class to display graphical representations of the entities on screen, and the sound class to play sound effects. Also, as demonstrated by the "Dr. Dobb's Challenge" game code, your entities will need to encapsulate their own movement physics, collision detection, and other game logic.
By examining the source code, making a partial conversion modification, a total conversion modification, and then perhaps by adding new features to the engine and DirectX sample code, you will obtain a good grounding in the fundamentals of creating video games using Visual Studio 2008, and DirectX! Good luck!
|