Ok. Here goes:
First off, you have to assume that the various classes are well defined and functional (they were for my purposes). Additionally, the method names do what they are called (ie: someobject->SetPosition() will set the object's position accordingly).
Second, all respective calls to LoadFromFile() will assign the object's ID value accordingly. Subsequent calls to LoadFromFile() by a given object will dbClone() an existing object. This is all handled internally by the CEntityObject base class...
Finally, this level editor was basically an unformatted game world. The proverbial "mouse-cursor" was the player (no actual mouse). Move the player where you want, press the appropriate key - voila!
Now to the goodies that you're waiting for...
This file is the actual source that I used to create the level editor. The first part of the file identifies which keystrokes place what objects at the current location.
The second part is the actual code. should be easy to follow as a guide
E = Entry Point (player start location)
X = Exit Point
= = Block (obstacle)
D = Power-Up -> Shield (virtually automatic)
F = Power-Up -> Boot
G = Power-Up -> Glove
J = Power-Up -> Tennis Shoes
W = Power-Up -> Spring
K = Power-Up -> Kite
0 = Power-Up -> Bowling Ball
~ = Free Life
A = Litter-Bug Amazon
B = Litter-Bug Babe
N = Litter-Bug Ninja
T = Trash-Hound Tech
C = Trash-Hound Cyborg
Q = Trash-Hound Iraq
P = Junker Punk
Y = Junker Tommy
U = Junker USA
H = Misc-Litterer Hound
M = Misc-Litterer Mummy
O = Misc-Litterer Bones
R = Misc-Litterer Raptor
S = Misc-Litterer Spectre
V = Alien-Litterer Hive-Brain
L = Alien-Litterer Roller-Bug
Z = Alien-Litterer Mutant
I = Alien-Litterer Psionic
1 = Vehicle-Entity Beach-Bug
2 = Vehicle-Entity Beach-Bug 2
3 = Vehicle-Entity US-Car
4 = Vehicle-Entity Taxi
5 = Vehicle-Entity Car Red
6 = Vehicle-Entity Car White
7 = Vehicle-Entity Car Yellow
8 = Vehicle-Entity Sports-Bike
9 = Vehicle-Entity Sports-Bike 2
The Following Source Code was used to make the Level-Editor:
#include "CaptOoze.h"
using namespace CAPT_OOZE;
using namespace TOOLBOX;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// in this application we are going to create some 3D objects
// and position them on screen
// when starting a Dark GDK program it is useful to set global
// application properties, we begin by turning the sync rate on,
// this means we control when the screen is updated, we also set
// the maximum rate to 60 which means the maximum frame rate will
// be set at 60 frames per second
dbSyncOn();
dbSyncRate(60);
// Now to setup the window for full-screen
int disp_width = GetSystemMetrics(0);
int disp_height = GetSystemMetrics(1);
HDC hdc = GetDC(NULL);
int disp_depth = GetDeviceCaps(hdc,12);
ReleaseDC(NULL,hdc);
dbHideWindow();
dbSetWindowPosition(0,0);
dbSetWindowLayout(0,0,0);
dbSetDisplayMode(disp_width, disp_height, disp_depth);
dbShowWindow();
float _y_pos=-300;
int MOVE_RATE = 2;
dbPositionCamera ( 0, 0, _y_pos );
dbPointCamera ( 0, 0, 0 );
dbSetCameraRange( 1, 100000 );
dbAutoCamOff ( );
//dbSetCameraRange(2000.0f, 100000.0f);
//CImageClass sky_image;
//sky_image.LoadFromFile( "MEDIA\\mm1.bmp" );
CEntityObject sky_sphere;
sky_sphere.LoadFromFile( "MEDIA\\mm.x" );
sky_sphere.SetPosition( 0, 0, 0 );
//sky_sphere.SetScale( 30000, 30000, 30000 );
//sky_sphere.SetTexture( sky_image, 1 );
sky_sphere.Show();
/* Only the player will show the MOVE animation */
CPlayer mPlayer;
mPlayer.Hide();
mPlayer.SetPosition(-2000,-2000,0);
mPlayer.SetCurrentObject(NORMAL);
mPlayer.SetTransparency(4);
mPlayer.Show();
CSphereObject mPlayerPos;
mPlayerPos.CreateObject("PlayerPos", 1);
mPlayerPos.SetPosition( -2000, -2000, -100 );
mPlayerPos.Show();
CKeyboard keyboard;
CMouse mouse;
/* Level map for later storage to file... */
/* NOTE: int key will be object.PosX << 16 ^ object.PosY */
/* This will generate a unique key based upon the */
/* object's position within the game-level world. */
std::map<int, CEntityObject*> Level;
std::map<int, CEntityObject*>::iterator Level_Pos;
std::map<int, CEntityObject*>::reverse_iterator Level_RPos;
bool delete_existing = false;
CEntityObject *obj = NULL;
CEntityObject *obj_new = NULL;
/* Entry/Exit Points - We can only have ONE of each so create it now */
CEntityObject *entry_point = new CEntryPoint();
CEntityObject *exit_point = new CExitPoint();
char status[150]="";
FILE *out_file = fopen( "Level1.dat", "w+b");
//CLevelMap map;
//map.LoadFromFile( "MEDIA\\Level_1.dat" );
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
keyboard.Poll();
mouse.Poll();
/* Where is the player now...? */
float x,y,z,xx,yy,zz;
mPlayer.GetPosition(x,y,z);
mPlayer.GetRotationAngles( xx, yy, zz );
if (keyboard.KeyOnce( VK_ADD )) {
MOVE_RATE++;
if (MOVE_RATE > 100) {
MOVE_RATE = 100;
}
sprintf_s( status, 150, "Move Rate Increased to %d.", MOVE_RATE );
}
if (keyboard.KeyOnce( VK_SUBTRACT )) {
MOVE_RATE--;
if (MOVE_RATE < 2) {
MOVE_RATE = 2;
}
sprintf_s( status, 150, "Move Rate Decreased to %d.", MOVE_RATE );
}
/* Looking to zoom the camera in / out? */
if (keyboard.KeyPressed(VK_F1))
_y_pos-=MOVE_RATE;
if (keyboard.KeyPressed(VK_F2))
_y_pos+=MOVE_RATE;
if (keyboard.KeyPressed(VK_F5)) {
_y_pos = -300;
dbPositionCamera(dbCameraPositionX(),dbCameraPositionY(), _y_pos);
continue; /* We'll lose this frame's update, but we're lost so I don't care */
}
/* Moving the player? */
if (keyboard.KeyPressed(VK_UP)) {
if (keyboard.KeyPressed(VK_DOWN)) {
/* if UP and DOWN are pressed, do nothing... */
y += 0;
} else if (keyboard.KeyPressed(VK_RIGHT)) {
/* UP and RIGHT are pressed */
mPlayer.RotateY( 225 );
x += (1.0f * MOVE_RATE);
y += (1.0f * MOVE_RATE);
} else if (keyboard.KeyPressed(VK_LEFT)) {
/* UP and LEFT are pressed */
mPlayer.RotateY(135);
x -= (1.0f * MOVE_RATE);
y += (1.0f * MOVE_RATE);
} else {
/* Only UP is pressed... */
mPlayer.RotateY(180);
y += (1.0f * MOVE_RATE);
}
} else if (keyboard.KeyPressed(VK_DOWN)) {
if (keyboard.KeyPressed(VK_UP)) {
/* DOWN and UP are pressed, do nothing... */
y -= 0;
} else if (keyboard.KeyPressed(VK_RIGHT)) {
/* DOWN and RIGHT are pressed */
mPlayer.RotateY( 315 );
x += (1.0f * MOVE_RATE);
y -= (1.0f * MOVE_RATE);
} else if (keyboard.KeyPressed(VK_LEFT)) {
mPlayer.RotateY(45);
x -= (1.0f * MOVE_RATE);
y -= (1.0f * MOVE_RATE);
}
else {
/* Only DOWN is pressed... */
mPlayer.RotateY(0);
y -= (1.0f * MOVE_RATE);
}
} else if (keyboard.KeyPressed(VK_LEFT)) {
if (keyboard.KeyPressed(VK_RIGHT)) {
/* LEFT and RIGHT are pressed, do nothing... */
x -= 0;
} else if (keyboard.KeyPressed(VK_UP)) {
/*LEFT and UP are pressed */
mPlayer.RotateY(135);
x -= (1.0f * MOVE_RATE);
y += (1.0f * MOVE_RATE);
} else if (keyboard.KeyPressed(VK_DOWN)) {
mPlayer.RotateY(45);
x -= (1.0f * MOVE_RATE);
y -= (1.0f * MOVE_RATE);
} else {
mPlayer.RotateY(90);
x -= (1.0f * MOVE_RATE);
}
} else if (keyboard.KeyPressed(VK_RIGHT)) {
if (keyboard.KeyPressed(VK_LEFT)) {
/* RIGHT and LEFT are pressed, do nothing... */
x += 0;
} else if (keyboard.KeyPressed(VK_UP)) {
/*LEFT and UP are pressed */
mPlayer.RotateY(225);
x += (1.0f * MOVE_RATE);
y += (1.0f * MOVE_RATE);
} else if (keyboard.KeyPressed(VK_DOWN)) {
mPlayer.RotateY(315);
x += (1.0f * MOVE_RATE);
y -= (1.0f * MOVE_RATE);
} else {
x += (1.0f * MOVE_RATE);
mPlayer.RotateY(270);
}
}
if (keyboard.KeyPressed( VK_CONTROL )) {
if (keyboard.KeyDown( 'S' )) {
fseek( out_file, 0, SEEK_SET );
/* Save the Level Map as it is now... */
for (int i=80; i>=0; i--) { /* Y-Axis */
for (int j=0; j<=80; j++) { /* X-Axis */
int key=((j<<16) ^ i);
CEntityObject *tmp = Level[key];
if (NULL != tmp) {
fputc( tmp->FileCode, out_file );
} else {
fputc( ' ', out_file );
}
}
fputc( '\n', out_file );
}
sprintf_s( status, 150, "Level Saved!" );
continue; /* We lose a frame update, but who cares...? */
}
}
/* Convert Player Position X/Y from float to int for more int-based calcs below */
int wx = static_cast<int>(x);
int wy = static_cast<int>(y);
/*
Convert from World-Coordinates in 3D space (GDK values ranging from -2000 thru 2000)
to world-map coordinates (ranging from 0 thru 80).
(Current - Min) / 50 = Axis_Pos
Assuming CurrentX = -1923 and CurrentY = 201 (GDK World coordinate) solve for
X/Y Axis Positions:
X: (-1923 - (-2000)) / 50 = 77 / 50 = 1.54 (int) -> 1
Y: (201 - (-2000)) / 50 = 2201 / 50 = 44.02 (int) -> 44
*/
int WorldPosX = (wx - (-2000)) / 50;
int WorldPosY = (wy - (-2000)) / 50;
float SnapToX = static_cast<float>(-2000 + (WorldPosX * 50));
float SnapToY = static_cast<float>(-2000 + (WorldPosY * 50));
/* Create the Unique Key to the map using X/Y World-Map Coordinates */
int map_key = ((WorldPosX << 16) ^ WorldPosY);
/* We default to NOT deleting any existing object at the current location */
delete_existing = false;
/* Get the existing object at this position (if any) and delete it */
obj = Level[map_key];
if (keyboard.KeyOnce( VK_DELETE )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Deleting object at: %d x %d", WorldPosX, WorldPosY );
}
/* Entry-Point Placement */
if (keyboard.KeyOnce( 'E' )) {
/* If there's already an OBJECT here, remove it... */
if (NULL != obj)
delete_existing = true;
/* if Entry-Point has already been added to the level, remove it from the current insertion point */
for (Level_Pos = Level.begin(); Level_Pos != Level.end(); Level_Pos++) {
if (entry_point != Level_Pos->second)
continue; /* On to the Next... */
/* We've found what we're looking for... */
Level.erase(Level_Pos); /* Erase it from the list */
break;
}
/* Either it wasn't already found; or if it was, it's been erased... */
sprintf_s( status, 150, "Entry Point Placed at: %d x %d", WorldPosX, WorldPosY );
entry_point->SetPosition( SnapToX, SnapToY, 0 );
entry_point->FileCode = 'E';
entry_point->Show();
obj_new = entry_point;
}
/* Exit-Point Placement */
if (keyboard.KeyOnce( 'X' )) {
/* If there's already an OBJECT here, remove it... */
if (NULL != obj)
delete_existing = true;
/* if Exit-Point has already been added to the level, remove it from the current insertion point */
for (Level_Pos = Level.begin(); Level_Pos != Level.end(); Level_Pos++) {
if (exit_point != Level_Pos->second)
continue; /* On to the Next... */
/* We've found what we're looking for... */
Level.erase(Level_Pos); /* Erase it from the list */
break;
}
/* Either it wasn't already found; or if it was, it's been erased... */
sprintf_s( status, 150, "Exit Point Placed at: %d x %d", WorldPosX, WorldPosY );
exit_point->SetPosition( SnapToX, SnapToY, 0 );
exit_point->FileCode = 'X';
exit_point->Show();
obj_new = exit_point;
}
/* Free Life Token */
if (keyboard.KeyOnce( VK_OEM_3 /* `~ key */ )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "FreeLife: %d x %d", WorldPosX, WorldPosY );
CFreeLifePoint *life = new CFreeLifePoint();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = '~';
life->Show();
obj_new = life;
}
}
/* Drop a block */
if (keyboard.KeyOnce( VK_SPACE )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Cube: %d x %d", WorldPosX, WorldPosY );
CCubeObject *cube = new CCubeObject();
if (MYVERIFY(NULL != cube)) {
cube->CreateObject( status, 50 );
cube->SetPosition( SnapToX, SnapToY, 0 );
cube->FileCode = '=';
cube->Show();
obj_new = cube;
}
}
if (keyboard.KeyOnce( 'D' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (Shield): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_Shield *life = new CPlayerBonus_Shield();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = 'D';
life->Show();
obj_new = life;
}
}
if (keyboard.KeyOnce( 'F' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (Boot): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_Boot *life = new CPlayerBonus_Boot();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = 'F';
life->Show();
obj_new = life;
}
}
if (keyboard.KeyOnce( 'G' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (Glove): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_Glove *life = new CPlayerBonus_Glove();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = 'G';
life->Show();
obj_new = life;
}
}
if (keyboard.KeyOnce( 'J' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (Shoes): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_Shoes *life = new CPlayerBonus_Shoes();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = 'J';
life->Show();
obj_new = life;
}
}
if (keyboard.KeyOnce( 'W' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (Spring): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_Spring *life = new CPlayerBonus_Spring();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = 'W';
life->Show();
obj_new = life;
}
}
if (keyboard.KeyOnce( 'K' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (Kite): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_Kite *life = new CPlayerBonus_Kite();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = 'K';
life->Show();
obj_new = life;
}
}
if (keyboard.KeyOnce( '0' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Player Bonus (BowlingBall): %d x %d", WorldPosX, WorldPosY );
CPlayerBonus_BowlingBall *life = new CPlayerBonus_BowlingBall();
if (MYVERIFY(NULL != life)) {
life->SetPosition( SnapToX, SnapToY, 0 );
life->FileCode = '0';
life->Show();
obj_new = life;
}
}
/*
**************************************************
A/B/N = LitterBug Entities: Amazon/Babe/Ninja
**************************************************
*/
/* LitterBug_Amazon */
if (keyboard.KeyOnce( 'A' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "LitterBug_Amazon: %d x %d", WorldPosX, WorldPosY );
CLitterBug_Amazon *amazon = new CLitterBug_Amazon();
if (MYVERIFY(NULL != amazon)) {
amazon->SetAnimationSpeed();
amazon->SetCurrentObject(IDLE);
amazon->SetScale( 2500, 2500, 2500 );
amazon->SetPosition( SnapToX, SnapToY, 0 );
amazon->FileCode = 'A';
amazon->Show();
obj_new = amazon;
}
}
/* LitterBug_Babe */
if (keyboard.KeyOnce( 'B' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "LitterBug_Babe: %d x %d", WorldPosX, WorldPosY );
CLitterBug_Babe *babe = new CLitterBug_Babe();
if (MYVERIFY(NULL != babe)) {
babe->SetAnimationSpeed();
babe->SetCurrentObject(IDLE);
babe->SetScale( 2500, 2500, 2500 );
babe->SetPosition( SnapToX, SnapToY, 0 );
babe->FileCode = 'B';
babe->Show();
obj_new = babe;
}
}
/* LitterBug_Ninja */
if (keyboard.KeyOnce( 'N' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "LitterBug_Ninja: %d x %d", WorldPosX, WorldPosY );
CLitterBug_Ninja *ninja = new CLitterBug_Ninja();
if (MYVERIFY(NULL != ninja)) {
ninja->SetAnimationSpeed();
ninja->SetCurrentObject(IDLE);
ninja->SetScale( 2500, 2500, 2500 );
ninja->SetPosition( SnapToX, SnapToY, 0 );
ninja->FileCode = 'N';
ninja->Show();
obj_new = ninja;
}
}
/*
**************************************************
T/C/Q = Trash-hound Entities: Tech/Cyborg/iraQ
**************************************************
*/
/* TrashHound_Tech */
if (keyboard.KeyOnce( 'T' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "TrashHound_Tech: %d x %d", WorldPosX, WorldPosY );
CTrashHound_Tech *tech = new CTrashHound_Tech();
if (MYVERIFY(NULL != tech)) {
tech->SetAnimationSpeed();
tech->SetCurrentObject(IDLE);
tech->SetScale( 2500, 2500, 2500 );
tech->SetPosition( SnapToX, SnapToY, 0 );
tech->FileCode = 'T';
tech->Show();
obj_new = tech;
}
}
/* TrashHound_Cyborg */
if (keyboard.KeyOnce( 'C' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "TrashHound_Cyborg: %d x %d", WorldPosX, WorldPosY );
CTrashHound_Cyborg *cyborg = new CTrashHound_Cyborg();
if (MYVERIFY(NULL != cyborg)) {
cyborg->SetAnimationSpeed();
cyborg->SetCurrentObject(IDLE);
cyborg->SetScale( 2500, 2500, 2500 );
cyborg->SetPosition( SnapToX, SnapToY, 0 );
cyborg->FileCode = 'C';
cyborg->Show();
obj_new = cyborg;
}
}
/* TrashHound_Iraq */
if (keyboard.KeyOnce( 'Q' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "TrashHound_Iraq: %d x %d", WorldPosX, WorldPosY );
CTrashHound_Iraq *iraq = new CTrashHound_Iraq();
if (MYVERIFY(NULL != iraq)) {
iraq->SetAnimationSpeed();
iraq->SetCurrentObject(IDLE);
iraq->SetScale( 2500, 2500, 2500 );
iraq->SetPosition( SnapToX, SnapToY, 0 );
iraq->FileCode = 'Q';
iraq->Show();
obj_new = iraq;
}
}
/*
**************************************************
P/Y/U = Junker Entities: Punk/tommY/Usa
**************************************************
*/
/* Junker_Punk */
if (keyboard.KeyOnce( 'P' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Junker_Punk: %d x %d", WorldPosX, WorldPosY );
CJunker_Punk *punk = new CJunker_Punk();
if (MYVERIFY(NULL != punk)) {
punk->SetAnimationSpeed();
punk->SetCurrentObject(IDLE);
punk->SetScale( 2500, 2500, 2500 );
punk->SetPosition( SnapToX, SnapToY, 0 );
punk->FileCode = 'P';
punk->Show();
obj_new = punk;
}
}
/* Junker_Tommy */
if (keyboard.KeyOnce( 'Y' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Junker_Tommy: %d x %d", WorldPosX, WorldPosY );
CJunker_Tommy *tommy = new CJunker_Tommy();
if (MYVERIFY(NULL != tommy)) {
tommy->SetAnimationSpeed();
tommy->SetCurrentObject(IDLE);
tommy->SetScale( 2500, 2500, 2500 );
tommy->SetPosition( SnapToX, SnapToY, 0 );
tommy->FileCode = 'Y';
tommy->Show();
obj_new = tommy;
}
}
/* Junker_USA */
if (keyboard.KeyOnce( 'U' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "Junker_USA: %d x %d", WorldPosX, WorldPosY );
CJunker_USA *usa = new CJunker_USA();
if (MYVERIFY(NULL != usa)) {
usa->SetAnimationSpeed();
usa->SetCurrentObject(IDLE);
usa->SetScale( 2500, 2500, 2500 );
usa->SetPosition( SnapToX, SnapToY, 0 );
usa->FileCode = 'U';
usa->Show();
obj_new = usa;
}
}
/*
**************************************************
H/M/B/R/S = Misc. Entities: Hound/Mummy/Bones/Raptor/Spectre
**************************************************
*/
/* MiscLitterer_Hound */
if (keyboard.KeyOnce( 'H' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "MiscLitterer_Hound: %d x %d", WorldPosX, WorldPosY );
CMiscLitterer_Hound *hound= new CMiscLitterer_Hound();
if (MYVERIFY(NULL != hound)) {
hound->SetAnimationSpeed();
hound->SetCurrentObject(IDLE);
hound->SetScale( 2500, 2500, 2500 );
hound->SetPosition( SnapToX, SnapToY, 0 );
hound->FileCode = 'H';
hound->Show();
obj_new = hound;
}
}
/* MiscLitterer_Mummy */
if (keyboard.KeyOnce( 'M' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "MiscLitterer_Mummy: %d x %d", WorldPosX, WorldPosY );
CMiscLitterer_Mummy *mummy= new CMiscLitterer_Mummy();
if (MYVERIFY(NULL != mummy)) {
mummy->SetAnimationSpeed();
mummy->SetCurrentObject(IDLE);
mummy->SetScale( 2500, 2500, 2500 );
mummy->SetPosition( SnapToX, SnapToY, 0 );
mummy->FileCode = 'M';
mummy->Show();
obj_new = mummy;
}
}
/* MiscLitterer_Bones */
if (keyboard.KeyOnce( 'O' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "MiscLitterer_Bones: %d x %d", WorldPosX, WorldPosY );
CMiscLitterer_Bones *bones= new CMiscLitterer_Bones();
if (MYVERIFY(NULL != bones)) {
bones->SetAnimationSpeed();
bones->SetCurrentObject(IDLE);
bones->SetScale( 2500, 2500, 2500 );
bones->SetPosition( SnapToX, SnapToY, 0 );
bones->FileCode = 'O';
bones->Show();
obj_new = bones;
}
}
/* MiscLitterer_Raptor */
if (keyboard.KeyOnce( 'R' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "MiscLitterer_Raptor: %d x %d", WorldPosX, WorldPosY );
CMiscLitterer_Raptor *raptor= new CMiscLitterer_Raptor();
if (MYVERIFY(NULL != raptor)) {
raptor->SetAnimationSpeed();
raptor->SetCurrentObject(IDLE);
raptor->SetScale( 1500, 1500, 1500 );
raptor->SetPosition( SnapToX, SnapToY, 0 );
raptor->FileCode = 'R';
raptor->Show();
obj_new = raptor;
}
}
/* MiscLitterer_Spectre */
if (keyboard.KeyOnce( 'S' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "MiscLitterer_Spectre: %d x %d", WorldPosX, WorldPosY );
CMiscLitterer_Spectre *spectre= new CMiscLitterer_Spectre();
if (MYVERIFY(NULL != spectre)) {
spectre->SetAnimationSpeed();
spectre->SetCurrentObject(IDLE);
spectre->SetScale( 2500, 2500, 2500 );
spectre->SetPosition( SnapToX, SnapToY, 0 );
spectre->FileCode = 'S';
spectre->Show();
obj_new = spectre;
}
}
/*
**************************************************
V/L/Z/I = Alien. Entities: Hive-Brain/roLlerBug/mutant/psioniC
**************************************************
*/
/* AlienLitterer_HiveBrain */
if (keyboard.KeyOnce( 'V' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "AlienLitterer_HiveBrain: %d x %d", WorldPosX, WorldPosY );
CAlienLitterer_HiveBrain *hivebrain = new CAlienLitterer_HiveBrain();
if (MYVERIFY(NULL != hivebrain)) {
hivebrain->SetAnimationSpeed();
hivebrain->SetCurrentObject(IDLE);
hivebrain->SetScale( 1000, 1000, 1000 );
hivebrain->SetPosition( SnapToX, SnapToY, 0 );
hivebrain->FileCode = 'V';
hivebrain->Show();
obj_new = hivebrain;
}
}
/* AlienLitterer_RollerBug */
if (keyboard.KeyOnce( 'L' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "AlienLitterer_RollerBug: %d x %d", WorldPosX, WorldPosY );
CAlienLitterer_RollerBug *rollerbug = new CAlienLitterer_RollerBug();
if (MYVERIFY(NULL != rollerbug)) {
rollerbug->SetAnimationSpeed();
rollerbug->SetCurrentObject(IDLE);
rollerbug->SetScale( 2500, 2500, 2500 );
rollerbug->SetPosition( SnapToX, SnapToY, 0 );
rollerbug->FileCode = 'L';
rollerbug->Show();
obj_new = rollerbug;
}
}
/* AlienLitterer_Mutant */
if (keyboard.KeyOnce( 'Z' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "AlienLitterer_Mutant: %d x %d", WorldPosX, WorldPosY );
CAlienLitterer_Mutant *mutant = new CAlienLitterer_Mutant();
if (MYVERIFY(NULL != mutant)) {
mutant->SetAnimationSpeed();
mutant->SetCurrentObject(IDLE);
mutant->SetScale( 2500, 2500, 2500 );
mutant->SetPosition( SnapToX, SnapToY, 0 );
mutant->FileCode = 'Z';
mutant->Show();
obj_new = mutant;
}
}
/* AlienLitterer_PsIonic */
if (keyboard.KeyOnce( 'I' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "AlienLitterer_Psionic: %d x %d", WorldPosX, WorldPosY );
CAlienLitterer_Psionic *psionic = new CAlienLitterer_Psionic();
if (MYVERIFY(NULL != psionic)) {
psionic->SetAnimationSpeed();
psionic->SetCurrentObject(IDLE);
psionic->SetScale( 1000, 1000, 1000 );
psionic->SetPosition( SnapToX, SnapToY, 0 );
psionic->FileCode = 'I';
psionic->Show();
obj_new = psionic;
}
}
/*
**************************************************
1/2/3/4/5/6/7/8/9 = Vehicle Entities:
1-BeachBug
2-BeachBug2
3-US Car
4-Taxi
5-Red Car
6-White Car
7-Yellow Car
8-Sports Bike
9-Sports Bike2
**************************************************
*/
/* VehicleEntity_BeachBug */
if (keyboard.KeyOnce( '1' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_BeachBug: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_BeachBug *beachbug = new CVehicleEntity_BeachBug();
if (MYVERIFY(NULL != beachbug)) {
beachbug->SetAnimationSpeed();
beachbug->SetCurrentObject(IDLE);
beachbug->SetScale( 2000, 2000, 2000 );
beachbug->SetPosition( SnapToX, SnapToY, 0 );
beachbug->FileCode = '1';
beachbug->Show();
obj_new = beachbug;
}
}
/* VehicleEntity_BeachBug2 */
if (keyboard.KeyOnce( '2' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_BeachBug2: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_BeachBug2 *beachbug2 = new CVehicleEntity_BeachBug2();
if (MYVERIFY(NULL != beachbug2)) {
beachbug2->SetAnimationSpeed();
beachbug2->SetCurrentObject(IDLE);
beachbug2->SetScale( 2000, 2000, 2000 );
beachbug2->SetPosition( SnapToX, SnapToY, 0 );
beachbug2->FileCode = '2';
beachbug2->Show();
obj_new = beachbug2;
}
}
/* VehicleEntity_USCar */
if (keyboard.KeyOnce( '3' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_USCar: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_USCar *uscar = new CVehicleEntity_USCar();
if (MYVERIFY(NULL != uscar)) {
uscar->SetAnimationSpeed();
uscar->SetCurrentObject(IDLE);
uscar->SetScale( 2000, 2000, 2000 );
uscar->SetPosition( SnapToX, SnapToY, 0 );
uscar->FileCode = '3';
uscar->Show();
obj_new = uscar;
}
}
/* VehicleEntity_Taxi */
if (keyboard.KeyOnce( '4' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_Taxi: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_Taxi *taxi = new CVehicleEntity_Taxi();
if (MYVERIFY(NULL != taxi)) {
taxi->SetAnimationSpeed();
taxi->SetCurrentObject(IDLE);
taxi->SetScale( 2000, 2000, 2000 );
taxi->SetPosition( SnapToX, SnapToY, 0 );
taxi->FileCode = '4';
taxi->Show();
obj_new = taxi;
}
}
/* VehicleEntity_CarRed */
if (keyboard.KeyOnce( '5' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_CarRed: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_CarRed *carred = new CVehicleEntity_CarRed();
if (MYVERIFY(NULL != carred)) {
carred->SetAnimationSpeed();
carred->SetCurrentObject(IDLE);
carred->SetScale( 2000, 2000, 2000 );
carred->SetPosition( SnapToX, SnapToY, 0 );
carred->FileCode = '5';
carred->Show();
obj_new = carred;
}
}
/* VehicleEntity_CarWhite */
if (keyboard.KeyOnce( '6' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_CarWhite: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_CarWhite *carwhite = new CVehicleEntity_CarWhite();
if (MYVERIFY(NULL != carwhite)) {
carwhite->SetAnimationSpeed();
carwhite->SetCurrentObject(IDLE);
carwhite->SetScale( 2000, 2000, 2000 );
carwhite->SetPosition( SnapToX, SnapToY, 0 );
carwhite->FileCode = '6';
carwhite->Show();
obj_new = carwhite;
}
}
/* VehicleEntity_CarYellow */
if (keyboard.KeyOnce( '7' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_CarYellow: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_CarYellow *caryellow = new CVehicleEntity_CarYellow();
if (MYVERIFY(NULL != caryellow)) {
caryellow->SetAnimationSpeed();
caryellow->SetCurrentObject(IDLE);
caryellow->SetScale( 2000, 2000, 2000 );
caryellow->SetPosition( SnapToX, SnapToY, 0 );
caryellow->FileCode = '7';
caryellow->Show();
obj_new = caryellow;
}
}
/* VehicleEntity_SportsBike */
if (keyboard.KeyOnce( '8' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_SportsBike: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_SportsBike *sportsbike = new CVehicleEntity_SportsBike();
if (MYVERIFY(NULL != sportsbike)) {
sportsbike->SetAnimationSpeed();
sportsbike->SetCurrentObject(IDLE);
sportsbike->SetScale( 2000, 2000, 2000 );
sportsbike->SetPosition( SnapToX, SnapToY, 0 );
sportsbike->FileCode = '8';
sportsbike->Show();
obj_new = sportsbike;
}
}
/* VehicleEntity_SportsBike2 */
if (keyboard.KeyOnce( '9' )) {
if (NULL != obj)
delete_existing = true;
sprintf_s( status, 150, "VehicleEntity_SportsBike2: %d x %d", WorldPosX, WorldPosY );
CVehicleEntity_SportsBike2 *sportsbike2 = new CVehicleEntity_SportsBike2();
if (MYVERIFY(NULL != sportsbike2)) {
sportsbike2->SetAnimationSpeed();
sportsbike2->SetCurrentObject(IDLE);
sportsbike2->SetScale( 2000, 2000, 2000 );
sportsbike2->SetPosition( SnapToX, SnapToY, 0 );
sportsbike2->FileCode = '9';
sportsbike2->Show();
obj_new = sportsbike2;
}
}
/* Are we supposed to delete the object...? */
if ((NULL != obj) && (true == delete_existing)) {
Level.erase(map_key);
if ((obj != entry_point) && (obj != exit_point)) {
obj->UnloadObject();
SAFE_DELETE(obj);
}
}
if (NULL != obj_new)
Level[map_key] = obj_new;
obj = NULL;
obj_new = NULL;
//keep camera over the player
mPlayer.SetPosition(x,y,z);
mPlayerPos.SetPosition(x,y,-100);
dbPositionCamera ( x, y, _y_pos );
//map.Update(0);
//map.CullEntities();
//map.CullObjects();
mPlayer.PrintStats();
char stats[120];
sprintf_s(stats, 120, "World-Map Position: X=%d Y=%d", WorldPosX, WorldPosY );
dbText( 700, 20, stats );
dbText( 0, 150, status );
// here we make a call to update the contents of the screen
dbSync( );
}
/* Save the Level Map as it is now... */
fseek( out_file, 0, SEEK_SET );
for (int i=80; i>=0; i--) { /* Y-Axis */
for (int j=0; j<=80; j++) { /* X-Axis */
int key=((j<<16) ^ i);
CEntityObject *tmp = Level[key];
if (NULL != tmp) {
fputc( tmp->FileCode, out_file );
} else {
fputc( ' ', out_file );
}
}
fputc( '\n', out_file );
}
fclose(out_file);
//map.UnloadLevel();
mPlayer.UnloadObject();
sky_sphere.UnloadObject();
mPlayerPos.UnloadObject();
//sky_image.UnloadImage();
// and now everything is ready to return back to Windows
return;
}
Now that the level was saved (hard coded filename), I have another class that I use within the game itself called CLevelMap. The CLevelMap class will load the file specified and create the appropriate objects at the proper locations. Here's the code:
.H file
#ifndef OTI_LEVEL1_H__
#define OTI_LEVEL1_H__
namespace CAPT_OOZE {
class CLevelMap {
public:
CLevelMap(void);
virtual ~CLevelMap(void);
public:
virtual void LoadFromFile( char *fname );
virtual void UnloadLevel( void );
virtual void Update( int elapsed );
virtual void CullEntities( void );
virtual void CullObjects( void );
virtual void GetEntryPoint( float &x, float &y, float &z ) const;
virtual TOOLBOX::CEntity* GetEntityByID( int id );
virtual TOOLBOX::CEntityObject* GetObjectByID( int id );
protected:
virtual float SnapTo( int val ) const;
virtual void AddNewBlock( int x, int y);
virtual void AddNewPoint( int type, int x, int y );
virtual void AddNewLitterBug( int type, int x, int y );
virtual void AddNewTrashHound( int type, int x, int y );
virtual void AddNewJunker( int type, int x, int y );
virtual void AddNewMiscLitterer( int type, int x, int y );
virtual void AddNewAlien( int type, int x, int y );
virtual void AddNewVehicle( int type, int x, int y );
virtual void AddNewPowerUp( int type, int x, int y );
virtual void AddHook( int type, int x, int y );
protected:
typedef std::vector<TOOLBOX::CEntity*> ENTITY_LIST;
typedef std::vector<TOOLBOX::CEntity*>::iterator ENTITY_LIST_POS;
typedef std::vector<TOOLBOX::CEntity*>::reverse_iterator ENTITY_LIST_RPOS;
typedef std::vector<TOOLBOX::CEntityObject*> OBJECT_LIST;
typedef std::vector<TOOLBOX::CEntityObject*>::iterator OBJECT_LIST_POS;
typedef std::vector<TOOLBOX::CEntityObject*>::reverse_iterator OBJECT_LIST_RPOS;
/* We don't know how many ENTITYs there will be until we read the level.dat file */
ENTITY_LIST m_Entities;
OBJECT_LIST m_Objects;
CSkySphere m_SkySphere;
private:
float m_EntryPointX;
float m_EntryPointY;
float m_EntryPointZ;
};
}; // namespace CAPT_OOZE
#endif //OTI_LEVEL1_H__
.cpp file
#include "CaptOoze.h"
namespace CAPT_OOZE {
CLevelMap::CLevelMap(void) {};
CLevelMap::~CLevelMap(void) {};
void CLevelMap::LoadFromFile( char *fname ) {
if (MYVERIFY(NULL != fname)) {
FILE *lvl_file = fopen( fname, "r+t" );
if (MYVERIFY(NULL != lvl_file)) {
/* NOTE: The Sky-Sphere should be defined in the level file... */
m_SkySphere.LoadFromFile( "MEDIA\\mm.x" );
m_SkySphere.Show();
int in_;
for( int y=81; (y >= 0 ) && ( feof( lvl_file ) == 0 ); y-- ) {
char status[50];
sprintf_s( status, 50, "Loading Level-Map Row: %d", y );
dbText( 0, 150, status );
dbSync();
for ( int x=0; (x <= 81) && ( feof( lvl_file ) == 0 ); x++ ) {
in_ = fgetc( lvl_file );
if (in_ == EOF)
break;
switch(in_)
{
case ' ': /* Do nothing... */
break;
case '\n': /* Do nothing... */
break;
case '=': {
AddNewBlock( x, y );
}
break;
case 'E': /* Fall Through... */
case 'X':
case '~': {
AddNewPoint( in_, x, y );
}
break;
case '*': {
AddHook( in_, x, y );
}
break;
case 'A': /* Fall Through... */
case 'B':
case 'N': {
AddNewLitterBug( in_, x, y );
}
break;
case 'T': /* Fall Through... */
case 'C':
case 'Q': {
AddNewTrashHound( in_, x, y );
}
break;
case 'P': /* Fall Through... */
case 'Y':
case 'U': {
AddNewJunker( in_, x, y );
}
break;
case 'H': /* Fall Through... */
case 'M':
case 'O':
case 'R':
case '@':
case 'S': {
AddNewMiscLitterer( in_, x, y );
}
break;
case 'V': /* Fall Through... */
case 'L':
case 'Z':
case 'I': {
AddNewAlien( in_, x, y );
}
break;
case '1': /* Fall Through... */
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
AddNewVehicle( in_, x, y );
}
break;
case 'D': /* Fall Through... */
case 'F':
case 'G':
case 'J':
case 'W':
case 'K':
case '0': {
AddNewPowerUp( in_, x, y );
}
break;
default:
MYERROR("Invalid input from Level-Map Loader File: %s (%c)", fname, in_);
break;
}
} /* for (int x...) */
} /* for (int y...) */
fclose(lvl_file);
} /* (NULL != lvl_file) */
} /* (NULL != fname) */
}
void CLevelMap::UnloadLevel( void ) {
ENTITY_LIST_POS y;
OBJECT_LIST_POS z;
TOOLBOX::CEntity *ent=NULL;
TOOLBOX::CEntityObject *obj=NULL;
/*
NOTE: Our last clause of this for...loop is so that we always get the
beginning of the list of entity-objects. Since we are erasing()
entities in the list, the iterator may become invalid; this way,
we will ensure that we always have a valid iterator to work with...
*/
for (y=m_Entities.begin(); y!=m_Entities.end(); y=m_Entities.begin()) {
ent = VALUE_OF(y);
if (MYVERIFY(ent != NULL)) {
ent->UnloadObject();
m_Entities.erase(y);
SAFE_DELETE(ent);
}
}
/*
NOTE: Our last clause of this for...loop is so we always get the
beginning of the list of entity-objects. Since we are erasing()
objects in the list, the iterator may become invalid; this way,
we will ensure that we always have a valid iterator to work with...
*/
for (z=m_Objects.begin(); z!=m_Objects.end(); z=m_Objects.begin()) {
obj = VALUE_OF(z);
if (MYVERIFY(obj != NULL)) {
obj->UnloadObject();
m_Objects.erase(z);
SAFE_DELETE(obj);
}
}
/* Release the Sky Sphere... */
m_SkySphere.UnloadObject();
}
void CLevelMap::Update( int elapsed ) {
ENTITY_LIST_POS y;
OBJECT_LIST_POS z;
TOOLBOX::CEntity *ent=NULL;
TOOLBOX::CEntityObject *obj=NULL;
/*
NOTE: Our last clause of this for...loop is so that we always get the
beginning of the list of entity-objects. Since we are erasing()
entities in the list, the iterator may become invalid; this way,
we will ensure that we always have a valid iterator to work with...
*/
for (y=m_Entities.begin(); y!=m_Entities.end(); y++) {
ent = VALUE_OF(y);
if (MYVERIFY(ent != NULL)) {
ent->Update(elapsed);
}
}
/*
NOTE: Our last clause of this for...loop is so we always get the
beginning of the list of entity-objects. Since we are erasing()
objects in the list, the iterator may become invalid; this way,
we will ensure that we always have a valid iterator to work with...
*/
for (z=m_Objects.begin(); z!=m_Objects.end(); z++) {
obj = VALUE_OF(z);
if (MYVERIFY(obj != NULL)) {
obj->Update(elapsed);
}
}
m_SkySphere.Update(elapsed);
}
void CLevelMap::CullEntities( void ) {
for (ENTITY_LIST_POS y=m_Entities.begin(); y!=m_Entities.end(); y++) {
TOOLBOX::CEntity *ent = VALUE_OF(y);
if (MYVERIFY(NULL != ent)) {
ent->Hide();
if (ent->IsInScreen()) {
ent->Show();
}
}
}
}
void CLevelMap::CullObjects( void ) {
for (OBJECT_LIST_POS y=m_Objects.begin(); y!=m_Objects.end(); y++) {
TOOLBOX::CEntityObject *obj = VALUE_OF(y);
if (MYVERIFY(NULL != obj)) {
obj->Hide();
if (obj->IsInScreen()) {
obj->Show();
}
}
}
}
void CLevelMap::GetEntryPoint( float &x, float &y, float &z ) const {
x = m_EntryPointX;
y = m_EntryPointY;
z = m_EntryPointZ;
}
TOOLBOX::CEntity* CLevelMap::GetEntityByID(int id) {
for (ENTITY_LIST_POS y=m_Entities.begin(); y!=m_Entities.end(); y++) {
TOOLBOX::CEntity *ent = VALUE_OF(y);
if (MYVERIFY(NULL != ent)) {
if (ent->GetObjectID() == id) {
return ent;
}
}
}
return NULL;
}
TOOLBOX::CEntityObject* CLevelMap::GetObjectByID(int id) {
for (OBJECT_LIST_POS y=m_Objects.begin(); y!=m_Objects.end(); y++) {
TOOLBOX::CEntityObject *obj = VALUE_OF(y);
if (MYVERIFY(NULL != obj)) {
if (obj->GetObjectID() == id) {
return obj;
}
}
}
return NULL;
}
float CLevelMap::SnapTo( int val ) const {
return (-2000 + (static_cast<float>(val) * 50.0f));
}
void CLevelMap::AddNewBlock( int x, int y ) {
char name[35];
sprintf_s( name, 35, "Cube: %d x %d", x, y );
TOOLBOX::CCubeObject *cube = new TOOLBOX::CCubeObject();
cube->CreateObject( name, 50 );
cube->SetPosition( SnapTo(x), SnapTo(y), 0 );
cube->Show();
/*
Level Blocks are direct instances of namespace TOOLBOX:: Entity_Objects; and since
TOOLBOX:: classes do not have physics built in, we need to add their physics
support ourselves...
*/
TOOLBOX::CFulcrumPhy_Wrapper &phy=TOOLBOX::CFulcrumPhy_Wrapper::GetInstance();
phy.makeBox( cube->GetObjectID(), false, 0 );
m_Objects.push_back(cube);
}
void CLevelMap::AddNewPoint( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'E': {
obj = new CEntryPoint();
}
break;
case 'X': {
obj = new CExitPoint();
}
break;
case '~': {
obj = new CFreeLifePoint();
}
break;
default:
MYERROR( "Error creating new Point: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Objects.push_back(obj);
if ('E' == type) {
/* We need these values so we can respond to GetEntryPoint() method... */
obj->GetPosition( m_EntryPointX, m_EntryPointY, m_EntryPointZ );
}
}
}
void CLevelMap::AddNewLitterBug( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'A': {
obj = new CLitterBug_Amazon();
}
break;
case 'B': {
obj = new CLitterBug_Babe();
}
break;
case 'N': {
obj = new CLitterBug_Ninja();
}
break;
default:
MYERROR( "Error creating new Litter-Bug: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddNewTrashHound( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'T': {
obj = new CTrashHound_Tech();
}
break;
case 'C': {
obj = new CTrashHound_Cyborg();
}
break;
case 'Q': {
obj = new CTrashHound_Iraq();
}
break;
default:
MYERROR( "Error creating new Trash-Hound: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddNewJunker( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'P': {
obj = new CJunker_Punk();
}
break;
case 'Y': {
obj = new CJunker_Tommy();
}
break;
case 'U': {
obj = new CJunker_USA();
}
break;
default:
MYERROR( "Error creating new Junker: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddNewMiscLitterer( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'H': {
obj = new CMiscLitterer_Hound();
}
break;
case 'M': {
obj = new CMiscLitterer_Mummy();
}
break;
case 'O': {
obj = new CMiscLitterer_Bones();
}
break;
case 'R': {
obj = new CMiscLitterer_Raptor();
}
break;
case '@': {
obj = new CMiscLitterer_Zombie();
}
break;
case 'S': {
obj = new CMiscLitterer_Spectre();
}
break;
default:
MYERROR( "Error creating new Misc. Litterer: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddNewAlien( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'V': {
obj = new CAlienLitterer_HiveBrain();
}
break;
case 'L': {
obj = new CAlienLitterer_RollerBug();
}
break;
case 'Z': {
obj = new CAlienLitterer_Mutant();
}
break;
case 'I': {
obj = new CAlienLitterer_Psionic();
}
break;
default:
MYERROR( "Error creating new Alien: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddNewVehicle( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case '1': {
obj = new CVehicleEntity_BeachBug();
}
break;
case '2': {
obj = new CVehicleEntity_BeachBug2();
}
break;
case '3': {
obj = new CVehicleEntity_USCar();
}
break;
case '4': {
obj = new CVehicleEntity_Taxi();
}
break;
case '5': {
obj = new CVehicleEntity_CarRed();
}
break;
case '6': {
obj = new CVehicleEntity_CarWhite();
}
break;
case '7': {
obj = new CVehicleEntity_CarYellow();
}
break;
case '8': {
obj = new CVehicleEntity_SportsBike();
}
break;
case '9': {
obj = new CVehicleEntity_SportsBike2();
}
break;
default:
MYERROR( "Error creating new Vehicle: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddNewPowerUp( int type, int x, int y ) {
TOOLBOX::CEntity *obj = NULL;
switch(type) {
case 'D': {
obj = new CPlayerBonus_Shield();
}
break;
case 'F': {
obj = new CPlayerBonus_Boot();
}
break;
case 'G': {
obj = new CPlayerBonus_Glove();
}
break;
case 'J': {
obj = new CPlayerBonus_Shoes();
}
break;
case 'W': {
obj = new CPlayerBonus_Spring();
}
break;
case 'K': {
obj = new CPlayerBonus_Kite();
}
break;
case '0': {
obj = new CPlayerBonus_BowlingBall();
}
break;
default:
MYERROR( "Error creating new Power-Up: (%c)", type );
break;
}
if (MYVERIFY(NULL != obj)) {
obj->SetPosition( SnapTo(x), SnapTo(y), 0 );
obj->SetCurrentObject(IDLE);
obj->Show();
m_Entities.push_back(obj);
}
}
void CLevelMap::AddHook( int type, int x, int y ) {
}
/*
Code taken from a post by forum user: Sixty Squares in the thread. I will look into using a derivative
of this code to optimize level block drawing / physics at a later date, but for now, it's kept
here for future reference...
http://forum.thegamecreators.com/?m=forum_view&t=83452&b=6
function Merge_Object(SObj,EObj,TOBj,X#,Y#,Z#)
remstart
SOBJ=Start Merge OBject
EOBJ=End MErge Object
TOBj=The final object number
X# Y# and Z# = The center point in the object (not sure what the word for this is). It's what the object's position is based on.
NOTE: The limbs are stated in this way: Limb 1=SObj.
The limb number goes up by 1 with each limb added. So, the second object would be limb 2.
remend
`Set Start Limb Number to 1
Limb=1
`Make a TINY almost invisible sphere to mark the center of the object
make object sphere TObj,0
`Begin to select all of the objects from the SOBj to the EObj
for M = SOBj to EObj
`Make a mesh from the selected object
make mesh from object m,m
`Add the object to the final object as a limb
add limb TObj,Limb,m
`Position the limb where the object was, but in a local way instead.
offset Limb TObj,Limb,Object Position x(m)-x#,Object Position y(m)-y#,Object Position z(m)-z#
`Rotate the limb to the old object's position.
rotate limb TObj,Limb,Object angle x(m),Object angle y(m),Object angle z(m)
`Increasethe limb number.
inc Limb
`Delete the original object
delete object m
`Delete the Mesh
delete mesh m
`Keep going until you're done!
next m
Endfunction
*/
}; // namespace CAPT_OOZE
Finally, the level editor code was used to create the following file which was then loaded up by the CLevelMap class:
LevelMap.dat:
=================================================================================
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= =
= Z =
= U U = ====== = =
= ======== ======== = = ===== ==== ~ =
= = X = =Y Y= = = = = ==== =
= === ===== ===== = = = = P = = = =
= = ======== = = =
= ===== ===== K =
= == == = == == =
= = 2 = V === V = 1 = =
= =================== ======= ======== ===================== M = =
= * ~ ==== =
= =
=== I 0 I = ==
= ================ = = = L === =
= == Q Q == === ======== === =
= =================== = = =
= D N N ==== == == =
= == ======= ======== R =
= = == ==== ========== =
= = F ===== ===== = = = = =
=== = B = B = = = = =
=E = A = ==== ==== == = ===== ===== ========= =
== ===== == == === = == == == ==
=W ======= N =G T T = C C 9 =JQ ==
=================================================================================
As I said, you won't be able to use it directly, but it should give you an idea on how to proceed.
I hope this helps,
JTK