Lol I'll just do it for you, but you have to promise me to study it a bit and learn what exactly is going on. (it will help you in the long run).
Old Code:
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadObject ( "Colonel-X.x", 1 );
dbPositionObject ( 1, 15, 15, 0 );
dbSetObjectSpeed ( 1, 70 );
dbRotateObject ( 1, 0, 180, 0 );
dbSetCameraRange ( 1.0f, 3000.0f );
dbLoadImage ( "Cone_Harbor_TX.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 2 );
dbSetTerrainHeightMap ( 2, "Cone_Harbor.jpg" );
dbSetTerrainScale ( 2, 72.0f, 14.4f, 72.0f );
dbSetTerrainLight ( 2, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 2, 1, 0 );
dbBuildTerrain ( 2 );
dbPositionObject ( 2, 0, 0, 0 );
bool Should_Walk = false;
bool Is_Walking = false;
bool Should_Walk_Left = false;
bool Is_Walking_Left = false;
bool Should_Walk_Right = false;
bool Is_Walking_Right = false;
bool Should_Crouch = false;
bool Is_Crouching = false;
bool Should_Crouch_Forward = false;
bool Is_Crouching_Forward = false;
bool Should_Run = false;
bool Is_Running = false;
bool Should_Run_Left = false;
bool Is_Running_Left = false;
bool Should_Run_Right = false;
bool Is_Running_Right = false;
bool Should_Turn_Right = false;
bool Is_Turning_Right = false;
bool Should_Turn_Left = false;
bool Is_Turning_Left = false;
while ( LoopGDK ( ) )
{
dbSync ( );
float fHeight = dbGetTerrainGroundHeight ( 2, dbObjectPositionX ( 1 ), dbObjectPositionZ ( 1 ) );
dbPositionCamera ( dbObjectPositionX ( 1 ), dbObjectPositionY ( 1 ) + 50, dbObjectPositionZ ( 1 ) - 75);
dbPositionObject ( 1, dbObjectPositionX ( 1 ), fHeight + 10.0f, dbObjectPositionZ ( 1 ) );
Should_Walk = dbKeyState ( 17 ) || dbUpKey ( );
if ( Should_Walk )
{
dbMoveObject ( 1, -2.0f );
}
if ( Should_Walk && ! Is_Walking )
{
dbLoopObject ( 1, 235, 259 );
Is_Walking = true;
}
else if ( ! Should_Walk && Is_Walking )
{
dbStopObject ( 1 );
Is_Walking = false;
} // Makes object #1 walk
if ( ! Is_Walking && ! Is_Walking_Left && ! Is_Walking_Right && ! Is_Crouching && ! Is_Crouching_Forward && ! Is_Running && ! Is_Running_Left && ! Is_Running_Right )
{
dbLoopObject ( 1, 219, 234 );
}
Should_Walk_Left = dbKeyState ( 30 );
if ( Should_Walk_Left )
dbMoveObjectRight ( 1, 1.0f );
if ( Should_Walk_Left && ! Is_Walking_Left )
{
dbLoopObject ( 1, 260, 279 );
Is_Walking_Left = true;
}
else if ( ! Should_Walk_Left && Is_Walking_Left )
{
dbStopObject ( 1 );
Is_Walking_Left = false;
}
Should_Walk_Right = dbKeyState ( 32 );
if ( Should_Walk_Right )
dbMoveObjectLeft ( 1, 1.0f );
if ( Should_Walk_Right && ! Is_Walking_Right )
{
dbLoopObject ( 1, 280, 299 );
Is_Walking_Right = true;
}
else if ( ! Should_Walk_Right && Is_Walking_Right )
{
dbStopObject ( 1 );
Is_Walking_Right = false;
}
Should_Crouch = dbKeyState ( 29 );
if ( Should_Crouch && ! Is_Crouching )
{
dbLoopObject ( 1, 359, 380 );
Is_Crouching = true;
}
else if ( ! Should_Crouch && Is_Crouching )
{
dbStopObject ( 1 );
Is_Crouching = false;
}
Should_Crouch_Forward = dbKeyState ( 29 ) && dbKeyState ( 17 );
if ( Should_Crouch_Forward )
dbMoveObject ( 1, -1.0f );
if ( Should_Crouch_Forward && ! Is_Crouching_Forward )
{
dbLoopObject ( 1, 381, 405 );
Is_Crouching_Forward = true;
}
else if ( ! Should_Crouch_Forward && Is_Crouching_Forward )
{
dbStopObject ( 1 );
Is_Crouching_Forward = false;
}
Should_Run = dbKeyState ( 42 ) && dbKeyState ( 17 );
if ( Should_Run )
dbMoveObject ( 1, -6.0f );
if ( Should_Run && ! Is_Running )
{
dbLoopObject ( 1, 300, 318 );
Is_Running = true;
}
else if ( ! Should_Run && Is_Running )
{
dbStopObject ( 1 );
Is_Running = false;
}
if ( dbLeftKey ( ) )
dbTurnObjectLeft ( 1, 1 );
if ( dbRightKey ( ) )
dbTurnObjectRight ( 1, 1 );
}
return;
}
New Code:
#include "DarkGDK.h"
#include "SC_Collision.h"
float gravity = -0.1f;
float slope = 0.5f;
int ground = 1;
int jumptimer = 0;
//player movement vector
float vx = 0;
float vy = 0;
float vz = 0;
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
SC_Start ( );
dbLoadObject ( "Colonel-X.x", 1 );
dbPositionObject ( 1, 15, 15, 0 );
dbSetObjectSpeed ( 1, 70 );
dbRotateObject ( 1, 0, 180, 0 );
SC_SetupObjectComplex ( 1, 2, 2 );
dbSetCameraRange ( 1.0f, 3000.0f );
dbLoadImage ( "Cone_Harbor_TX.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 2 );
dbSetTerrainHeightMap ( 2, "Cone_Harbor.jpg" );
dbSetTerrainScale ( 2, 72.0f, 14.4f, 72.0f );
dbSetTerrainLight ( 2, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 2, 1, 0 );
dbBuildTerrain ( 2 );
dbPositionObject ( 2, 0, 0, 0 );
dbSetupObjectComplex ( 2, 1, 2 );
bool Should_Walk = false;
bool Is_Walking = false;
bool Should_Walk_Left = false;
bool Is_Walking_Left = false;
bool Should_Walk_Right = false;
bool Is_Walking_Right = false;
bool Should_Crouch = false;
bool Is_Crouching = false;
bool Should_Crouch_Forward = false;
bool Is_Crouching_Forward = false;
bool Should_Run = false;
bool Is_Running = false;
bool Should_Run_Left = false;
bool Is_Running_Left = false;
bool Should_Run_Right = false;
bool Is_Running_Right = false;
bool Should_Turn_Right = false;
bool Is_Turning_Right = false;
bool Should_Turn_Left = false;
bool Is_Turning_Left = false;
while ( LoopGDK ( ) )
{
float fHeight = dbGetTerrainGroundHeight ( 2, dbObjectPositionX ( 1 ), dbObjectPositionZ ( 1 ) );
dbPositionCamera ( dbObjectPositionX ( 1 ), dbObjectPositionY ( 1 ) + 50, dbObjectPositionZ ( 1 ) - 75);
dbPositionObject ( 1, dbObjectPositionX ( 1 ), fHeight + 10.0f, dbObjectPositionZ ( 1 ) );
float oldx = dbObjectPositionX ( 1 );
float oldy = dbObjectPositionY ( 1 );
float oldz = dbObjectPositionZ ( 1 );
if ( vy == 0 && jumptimer == 0 ) vy = vy + 10*gravity;
else vy = vy + gravity;
Should_Walk = dbKeyState ( 17 ) || dbUpKey ( );
if ( Should_Walk )
{
dbMoveObject ( 1, -2.0f );
}
if ( Should_Walk && ! Is_Walking )
{
dbLoopObject ( 1, 235, 259 );
Is_Walking = true;
}
else if ( ! Should_Walk && Is_Walking )
{
dbStopObject ( 1 );
Is_Walking = false;
} // Makes object #1 walk
if ( ! Is_Walking && ! Is_Walking_Left && ! Is_Walking_Right && ! Is_Crouching && ! Is_Crouching_Forward && ! Is_Running && ! Is_Running_Left && ! Is_Running_Right )
{
dbLoopObject ( 1, 219, 234 );
}
Should_Walk_Left = dbKeyState ( 30 );
if ( Should_Walk_Left )
dbMoveObjectRight ( 1, 1.0f );
if ( Should_Walk_Left && ! Is_Walking_Left )
{
dbLoopObject ( 1, 260, 279 );
Is_Walking_Left = true;
}
else if ( ! Should_Walk_Left && Is_Walking_Left )
{
dbStopObject ( 1 );
Is_Walking_Left = false;
}
Should_Walk_Right = dbKeyState ( 32 );
if ( Should_Walk_Right )
dbMoveObjectLeft ( 1, 1.0f );
if ( Should_Walk_Right && ! Is_Walking_Right )
{
dbLoopObject ( 1, 280, 299 );
Is_Walking_Right = true;
}
else if ( ! Should_Walk_Right && Is_Walking_Right )
{
dbStopObject ( 1 );
Is_Walking_Right = false;
}
Should_Crouch = dbKeyState ( 29 );
if ( Should_Crouch && ! Is_Crouching )
{
dbLoopObject ( 1, 359, 380 );
Is_Crouching = true;
}
else if ( ! Should_Crouch && Is_Crouching )
{
dbStopObject ( 1 );
Is_Crouching = false;
}
Should_Crouch_Forward = dbKeyState ( 29 ) && dbKeyState ( 17 );
if ( Should_Crouch_Forward )
dbMoveObject ( 1, -1.0f );
if ( Should_Crouch_Forward && ! Is_Crouching_Forward )
{
dbLoopObject ( 1, 381, 405 );
Is_Crouching_Forward = true;
}
else if ( ! Should_Crouch_Forward && Is_Crouching_Forward )
{
dbStopObject ( 1 );
Is_Crouching_Forward = false;
}
Should_Run = dbKeyState ( 42 ) && dbKeyState ( 17 );
if ( Should_Run )
dbMoveObject ( 1, -6.0f );
if ( Should_Run && ! Is_Running )
{
dbLoopObject ( 1, 300, 318 );
Is_Running = true;
}
else if ( ! Should_Run && Is_Running )
{
dbStopObject ( 1 );
Is_Running = false;
}
if ( dbLeftKey ( ) )
dbTurnObjectLeft ( 1, 1 );
if ( dbRightKey ( ) )
dbTurnObjectRight ( 1, 1 );
//this would be the player's final position without collision
float x = oldx + vx;
float y = oldy + vy;
float z = oldz + vz;
//first handle gravity - seperated from horizontal movement
//to achieve a more realistic effect
//Method: simple - cast a sphere vertically down, if it hits the level then
// position the object there (sticky collision) then move
// on to horizontal movement
// more complex - if we were to only use the simple method the player would be
// allowed to climb almost vertical slopes. Alternative is to
// get the normalY direction to work out how flat the gorund
// below the player is, 0-slope# is flatter, slope#-1 is steeper.
// if it's flat, use sticky collision, if it's steep slide the
// player down the slope. Changing slope# determines how steep the
// player can climb. NOTE: this also effects stairs.
int collide = SC_SphereCastGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, radius,0 );
if ( collide > 0 )
{
//how flat is this ground
float ny = SC_GetCollisionNormalY();
if ( dbAbs(ny) > slope )
{
//FLAT, stick
oldy = SC_GetStaticCollisionY();
}
else
{
//STEEP, slide
x = x - oldx; z = z - oldz;
oldx = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
oldz = SC_GetCollisionSlideZ();
x = x + oldx; z = z + oldz;
}
//ny#<0 means the player has hit a ceiling rather than a floor
if ( ny > slope )
{
//only on ground if standing on flat ground
ground = 1;
vy = 0;
}
else
{
ground = 0;
//if player has hit a flat ceiling then stop vy# movement
if ( ny < -slope ) vy = gravity;
}
}
else
{
//nothing below player, not on ground, add vertical speed to player
oldy = oldy + vy;
ground = 0;
}
//jumptimer will decrease only when player is back on ground
//creates a pause between two successive jumps
if ( ground == 1 && jumptimer > 0 ) jumptimer--;
//handle horizontal movement as sliding
//player only collides with group 1 (level) objs and moves freely through others
collide = SC_SphereSlideGroup( 1, oldx,oldy,oldz, x,oldy,z, radius,0 );
if ( collide > 0 )
{
//if hit, reposition player, halt movement vector
x = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
z = SC_GetCollisionSlideZ();
vx = 0;
vz = 0;
//possible code for giving the player a jumping help up stairs...
//might be useful if slope# is set very high but stairs are still required
//dy = oldy - SC_GetStaticCollisionY()
//if ( dy < slope && dy > 0 && ground == 1 ) vy = 0.5;
}
//position the player
dbPositionObject( 1,x,oldy,z );
SC_UpdateObject( 1 );
dbSync ( );
}
return;
}
Be sure to put the SC_Collision.h file with your source code and also go into where you save Sparky's Collision the got to Lib > VS8 > then copy the object library and paste that into C

rogram FilesMicrosoft Visual Studio 9.0VClib or where ever you installed Visual Studio.