Exemplo n.º 1
0
bool
CMole::InitialiseSprite(const char* _kcpSpriteTexture)
{
	// Clean up
	FW_RELEASE(m_pSprite);


	bool bReturn = false;


	m_pSprite = CMMMContext::GetInstance().GetSpriteM()->FindResouceById( GDE::CResourceId(_kcpSpriteTexture) );


	if (m_pSprite == 0)
	{
		GDE::CTexture* pTexture = CMMMContext::GetInstance().GetRenderer()->GetTextureManager().LoadResource(_kcpSpriteTexture);


		if (_kcpSpriteTexture == 0)
		{
			assert_now( "Unable to find Image \"%s\" for Mole", _kcpSpriteTexture );
		}
		else
		{
			GDE::SFRect TexRect;
			TexRect.m_fX = 0.0f;
			TexRect.m_fY = 0.0f;
			TexRect.m_fWidth = static_cast<float>(pTexture->GetWidth());
			TexRect.m_fHeight = static_cast<float>(pTexture->GetHeight());


			m_pSprite = CMMMContext::GetInstance().GetSpriteM()->CreateSprite( GDE::CResourceId( _kcpSpriteTexture ), pTexture, TexRect );
			m_pSprite->SetHotSpot( TexRect.m_fWidth*0.5f, TexRect.m_fHeight*0.5f );


			pTexture->Release();	// now held inside the sprite.


			bReturn = true;
		}
	}
	else
	{
		bReturn = true;
	}


	return (bReturn);
}
Exemplo n.º 2
0
/**
 *	Initialise the Mole at a given position and texture name, returning succes.
 */
bool CMole::Init( CFVec2Arg vPosition, const char *strTexture, FLOAT32 fHeading, FLOAT32 fDisturbanceRange, FLOAT32 fSightRange )
{
	m_bHighlighted = false;
	m_vPosition = vPosition;
	m_fHeading = fHeading;
	m_pSprite = CMMMContext::GetInstance().GetSpriteM()->FindResouceById( GDE::CResourceId( strTexture ) );
	if ( NULL == m_pSprite )
	{
		GDE::CTexture* pTexture = CMMMContext::GetInstance().GetRenderer()->GetTextureManager().LoadResource( strTexture );
		if ( NULL == pTexture )
		{
			assert_now( "Unable to find Image \"%s\" for Mole", strTexture );
			return false;
		}

		GDE::SFRect TexRect;
		TexRect.m_fX = 0.0f;
		TexRect.m_fY = 0.0f;
		TexRect.m_fWidth = (FLOAT32)pTexture->GetWidth();
		TexRect.m_fHeight = (FLOAT32)pTexture->GetHeight();
		m_pSprite = CMMMContext::GetInstance().GetSpriteM()->CreateSprite( GDE::CResourceId( strTexture ), pTexture, TexRect );
		m_pSprite->SetHotSpot( TexRect.m_fWidth*0.5f, TexRect.m_fHeight*0.5f );
		pTexture->Release();	// now held inside the sprite.
	}

	m_vDestination = SFVec2(Math::GetRandomFloat(0.0f, 800.0f), Math::GetRandomFloat(0.0f, 600.0f));

#ifndef _EDITOR
	m_pMoleAgent = new CMoleAgent(*this, fDisturbanceRange, fSightRange);
#else
	fDisturbanceRange;
	fSightRange;
#endif

	return true;
}
Exemplo n.º 3
0
/**
 *	Initialise the squirrel from the provided parser.
 */
bool CSquirrel::Init( GDE::CDataParser* pParser )
{
	m_fMinDistSep = 0.2f;
	m_fMaxDistSep = 1.0f;
	m_fTimeToDisturbance = 0.0f;
	m_fLastDistDelay = 0.0f;
	m_fDistTimeMoving = 0.0f;
	m_fMinDistRad = 0.0f;
	m_fMaxDistRad = 200.0f;

	m_uScore = 0;
	m_ppAcorns = NULL;
	m_uNumAcorns = 0;
	m_vPosition = SFVec2( 100.0f, 100.f );
	m_pSprite = NULL;
	/**
	 *	Tokens to look up in the parser for each movement.
	 */
	const static char* s_strMoveTokens[] = 
	{
		"Left",
		"Right",
		"Up",
		"Down"
	};
	_COMPILE_ASSERT( _ARRAY_SIZE( s_strMoveTokens ) == EMove_COUNT );

	if ( false == pParser->GetValue( m_fSpeed, "Squirrel", "Speed" ) )
	{
		assert_now( "Unable to parse squirrel speed" );
		return false;
	}

	if ( false == pParser->GetValue( m_fRadius, "Squirrel", "Radius" ) )
	{
		assert_now( "Unable to parse squirrel radius" );
		return false;
	}

	if ( false == pParser->GetValue( m_uMaxLives, "Squirrel", "MaxLives" ) )
	{
		assert_now( "Unable to parse maximum squirrel lives" );
		return false;
	}
	m_uNumLives = m_uMaxLives;

	if ( false == pParser->GetValue( m_uMaxAcorns, "Squirrel", "MaxAcorns" ) )
	{
		assert_now( "Unable to parse maximum squirrel acorns" );
		return false;
	}
	m_ppAcorns = new CAcorn*[m_uMaxAcorns];

	if ( false == pParser->GetValue( m_fMinDistSep, "Squirrel", "MinDisturbanceSep" ) )
	{
		assert_now( "Unable to parse squirrel MinDisturbanceSep" );
		return false;
	}
	if ( false == pParser->GetValue( m_fMaxDistSep, "Squirrel", "MaxDisturbanceSep" ) )
	{
		assert_now( "Unable to parse squirrel MaxDisturbanceSep" );
		return false;
	}
	if ( false == pParser->GetValue( m_fMinDistRad, "Squirrel", "MinDisturbanceRad" ) )
	{
		assert_now( "Unable to parse squirrel MinDisturbanceRad" );
		return false;
	}
	if ( false == pParser->GetValue( m_fMaxDistRad, "Squirrel", "MaxDisturbanceRad" ) )
	{
		assert_now( "Unable to parse squirrel MaxDisturbanceRad" );
		return false;
	}

	// parse and get input bindings:
	const static UINT32 uMAX_BINDING_LEN = 32;
	char strInputBinding[uMAX_BINDING_LEN+1];
	GDE::CInputDevice* pDevice = CMMMContext::GetInstance().GetInput();
	for ( UINT32 i=0; i<EMove_COUNT; i++ )
	{
		m_Movements[i].m_bValue = false;
		if ( false == pParser->GetString( strInputBinding, uMAX_BINDING_LEN, "Squirrel", s_strMoveTokens[i] ) )
		{
			assert_now( "Unable to find squirrel movement binding for %s", s_strMoveTokens[i] );
			return false;
		}
		// now get code
		if ( false == pDevice->GetInputCode( strInputBinding, m_Movements[i].m_uInputCode ) )
		{
			assert_now( "Unable to bind squirrel input \"%s\" for movement %s", strInputBinding, s_strMoveTokens[i] );
			return false;
		}
	}

	const static UINT32 uMAX_SPRITENAME_LEN = 128;
	char strTexture[uMAX_SPRITENAME_LEN];
	if ( false == pParser->GetString( strTexture, uMAX_SPRITENAME_LEN, "Squirrel", "Sprite" ) )
	{
		assert_now( "Unable to find squirrel sprite name" );
		return false;
	}

	m_pSprite = CMMMContext::GetInstance().GetSpriteM()->FindResouceById( GDE::CResourceId( strTexture ) );
	if ( NULL == m_pSprite )
	{
		GDE::CTexture* pTexture = CMMMContext::GetInstance().GetRenderer()->GetTextureManager().LoadResource( strTexture );
		if ( NULL == pTexture )
		{
			assert_now( "Unable to find Image \"%s\" for Squirrel", strTexture );
			return false;
		}

		GDE::SFRect TexRect;
		TexRect.m_fX = 0.0f;
		TexRect.m_fY = 0.0f;
		TexRect.m_fWidth = (FLOAT32)pTexture->GetWidth();
		TexRect.m_fHeight = (FLOAT32)pTexture->GetHeight();
		m_pSprite = CMMMContext::GetInstance().GetSpriteM()->CreateSprite( GDE::CResourceId( strTexture ), pTexture, TexRect );
		m_pSprite->SetHotSpot( TexRect.m_fWidth*0.5f, TexRect.m_fHeight*0.5f );
		pTexture->Release();	// now held inside the sprite.
	}

	return true;
}