Hello all,
I've been doing a few small things with this and I am stuck now at collisions and enemies... I don't know what to do, I've tried all the solutions on here and they don't work!! Here is what I have now and I haven't tried anything with the enemies thing yet, but I would love a good tut on it... Thank you for all your help.
#include "DarkGDK.h"
float g_fSpeed = 0.1f;
float g_fTurn = 0.03f;
float g_fOldCamAngleX = 0.0f;
float g_fOldCamAngleY = 0.0f;
float g_fCameraAngleX = 0.0f;
float g_fCameraAngleY = 0.0f;
int fCameraAngleX;
int fCameraAngleY;
void userInput (void);
void showFPS (void);
bool gun_pickup = false;
void DarkGDK(void)
{
dbSetWindowTitle("FPS Character With Collision");
dbMaximizeWindow ( );
dbHideMouse ( );
dbLoadSound ("Gamesound.wav", 23);
dbPlaySound (23);
dbLoadImage ("texture.jpg", 1);
dbLoadImage ("detail.jpg", 2);
dbSetupTerrain ( );
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "map.bmp" );
dbSetTerrainScale ( 1, 3, 0.6f, 3 );
dbSetTerrainSplit ( 1, 16 );
dbSetTerrainTiling ( 1, 4 );
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1, 1, 0.78f, 0.5f );
dbSetTerrainTexture ( 1, 1, 2 );
dbBuildTerrain ( 1 );
dbSync ( );
dbLoadObject ("New Statue.x", 25);
dbPositionObject ( 25, 450, 0, 485 );
dbRotateObject ( 25, 0, 90, 90);
dbLoadObject ("Atomiser.x",10);
dbPositionObject (10, 550, 5, 550);
dbRotateObject (10, 90, 0, -90);
dbLockObjectOff (10);
dbLoadImage ("gunfire1.png",12,0);
dbMakeObjectBox ( 12, 4 , 4, 0 );
dbTextureObject ( 12 , 100 );
dbFadeObject ( 12, 8000 );
dbSetObjectTransparency ( 12 , 1 );
dbHideObject ( 12 );
dbSetObjectCollisionOff ( 12 );
dbMoveObjectRight ( 12 , 1.85f);
dbMoveObject ( 12 , 8 );
dbMoveObjectDown ( 12 , 1.3f);
dbLockObjectOn ( 12 );
dbSyncOn ( );
dbSyncRate ( 60 );
dbPositionCamera (700, 700, 700);
dbAutomaticCameraCollision(700, 2, 1);
dbSync ( );
showFPS();
userInput();
while ( LoopGDK ( ) )
{
dbLoadImage("crosshair.png",1000);
dbPasteImage ( 1000 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
float xdist, ydist, zdist;
int differences;
xdist = dbCameraPositionX() - dbObjectPositionX(10);
ydist = dbCameraPositionY() - dbObjectPositionY(10);
zdist = dbCameraPositionZ() - dbObjectPositionZ(10);
differences = sqrt((xdist*xdist) + (ydist*ydist) + (zdist*zdist));
if (differences < 20)
{
gun_pickup = true;
}
else
{
gun_pickup = false;
}
if (gun_pickup == true)
{
dbDisableObjectZDepth(10);
dbRotateObject(10,-90,0,0);
dbPositionObject(10,15,-23,30);
dbLockObjectOn(10);
dbFixObjectPivot(10);
}
if ( dbEscapeKey ( ) )
break;
showFPS();
userInput();
dbSync ( );
}
dbSync ( );
return;
dbUpdateTerrain ( );
dbSync ( );
}
void showFPS(void)
{
char szFPS [ 256 ] = "";
strcpy ( szFPS, "fps = " );
strcat ( szFPS, dbStr ( dbScreenFPS ( ) ) );
dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( szFPS ), dbScreenHeight ( ) - 40, szFPS );
}
void userInput(void)
{
dbControlCameraUsingArrowKeys ( 0, g_fSpeed, g_fTurn );
g_fOldCamAngleY = g_fCameraAngleY;
g_fOldCamAngleX = g_fCameraAngleX;
g_fCameraAngleY = dbWrapValue ( g_fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
g_fCameraAngleX = dbWrapValue ( g_fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
dbYRotateCamera ( dbCurveAngle ( g_fCameraAngleY, g_fOldCamAngleY, 24 ) );
dbXRotateCamera ( dbCurveAngle ( g_fCameraAngleX, g_fOldCamAngleX, 24 ) );
char* szKey = dbInKey ( );
if ( strcmp ( szKey, "+" ) == 0 )
{
if ( g_fSpeed < 1000 )
g_fSpeed = g_fSpeed + 0.5f;
}
if ( strcmp ( szKey, "-" ) == 0 )
{
if ( g_fSpeed > 0.02f )
g_fSpeed = g_fSpeed - 0.5f;
}
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 3.0f, dbCameraPositionZ ( ) );
}