And this is the final code. i use string header to make Comparisons.
#include "DarkGDK.h"
//#include "DarkPhysics.h"
#include "DarkAi.h"
#include "string"
#pragma comment ( lib, "DarkAi.lib" )
int health=100;
int ptimer = 0;
int btimer = 0;
int vtimer = 0;
int pMode = 0;
int bMode = 0;
int vMode = 0;
float CameraAngleY;
float CameraAngleX;
int enemyBullet=0;
bool flag=0;
float gunWaggle2=0.0;
int ammoEnemy=30;
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
// define some functions for use later on
void MakeLevel ( void );
void MakeBackground ( void );
using namespace std;
string action[3];
void animation();
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbBackdropOn ( );
dbAutoCamOff ( );
dbSetDisplayMode ( 800, 600, 32 );
dbSetWindowPosition ( GetSystemMetrics ( SM_CXSCREEN ) / 2 - ( 800 / 2 ), GetSystemMetrics ( SM_CYSCREEN ) / 2 - ( 600 / 2 ) );
//dbMaximiseWindow( );
//dbSetWindowOff( );
//dbSetDisplayMode( 1024, 768, 32 );
AIStart();
AISetRadius ( 4.5 );
MakeLevel ( );
// set up the shoot timer
float shootTimer [ 4 ];
for ( int i = 0; i < 4; i++ )
shootTimer [ i ] = 0;
// entity template
dbMakeObjectCone ( 6000, 5 );
dbXRotateObject ( 6000, 90 );
dbFixObjectPivot ( 6000 );
dbMakeMeshFromObject ( 1, 6000 );
dbDeleteObject ( 6000 );
//dbLoadImage("fire2.png",603);
// attack template
dbMakeObjectPlane ( 6000, 0.1f, 1 );
//dbTextureObject (6000,603);
dbXRotateObject ( 6000, 90 );
dbFixObjectPivot ( 6000 );
dbMakeMeshFromObject ( 2,6000 );
dbDeleteObject ( 6000 );
for(int i=2;i<=3;i++)
{
dbMakeObjectBox (i+5,3,3, 0 );
dbLoadImage ("flash4.dds",655);
dbTextureObject ( i+5 ,655 );
dbSetObjectLight ( i+5 , 0 );
dbSetObjectEmissive ( i+5, 0x00FFFF91 );
dbSetObjectAmbience ( i+5 , 0x00FFFFFF );
dbFixObjectPivot ( i+5);
dbFadeObject ( i+5, 8000 );
dbSetObjectTransparency ( i+5 , 1 );
dbHideObject ( i+5);
}
for ( int i = 2; i <= 3; i++ )
{
// make objects
// dbLoadEffect("bumpbone.fx",111,0);
dbLoadObject( "SAS.X", i);
//dbSetObjectEffect(i,111);
dbYRotateObject(i, 180);
dbScaleObject (i,25,25,25 );
dbSetObjectLight(i,0);
dbMakeLight(1);
dbColorLight(1,0,0,0);
dbPointLight(1,dbObjectPositionX(i),dbObjectPositionY(i),dbObjectPositionZ(i));
dbFixObjectPivot(i );
dbPositionObject ( i, ( i - 2 ) * 40 - 20, 2.5, 15 );
//dbLoopObject (i,961,985);
dbSetObjectSpeed (i,31);
dbMakeObject (i + 1000, 2, 1 );
dbSetObjectLight ( i + 1000, 0 );
dbHideObject ( i + 1000 );
// add them to the enemy team
AIAddEnemy ( i );
AISetEntitySpeed ( i, 10.0 );
AISetEntityViewArc ( i, 90, 170 );
AISetEntityViewRange ( i, 300 );
AISetEntityControl ( i,1);
AISetEntityCanStrafe ( i,1);
//AISetEntityCanAttack(i,1);
AISetEntityCanSearch ( i, 1 );
AISetEntityStance ( i, 1 );
dbLoad3DSound("fire.wav",i+2000);
dbLoadObject( "VWEAP.X",i+2 );
dbLoadImage( "gun_D.dds",602 );
dbSetObjectLight(i+2,0);
dbTextureObject( i+2, 602 );
dbXRotateObject( i+2, 0 );
dbYRotateObject( i+2, -8 );
dbZRotateObject( i+2, 0 );
dbScaleObject( i+2,70,70,70 );
dbOffsetLimb( i+2, 0,0,1.5,0);
dbFixObjectPivot(i+2);
dbGlueObjectToLimb(i+2,i,38);
}
// make zone
AIAddZone ( 1, -10, -15, 10, -5 );
dbMakeObjectBox ( 11, 17, 0.1f, 10 );
dbPositionObject ( 11, 0, 0.05f, -10 );
dbColorObject ( 11, dbRgb ( 0, 0, 255 ) );
// assign zones
AIEntityAssignZone ( 2, 1 );
AIEntityAssignZone ( 3, 1 );
// make player
dbMakeObjectBox ( 1,20,140,20);
dbPositionObject ( 1,0,-10, -40 );
AIAddPlayer ( 1 );
dbHideObject(1);
float speed = 5;
// our main loop
while ( LoopGDK ( ) )
{
//above ground & under sky
CameraAngleY =CameraAngleY+(dbMouseMoveX ( ) * 1.0f );
CameraAngleX =CameraAngleX+(dbMouseMoveY ( ) * 1.0f );
if ( CameraAngleX > 90 && CameraAngleX <135 ) CameraAngleX = 90;
if ( CameraAngleX < 270 && CameraAngleX > 225 ) CameraAngleX = 90;
dbYRotateCamera (0 ,CameraAngleY);
dbXRotateCamera (0 ,CameraAngleX);
dbXRotateObject (1,CameraAngleX);
dbYRotateObject (1,CameraAngleY);
dbPositionMouse (( dbScreenWidth( ) / 2 ),( dbScreenHeight( ) / 2 ));
//dbControlCameraUsingArrowKeys(0,3,3);
// move player
if ( dbUpKey ( ) ) dbMoveObject ( 1, speed );
if ( dbDownKey ( ) ) dbMoveObject ( 1, -speed );
if ( dbLeftKey ( ) ) dbMoveObjectLeft ( 1, speed);
if ( dbRightKey ( ) ) dbMoveObjectRight ( 1, speed );
dbText(15,15,dbStr(health));
// hide or show paths
if ( dbKeyState ( 2 ) && ptimer < dbTimer ( ) )
{
// update timer and mode
ptimer = dbTimer ( ) + 300;
pMode = 1 - pMode;
// decide what to do
if ( pMode == 0 )
AIDebugHidePaths ( );
else
AIDebugShowPaths ( 2.5 );
}
// hide or show obstacles
if ( dbKeyState ( 3 ) && btimer < dbTimer ( ) )
{
// update timer and mode
btimer = dbTimer ( ) + 300;
bMode = 1 - bMode;
// decide what to do
if ( ( bMode == 0 ) )
AIDebugHideObstacleBounds ( 0 );
else
AIDebugShowObstacleBounds ( 0,2.5 );
}
// hide or show arcs
if ( dbKeyState ( 4 ) && vtimer < dbTimer ( ) )
{
// update timer and mode
vtimer = dbTimer ( ) + 300;
vMode = 1 - vMode;
// decide what to do
if ( vMode )
AIDebugHideViewArcs ( );
else
AIDebugShowViewArcs ( 2.5 );
}
// hide attack lines
for ( int i = 1001; i <= 1003; i++ )
{
if ( dbObjectExist ( i ) && shootTimer [ i - 1000 ] < 70 )
dbHideObject ( i );
}
for(int i=2;i<=3;i++)
{
dbSetObjectToObjectOrientation (i+5,i );
dbPositionObject(i+5, dbObjectPositionX ( i ) , dbObjectPositionY ( i ) , dbObjectPositionZ(i) );
dbMoveObjectRight(i+5 ,-2.0 + sin ( gunWaggle2 / 2.0f ) / 8.0f );
dbMoveObject (i+5 ,9 );
dbMoveObjectDown(i+5,-12.5);
dbText(15,35,AIGetEntityAction( i ));
dbText(15,55,AIGetEntityState ( i));
dbText(15,75,dbStr(AIGetEntityMoveX ( i )));
dbText(15,95,dbStr(AIGetEntityMoveZ ( i )));
}
/*if(AIGetEntityState(i)=="Run and Attack")
dbLoopObject(i,1052,1070);
if(AIGetEntityState(i)=="Go To Destination")
dbLoopObject(i,1052,1070);
if(AIGetEntityState(i)=="Attack")
dbLoopObject(i,961,985);
/* if(dbLower(AIGetEntityAction ( i))=="Strafing Left And Attacking")
key=1;
if(dbLower(AIGetEntityAction ( i))=="Strafing Right And Attacking")
key=2;
if(key==1)dbLoopObject(i,1032,1051);
if(key==2)dbLoopObject(i,1012,1031);*/
/*if(AIGetEntityMoveX ( i )>0 && (AIGetEntityMoveZ ( i )<0 ))
dbLoopObject(i,1032,1051);
/*if(AIGetEntityMoveX ( i )>0 && (AIGetEntityMoveZ ( i )>0))
dbLoopObject(i,1012,1031);
if(AIGetEntityMoveX ( i )<0 && (AIGetEntityMoveZ ( i )>0 ))
dbLoopObject(i,1032,1051);
if(AIGetEntityMoveX ( i )<0 && (AIGetEntityMoveZ ( i )<0))
dbLoopObject(i,1012,1031);*/
animation();
dbPositionCamera ( dbObjectPositionX(1),15,dbObjectPositionZ(1));
//dbPointCamera( dbCameraPositionX(0),50, dbCameraPositionZ(0));
// dbPointCamera ( 0, 0, -5 );
// update AI
AIUpdate ( );
// displaying the attack is handled outside the AI system
for ( int i = 2; i <=3; i++ )
{
// check our entity exists
if ( AIEntityExist ( i ) == 1 )
{
// check we can fire
if ( AIGetEntityCanFire ( i ) && shootTimer [ i ] <= 0)
{
// get the target position abd place the attack line between them
float tx = AIGetEntityTargetX ( i );
float tz = AIGetEntityTargetZ ( i );
float x = dbObjectPositionX ( i );
float z = dbObjectPositionZ ( i );
float dx = ( x + tx ) / 2.0f;
float dz = ( z + tz ) / 2.0f;
float dist = sqrt ( ( tx - x ) * ( tx - x ) + ( tz - z ) * ( tz - z) );
float ang = acos ( ( tz - z ) / dist ) * 57.29577951308f;
if ( ( tx - x ) < 0 )
ang = 360 - ang;
// update position
dbPositionObject ( i + 1000, dx, 14.0f, dz );
dbYRotateObject ( i + 1000, ang + 0.1f );
dbScaleObject ( i + 1000, 100, 100, 100 * dist );
dbShowObject ( i + 1000 );
if (flag==0)
{
gunWaggle2 += 5.0f;
dbLoopSound (i+2000,500);
dbPositionListener(dbObjectPositionX(i),dbObjectPositionY(i),dbObjectPositionZ(i));
if(vtimer < dbTimer ( ) )
{
// update timer and mode
vtimer = dbTimer ( ) + 1900;
dbStopSound(i+2000);
}
// dbShowObject (i+5 );
dbRollObjectLeft ( i+5 , (float)(rand() % 90) );
if ( enemyBullet++ == 1 )
{
enemyBullet = 0;
dbShowObject (i+5 );
dbRollObjectLeft (i+5, (float)(rand() % 360) );
dbShowLight ( 0 );
dbPositionLight ( 0 , dbObjectPositionX (i) , dbObjectPositionY (i), dbObjectPositionZ (i) );
}
else
{
dbHideObject(i+5);
}
}
if((dbIntersectObject(i + 1000,dbObjectPositionX(i),dbObjectPositionY(i),dbObjectPositionZ(i),dbObjectPositionX(1),dbObjectPositionY(1),dbObjectPositionZ(1)))==0)
{
//dbBox ( 0 , 0 , dbScreenWidth() , dbScreenHeight() , 0x22F34F4F , 0x22F34F4F , 0x22F34F4F , 0x22F34F4F );
health--;
//dbMoveObject(1,-10.0);
}
shootTimer [ i ] = 100;
}
else
if( AIGetEntityCanFire ( i )!=1)
{
dbHideObject(i+5);
dbStopSound( i+2000 );
}
}
// control how often the entity can shoot
if ( shootTimer [ i ] > 0 )
shootTimer [ i ] -= ( speed * 3 );
}
// update the screen*/
// dbPointCamera ( 0, 0, -5 );
dbSync ( );
}
// return back to windows
return;
}
void MakeLevel ( void )
{
// make our level
// make floor
dbMakeObjectBox ( 100, 5000, 1, 5000 );
dbPositionObject ( 100, 0, -0.5, 0 );
dbColorObject ( 100, dbRgb ( 128, 128, 128 ) );
dbMakeObjectBox ( 101, 1, 10, 30 );
dbPositionObject ( 101, -10, 5, 0 );
dbColorObject ( 101, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
AIAddStaticObstacle ( 101 );
dbMakeObjectBox ( 102, 1, 10, 30 );
dbPositionObject ( 102, 10, 5, 0 );
dbColorObject ( 102, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
AIAddStaticObstacle ( 102 );
dbMakeObjectBox ( 103, 40, 10, 1 );
dbPositionObject ( 103, -30, 5, -15 );
dbColorObject ( 103, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
AIAddStaticObstacle ( 103 );
dbMakeObjectBox ( 104, 40, 10, 1 );
dbPositionObject ( 104, 30, 5, -15 );
dbColorObject ( 104, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
AIAddStaticObstacle ( 104 );
dbMakeObjectBox ( 105, 1, 10, 20 );
dbPositionObject ( 105, 30, 5, -40 );
dbColorObject ( 105, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
AIAddStaticObstacle ( 105 );
// make boundary obstacle, encloses the space to keep the entity in
AIStartNewObstacle ( );
// add points in a anti-clockwise direction to
// create a boundary (use clockwise to create an obstacle)
/* AIAddObstacleVertex ( -50, -50 );
AIAddObstacleVertex ( 50, -50 );
AIAddObstacleVertex ( 50, 50 );
AIAddObstacleVertex ( -50, 50 );*/
// finish creating our boundary
AIEndNewObstacle ( 0,10 );
// finalise our obstacles
AICompleteObstacles ( );
}
void animation()
{
//action[1]=AIGetEntityAction(2);
for(int i=2;i<=3;i++)
{
action[i]=AIGetEntityAction(i);
//if(dbObjectPlaying(i)==0)
if ( action[i] == "Moving Forward And Attacking" ){dbLoopObject( i,987,1011); }
if ((action[i] == "Stopped") || (action[i] == "Stopped And Attacking" )){dbLoopObject( i,961,985 ); }
if ((action[i] == "Strafing Left") || (action[i] == "Strafing Left And Attacking")){dbLoopObject( i,1032,1051);}
if ((action[i] == "Strafing Right") || (action[i] == "Strafing Right And Attacking")){dbLoopObject( i,1012,1031);}
//}
}
}
http://www.nvidia.com/docs/TEMPLATE/482/nv_logo_footer.gif