just incase you needed to see some code, here it is.
#include "DarkGDK.h"
#include "SC_Collision.h"
float gunWaggle = 0.0f;
float gunWaggle2 = 0.0f;
int fCameraAngleX;
int fCameraAngleY;
float Max;
float XAngleCamera;
bool gun_pickup = false;
int numSpheres = 5;
float radius = 7.0f;
float littleRadius = 2.0f;
int rtimer = 0;
int stimer = 0;
int vtimer = 0;
float gravity = -0.1f;
float slope = 0.5f;
int ground = 1;
int jumptimer = 0;
int syncmode = 60;
int view = 1;
int hide = 0;
//player movement vector
float vx = 0;
float vy = 0;
float vz = 0;
void makeLevel()
{
SetCurrentDirectory ( "media" );
dbLoadObject ( "universe.dbo", 1 );
dbSetObjectLight ( 1, 0 );
dbPositionObject(1,10,10,0);
// load a model for our sky
dbLoadObject ( "dst.x", 2000 );
dbSetObjectLight ( 2000, 0 );
dbSetObjectTexture ( 2000, 3, 2 );
dbScaleObject ( 2000, 5000000, 5000000, 5000000 );
SC_SetupComplexObject( 1,1,1 );
//all level objects are group 1
}
void makePlayer()
{
dbLoadObject("gign.x",2);
dbPositionObject( 2,20,-30,0 );
dbMoveObjectUp( 2,2000.0f);
dbMoveObjectRight(2,1000.0f);
dbScaleObject(2,100,100,100);
dbSetObjectSpeed(2,70);
//gun
dbLoadObject("CQBR_onside.x",9);
dbRotateObject(9,0,-285,165);
dbScaleObject(9,139,139,139);
dbFixObjectPivot(9);
dbPositionObject(9,8,0,0);
dbGlueObjectToLimb (9,2,25);
dbFixObjectPivot(9);
SC_SetupObject( 2,0,0 );
//player has no group
}
void movePlayer()
{
float oldx = dbObjectPositionX(2);
float oldy = dbObjectPositionY(2);
float oldz = dbObjectPositionZ(2);
//apply gravity, and user changes to movement
float angy = dbObjectAngleY(2);
vx = 0;
vz = 0;
//if player is jumping or falling then apply 'normal' gravity
//if not attempt to keep the player stuck to the floor
if ( vy == 0 && jumptimer == 0 ) vy = vy + 10*gravity;
else vy = vy + gravity;
if (dbKeyState(32) == 1 ) { vx = vx - dbCos(angy); vz = vz + dbSin(angy); }
if (dbKeyState(30) == 1 ) { vx = vx + dbCos(angy); vz = vz - dbSin(angy); }
if (dbKeyState(31) == 1 ) { vx = vx + dbSin(angy); vz = vz + dbCos(angy);}
if (dbKeyState(17) == 1 ) { vx = vx - dbSin(angy); vz = vz - dbCos(angy); dbLoopObject(2,92,128);} else dbLoopObject(2,33,90);
//only jump if on ground, and a certain time after last jump
if ( ground == 1 )
{
if ( dbSpaceKey() == 1 && jumptimer == 0 )
{
vy = vy + 4.0f;
jumptimer = 10;
}
}
//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( 2,x,oldy,z );
SC_UpdateObject( 2 );
}
void DarkGDK( )
{
dbSyncOn( );
dbSyncRate( 60 );
dbSetWindowOn();
dbSetWindowPosition (112,84);
dbSetWindowSize (1024,600);
dbSetDisplayMode( 1024,600,32 );
dbSetWindowPosition (132,84);
dbAutoCamOff( );
dbRandomize( dbTimer() );
SC_Start( );
dbLoadSound("M4.wav",211);//Load a gun sound, id is 211
dbSetSoundSpeed(211,19000);
/////////////////////////////
//second muzzle
dbLoadImage("SCflash.png", 20);
dbSprite(20, 0, 0, 20);
dbSetSpriteAlpha(20, 0);
dbHideSprite(20);
dbOffsetSprite( 20,-338,-165);
dbLoadImage("crosshairzoom.png",101);
dbLoadImage("SC.png",50);
//Crosshair image
dbLoadImage("crosshair.png",100);
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
//Makes the camera rotation mount above the player
dbMakeObjectSphere(5,1);
dbPositionObject(5,0,0,0);
dbScaleObject(5,10,10,10);
dbHideObject(5);
makeLevel();
makePlayer();
dbLockObjectOn(100);
while( LoopGDK( ) )
{
movePlayer();
//Camera Loop Options
//This Positions the camera so its always at the camera mount.
dbPositionCamera(dbObjectPositionX(5),dbObjectPositionY(5),dbObjectPositionZ(5));
//Positions The camera mount so its always above the player
dbPositionObject(5,dbObjectPositionX(2)+.5,dbObjectPositionY(2) +55.8,dbObjectPositionZ(2));
//Makes float XAngleCamera always = the camera mount's X angle
XAngleCamera = dbObjectAngleX(5);
//Makes float Max = the camera mount's object X angle + or minus mouse up and down movement.
Max = dbObjectAngleX(5) + dbMouseMoveY() / 2;
//Rotates the camera mount's X angle to equal Max
dbXRotateObject(5,Max);
//Sets the camera's X and Z angle to the same as the camera mount and sets it's Y angle to the same as the player.
dbRotateCamera(dbObjectAngleX(5),dbObjectAngleY(2)+180,dbObjectAngleZ(5));
//Rotates the player model left and right based on the mouse
dbRotateObject( 2, 0, dbObjectAngleY(2) + dbMouseMoveX() / 2, dbObjectAngleZ(2) ) ;
//Sets the camera to always be behind the camera mount
dbMoveCamera( -50 );
dbSetCameraFOV( 2 , 51.0f) ;
dbPitchCameraUp(15.0f);
char str [ 128 ];
sprintf_s( str, 128, "FPS: %d", dbScreenFPS( ) ); dbText( 0,80,str );
//sprintf_s( str, 128, "Touching Ground: %d", ground ); dbText( 0,100,str );
//////////////////////////////////////////////////////////////////////////////////////////////
static int trans = 0;
static int iter = 0;
if(dbMouseClick() == 1) // this is the code that needs to be change
{
dbSetCameraFOV( 0 , 57.0f) ; //zoom Camera
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
dbPasteImage ( 101 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
if(trans < 256 && iter != -95)
iter = 100;
else if(trans > -1)
iter = -70;
else
iter = 70;
trans += iter;
dbSetSpriteAlpha(20, trans);
//dbPlaySound(211);
}
else
{
if(trans != 0) {
trans = (trans < 0) ? 0 : trans - 12;
dbSetSpriteAlpha(20, trans);
}
//dbStopSound(211);//pause gun sound
}
dbSprite(20, 0, 0, 20);
dbText(0, 0, dbStr(trans));
if(dbMouseClick() == 2)//right click
{
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
dbPasteImage ( 101 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
}
else
{
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
dbPasteImage ( 101 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
}
////////////////////////////////////////////////////////////////////
dbPositionMouse (dbScreenWidth() /2, dbScreenHeight() /2);
dbHideMouse ();
///////////Scope/////////////////
if(dbKeyState(42))
{
dbPasteImage ( 50 , ( dbScreenWidth( ) / 2 ) - 160 , ( dbScreenHeight( ) / 2 )
-125 , 1 );
dbSetCameraFOV( 0 , 43.0f) ;
dbHideObject(2);
dbHideObject(100);
dbTurnObjectLeft(50,20);
dbShowSprite(20);
dbHideObject(31);
dbHideObject(9);
}
else
{
dbSetCameraFOV( 0 , 57.0f) ;
dbSetAlphaMappingOn(100,0);
dbShowObject(2);
dbShowObject(100);
dbHideSprite(20);
dbShowObject(9);
}
/////////Zoom////////////////////////////
if(dbKeyState(29))
{
dbSetCameraFOV( 0 , 28.0f) ;
dbPitchCameraDown(10.0f);
dbMoveCameraRight(1,10.0f);
}
else
{
dbSetCameraFOV( 0 , 57.0f) ;
dbPitchCameraUp(10.0f);
dbMoveCameraLeft(1,10.0f);
}
dbSync( );
}
}