943,752 Members | Top Members by Rank

Ad:
Aug 14th, 2009
0

Multiple DirectX .x files from Dark GDK

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
C++ Obliviator is offline Offline
13 posts
since Mar 2009
Aug 14th, 2009
0

Re: Multiple DirectX .x files from Dark GDK

And one more thing!!!

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

WHY?!?!?!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
C++ Obliviator is offline Offline
13 posts
since Mar 2009
Dec 13th, 2010
0
Re: Multiple DirectX .x files from Dark GDK
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 :[
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kiaurutis is offline Offline
1 posts
since Dec 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: allegro problem again, setting it up
Next Thread in Game Development Forum Timeline: Setting up C#/XNL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC