// The spawner object class constructor.
SpawnerObject::SpawnerObject( char *name, char *path, unsigned long type ) : SceneObject( type )
{
	// Set spawner objects as ghosts.
	SetGhost( true );

	// Load the spawner's script.
	Script *script = new Script( name, path );

	// Get the spawner's frequency.
	m_frequency = *script->GetFloatData( "frequency" );
	
	// Clear the spawn timer.
	m_spawnTimer = 0.0f;

	// Load the sound to play when the spawner's object is collected.
	if( script->GetStringData( "sound" ) != NULL )
	{
		m_sound = new Sound( script->GetStringData( "sound" ) );
		m_audioPath = new AudioPath3D;
	}

	// No object found, so clear pointers for sound and audio
	else
	{
		m_sound = NULL;
		m_audioPath = NULL;
	}

	// Load the script for the spawner's object.
	m_objectScript = g_engine->GetScriptManager()->Add( script->GetStringData( "object" ), script->GetStringData( "object_path" ) );

	// Get the name of the spawner's object.
	m_name = new char[strlen( m_objectScript->GetStringData( "name" ) ) + 1];
	strcpy( m_name, m_objectScript->GetStringData( "name" ) );

	// Set the spawner's mesh to use the object's mesh.
	SetMesh( m_objectScript->GetStringData( "mesh" ), m_objectScript->GetStringData( "mesh_path" ) );

	// Set the object to spin slowly.
	SetSpin( 0.0f, 1.0f, 0.0f );

	// Get the spawner's radius. A radius of 0.0 indicates that it must be
	// taken from the object to be spawned.
	if( *script->GetFloatData( "radius" ) != 0.0f )
		SetBoundingSphere( D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), *script->GetFloatData( "radius" ) );

	// Get mesh for spawner's ellipse radius
	else if( GetMesh() != NULL )
		SetEllipsoidRadius( *m_objectScript->GetVectorData( "ellipse_radius" ) );

	// Destroy the spawner's script.
	SAFE_DELETE( script );

}
Exemple #2
0
//-----------------------------------------------------------------------------
// The player object class constructor.
//-----------------------------------------------------------------------------
PlayerObject::PlayerObject( PlayerInfo *player, Script *script, unsigned long type ) : AnimatedObject( script->GetStringData( "mesh_name" ), script->GetStringData( "mesh_path" ), type )
{
	// Set the player's DirectPlay ID.
	m_dpnid = player->dpnid;

	// Set the players's name.
	m_name = new char[strlen( player->name ) + 1];
	strcpy( m_name, player->name );

	// Players start with full health;
	m_health = 100.0f;
	m_dying = false;

	// Indicate that the view transform is not being taken from this player.
	m_isViewing = false;

	// Clear the player's score.
	m_frags = 0;
	m_deaths = 0;

	// Player objects start off invisible and disabled.
	SetVisible( false );
	SetEnabled( false );

	// Clear the player's input.
	m_drive = 0.0f;
	m_strafe = 0.0f;
	m_fire = false;

	// Set the correct ellipse radius.
	SetEllipsoidRadius( *script->GetVectorData( "ellipse_radius" ) );

	// Level the player's view tilt.
	m_viewTilt = 0.0f;

	// Set the default view smoothing and sensitivity.
	m_viewSmoothing = 0.5f;
	m_viewSensitivity = 0.65f;

	// Get the view weapon offset.
	m_viewWeaponOffset = *script->GetVectorData( "view_weapon_offset" );

	// Clear the weapons array.
	for( unsigned char w = 0; w < 10; w++ )
		m_weapons[w] = NULL;

	// The player starts with the first basic weapon.
	Script *weaponScript = new Script( "Gun1.txt", "./Assets/Objects/Gun1/" );
	m_weapons[0] = new Weapon( weaponScript, m_viewWeaponOffset );
	m_currentWeapon = 0;
	if( player->dpnid == g_engine->GetNetwork()->GetLocalID() )
		m_weapons[m_currentWeapon]->UseViewWeapon( true );
	else
		m_weapons[m_currentWeapon]->UseViewWeapon( false );
	SAFE_DELETE( weaponScript );

	// Indicate that the player is not changing weapons.
	m_changingWeapon = 0.0f;
	m_weaponChanging = false;

	// Create the callback data used for tracking the player's foot steps.
	m_callbackData[0].foot = 0;
	m_callbackData[1].foot = 1;

	// Create the callback keys. The second key time is set per animation.
	D3DXKEY_CALLBACK keys[2];
	keys[0].Time = 0;
	keys[0].pCallbackData = &m_callbackData[0];
	keys[1].pCallbackData = &m_callbackData[1];

	LPD3DXKEYFRAMEDANIMATIONSET oldAS;
	LPD3DXCOMPRESSEDANIMATIONSET newAS;
	LPD3DXBUFFER buffer;

	// Go through the four movement animations and set the foot step keys.
	for( char a = 1; a < 5; a++ )
	{
		// Get the old animation.
		GetAnimationController()->GetAnimationSet( a, (LPD3DXANIMATIONSET*)&oldAS );

		// Set the time for the second key.
		keys[1].Time = float( oldAS->GetPeriod() / 2.0f * oldAS->GetSourceTicksPerSecond() );

		// Compress the old animation set.
		oldAS->Compress( D3DXCOMPRESS_DEFAULT, 0.4f, NULL, &buffer );

		// Create the new animation using the old one and the foot step keys.
		D3DXCreateCompressedAnimationSet( oldAS->GetName(), oldAS->GetSourceTicksPerSecond(), oldAS->GetPlaybackType(), buffer, 2, keys, &newAS );
		SAFE_RELEASE( buffer );

		// Unregister the old animation set.
		GetAnimationController()->UnregisterAnimationSet( oldAS );
		SAFE_RELEASE( oldAS );

		// Register the new animation set.
		// Note: The new animation is appended to the end of the list.
		GetAnimationController()->RegisterAnimationSet( newAS );
		SAFE_RELEASE( newAS );
	}

	// Play the idle animation.
	PlayAnimation( 0, 0.0f );

	// Create the step sound audio paths.
	m_leftStepAudioPath = new AudioPath3D;
	m_rightStepAudioPath = new AudioPath3D;

	// Set the friction on this object.
	SetFriction( 8.0f );
}