I'm creating my first FPS game,
in MS Visual C++ 2008 Express Edition with Dark GDK.

I've created a level and so on, and now I'm updating my enemies.

My ninja enemies have different .x files for different states, example: one for idle and one for attack.

I can't manage the switching between the different states! :(

Here is my code:

void updateNinja ( void )
{
	int iLoop = 0;
	float distCameraNinja;
	
	for ( iLoop = 0; iLoop < ninjaCount; iLoop++)
	{
		if ( ninja[ iLoop ].life > 0 )
		{
			switch ( ninja[ iLoop ].mode )
			{
				case 1 :	// idle		loop idle & check dist
					{
						if ( ninja[ iLoop ].type == 1 )
							dbLoopObject	( ninja[ iLoop ].obj , 0 , 0 );
						else
						{
							dbDeleteObject	( ninja[ iLoop ].obj );
							dbLoadObject	( "media\\H-Ninja-Idle.x" , ninja[ iLoop ].obj );
							dbLoopObject	( ninja[ iLoop ].obj );
							ninja[ iLoop ].type = 1;
						}

						distCameraNinja	= getDistance ( ninja[ iLoop ].curPosX , 0 , ninja[ iLoop ].curPosZ , dbCameraPositionX ( 0 ) , 0 , dbCameraPositionZ ( 0 ) );
						
						if ( distCameraNinja < 100 )
							ninja[ iLoop ].mode = 2;

					} break;

				case 2 :	// run		loop run & play sound & check dist
					{
						if ( ninja[ iLoop ].type == 2 )
							dbLoopObject	( ninja[ iLoop ].obj );
						else
						{
							dbDeleteObject		( ninja[ iLoop ].obj );
							dbLoadObject		( "media\\Ninja\\H-Ninja-Move.x" , ninja[ iLoop ].obj );
							dbPositionObject	( ninja[ iLoop ].obj , ninja[ iLoop ].curPosX , 0 , ninja[ iLoop ].curPosZ );
							dbScaleObject		( ninja[ iLoop ].obj , 3000 , 3000 , 3000 );
							dbSetObjectSpeed	( ninja[ iLoop ].obj , 20 );
							dbLoopObject		( ninja[ iLoop ].obj );
							ninja[ iLoop ].type = 2;
						}

						distCameraNinja	= getDistance ( ninja[ iLoop ].curPosX , 0 , ninja[ iLoop ].curPosZ , dbCameraPositionX ( 0 ) , 0 , dbCameraPositionZ ( 0 ) );

						if ( distCameraNinja> 500 )
							ninja[ iLoop ].mode = 1;
						else if ( distCameraNinja > 100 )
							ninja[ iLoop ].mode = 2;
						else if ( distCameraNinja < 100 )
							ninja[ iLoop ].mode = 3;

					} break;

				case 3 :	// attack	loop attack & play sound & check dist
					{
						if ( ninja[ iLoop ].type == 3 )
							dbLoopObject	( ninja[ iLoop ].obj );
						else
						{
							dbDeleteObject		( ninja[ iLoop ].obj );
							dbLoadObject		( "media\\Ninja\\H-Ninja-Attack1.x" , ninja[ iLoop ].obj );
							dbPositionObject	( ninja[ iLoop ].obj , ninja[ iLoop ].curPosX , 0 , ninja[ iLoop ].curPosZ );
							dbScaleObject		( ninja[ iLoop ].obj , 3000 , 3000 , 3000 );
							dbSetObjectSpeed	( ninja[ iLoop ].obj , 20 );
							dbLoopObject		( ninja[ iLoop ].obj );
							ninja[ iLoop ].type = 3;
						}						
						
						distCameraNinja	= getDistance ( ninja[ iLoop ].curPosX , 0 , ninja[ iLoop ].curPosZ , dbCameraPositionX ( 0 ) , 0 , dbCameraPositionZ ( 0 ) );

						if ( distCameraNinja> 500 )
							ninja[ iLoop ].mode = 1;
						else if ( distCameraNinja > 100 )
							ninja[ iLoop ].mode = 2;
						else if ( distCameraNinja < 100 )
							ninja[ iLoop ].mode = 3;

					} break;

			}

			char	czText[256];
			wsprintf ( czText , "%d distCameraNinja " , (int) distCameraNinja );
			dbText ( 0 , ( iLoop + monsterCount ) * 15 , czText );
		
		}

	}

}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

float getDistance ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 )
{
	float dist;
	float dx;
	float dy;
	float dz;

	dx = x2 - x1;
	dy = y2 - y1;
	dz = z2 - z1;

	dist = sqrt ( ( dx * dx ) + ( dy * dy ) + ( dz * dz ) );

	return dist;
}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

Can anybody help me?

Are there a better way of switching than deleting the current object and load a new object with the same object number?

Please help

And one more thing!!!

When "else" is done in "case 2 : ", the camera automatically moves to another location !?!?!?

WHY?!?!?!

I dont see any answer here... who did solved this? can u help me solve the same problem too? i have separate files for 1 model and when load new objects camera resets :[

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.