コード例 #1
0
ファイル: Mole.cpp プロジェクト: roosen5/media-design-school
void CMole::Draw( void )
{
	m_pSprite->RenderEx( m_vPosition.X(), m_vPosition.Y(), m_fHeading, 1.0f, 1.0f );
	if ( m_bHighlighted )
	{
		CCircle Bounds;
		Bounds.Initialise( m_vPosition, fMOLE_RADIUS );
		CMMMContext::GetInstance().DrawCircle( Bounds, 0xFFFF0000 );
	}

#ifndef _EDITOR
	if (CMMMContext::GetInstance().IsDrawingMoleState())
	{
		CCircle radiusCircle;
		radiusCircle.Initialise(m_vPosition, fMOLE_RADIUS);
		CMMMContext::GetInstance().DrawCircle(radiusCircle, 0xFF00FF00);

		CCircle destinationCircle;
		destinationCircle.Initialise(m_vDestination, 5.0f );
		CMMMContext::GetInstance().DrawCircle(destinationCircle, 0xFF8800FF);
	}

	m_pMoleAgent->Draw();
#endif
}
コード例 #2
0
void		CSquirrel::LoseLife( void )
{
	if ( m_uNumLives )
	{
		// do not lose a life if over a tunnel:
		CTunnel*	pTunnels;
		UINT32		uNumTunnels;
		CMMMContext::GetInstance().GetTunnels( pTunnels, uNumTunnels );

		CCircle Bounds;
		Bounds.Initialise( m_vPosition, m_fRadius );
		for ( UINT32 i=0; i<uNumTunnels; i++ )
		{
			if ( pTunnels[i].Intersects( Bounds ) )
			{
				return; // immune, over a tunnel!
			}
		}


		for ( UINT32 i=0; i<m_uNumAcorns; i++ )
		{
			m_ppAcorns[i]->SetState( CAcorn::ES_Available );
		}
		m_uNumAcorns = 0;
		m_uNumLives--;
		if ( m_uNumLives )
		{
			Spawn();
		} else
		{
			CMMMContext::GetInstance().NotifySquirrelDeath();
		}
	}
}
コード例 #3
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::DrawTargetAcorn(const CAcorn* _kpAcorn) const
{
	GDE::CRenderer* pRenderer = CMMMContext::GetInstance().GetRenderer();


	GDE::SVertex FirstLine[2];
	FirstLine[0].m_uColour = 0xFFFFFF00;
	FirstLine[1].m_uColour = 0xFFFFFF00;


	FirstLine[0].m_fX = m_vPosition.X();
	FirstLine[0].m_fY = m_vPosition.Y();
	FirstLine[0].m_fZ = 0.0f;

	FirstLine[1].m_fX = _kpAcorn->GetPosition().X();
	FirstLine[1].m_fY = _kpAcorn->GetPosition().Y();
	FirstLine[1].m_fZ = 0.0f;


	pRenderer->DrawPrimitives(GDE::PT_LineList, 1, FirstLine);

	CCircle AcornCircle;
	AcornCircle.Initialise(_kpAcorn->GetPosition(), 14.0f);


	AcornCircle.Draw(0xAAFFFF00, true);
}
コード例 #4
0
ファイル: Mole.cpp プロジェクト: roosen5/media-design-school
void CMole::Update(FLOAT32 _fTimeDelta)
{
	m_pMoleAgent->Update(_fTimeDelta);

	// Turn.
	m_fHeading += m_pMoleAgent->GetRotationalSpeed() * _fTimeDelta;

	// Update position.
	CFVec2 vHeading;
	vHeading.SetToRotationZ(m_fHeading);
	CFVec2 vVelocity = vHeading * m_pMoleAgent->GetSpeed() * _fTimeDelta;
	m_vPosition += vVelocity;

	if ((m_vDestination - m_vPosition).Magnitude() < fMOLE_RADIUS)
	{
		Messages::send(DESTINATION_REACHED_EVENT, this);
	}

	// finally check if that pesky rodent got caught:
	CCircle Bounds;
	Bounds.Initialise( m_vPosition, fMOLE_RADIUS );
	if ( CMMMContext::GetInstance().GetSquirrel()->Intersects( Bounds ) )
	{
		CMMMContext::GetInstance().GetSquirrel()->LoseLife();
		Messages::send(DESTINATION_REACHED_EVENT, this);
	}
}
コード例 #5
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
bool
CMole::Intersects(const CBox2D& _krBox) const
{
	CCircle Bounds;
	Bounds.Initialise(m_vPosition, m_fRadius);


	return (_krBox.Intersects(Bounds));
}
コード例 #6
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
bool
CMole::Intersects(const CCircle& _krCircle) const
{
	CCircle Bounds;
	Bounds.Initialise(m_vPosition, m_fRadius);


	return (_krCircle.Overlaps(Bounds));
}
コード例 #7
0
void CPathFindingAgent::Draw() const
{
	if (m_path.size() > 1)
	{
		for (UINT32 uiIndex = 0; uiIndex < m_path.size() - 1; uiIndex++)
		{
			CCircle waypointCircle;
			waypointCircle.Initialise(m_path[uiIndex]->GetPosition(), 5.0f);
			CMMMContext::GetInstance().DrawCircle(waypointCircle, 0xFFBFBD2B);
			CMMMContext::GetInstance().DrawLine(m_path[uiIndex]->GetPosition(), m_path[uiIndex + 1]->GetPosition(), 0xFFBFBD2B);
		}
		
		CCircle waypointCircle;
		waypointCircle.Initialise(m_path.back()->GetPosition(), 5.0f);
		CMMMContext::GetInstance().DrawCircle(waypointCircle, 0xFFBFBD2B);
		
		CCircle destinationCircle;
		destinationCircle.Initialise(m_vDestination, fGRID_SIZE);
		CMMMContext::GetInstance().DrawCircle(destinationCircle, 0xFFBFBD2B);
	}
}
コード例 #8
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::DrawKnownAcorns() const
{
	std::map<CAcorn*, bool>::iterator Current = s_mKnownAcorns.begin();
	std::map<CAcorn*, bool>::iterator End = s_mKnownAcorns.end();


	for (Current; Current != End; ++ Current)
	{
		// Draw known unbags acorns
		if ((*Current).second == false)
		{
			CCircle AcornCircle;
			AcornCircle.Initialise((*Current).first->GetPosition(), 14.0f);
			AcornCircle.Draw(0xAAFA00FF, true);
		}
	}
}
コード例 #9
0
/**
 *	Draw the board.
 *	Should be properly decoupled, oops.
 */
void CGameBoard::Draw( void )
{
	CCircle Circle;
	UINT32 colCurrent;

	bool bHighlighted = false;

	for ( int y=0; y<m_iHeight; y++ )
	{
		for ( int x=0; x<m_iWidth; x++ )
		{
			switch( GetBoardPos( x, y ) )
			{
			default:
			case BOARD_ERROR:
				assert_now( "Error with board" );
			case EMPTY:
				colCurrent = colEMPTY;
				break;
			case PLAYER1:
				colCurrent = colPLAYER_ONE;
				break;
			case PLAYER2:
				colCurrent = colPLAYER_TWO;
				break;
			}
			const FLOAT32 fXPos = fPIECE_RADIUS+fPIECE_SPACING+(fPIECE_SPACING + fPIECE_RADIUS*2)*x;
			const FLOAT32 fYPos = fPIECE_RADIUS+fPIECE_SPACING+(fPIECE_SPACING + fPIECE_RADIUS*2)*y;
			Circle.Initialise( SFVec2( fXPos, fYPos ), fPIECE_RADIUS );
			CConnect4Context::GetInstance().DrawFilledCircle( Circle, colCurrent );
			if ( false == bHighlighted )
			{
				if ( m_iColumnHighlighted == x )
				{
					CConnect4Context::GetInstance().DrawCircle( Circle, colHIGHLIGHT );			
				}
			}
		}
	}
}
コード例 #10
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::Draw(bool _bDrawKnownAcorns)
{
	_bDrawKnownAcorns;
	m_pSprite->RenderEx( m_vPosition.X(), m_vPosition.Y(), m_fHeading, 1.0f, 1.0f );


	//if ( m_bHighlighted )
	{
		CCircle Bounds;
		Bounds.Initialise( m_vPosition, m_fRadius );
		CMMMContext::GetInstance().DrawCircle( Bounds, 0xFFFF0000 );
	}


#ifndef _EDITOR

	DrawWhiskers();
	DrawTaskPathTarget(m_Tasks.top());


	if (m_Tasks.top().GetType() == CTask::TYPE_PATROL)
	{
		DrawTargetAcorn(m_Tasks.top().GetAcorn());
	}


	DrawTaskType();
	m_Repulsor.Draw();
	DrawSteeringForce();

	if (_bDrawKnownAcorns)
	{
		DrawKnownAcorns();
	}

#endif
}
コード例 #11
0
bool CSquirrel::Intersects( const CCircle& Circle ) const
{
	CCircle Bounds;
	Bounds.Initialise( m_vPosition, m_fRadius );
	return Circle.Overlaps( Bounds );
}
コード例 #12
0
void	CSquirrel::Update( FLOAT32 fTimeDelta )
{
	if ( 0 == m_uNumLives )
	{
		return;
	}

	const static CFVec2 s_vMoveOffsets[] = 
	{
		SFVec2( -1.0f,  0.0f ), //"Left",
		SFVec2(  1.0f,  0.0f ), //"Right",
		SFVec2(  0.0f, -1.0f ), //"Up",
		SFVec2(  0.0f,  1.0f ), //"Down"
	};

	_COMPILE_ASSERT( _ARRAY_SIZE( s_vMoveOffsets ) == EMove_COUNT );

	CFVec2 vMove = SFVec2( 0.0f, 0.0f );
	for ( UINT32 i=0; i< EMove_COUNT; i++ )
	{
		if ( m_Movements[i].m_bValue )
		{
			vMove += s_vMoveOffsets[i];
		}
	}

	// great, now we have the movement direction.
	if ( vMove.SquareMagnitude() != 0.0f )
	{
		m_fDistTimeMoving += fTimeDelta;
		vMove.Normalise();
		FLOAT32 fStep = 1.0f;
		CFVec2 vTestedMove = vMove * fTimeDelta * m_fSpeed * fStep;
		// now check the target position -  is it embedded in any walls?
		CCircle TargetBounds;
		while ( fStep > 0.0f )
		{
			TargetBounds.Initialise( m_vPosition + vTestedMove, m_fRadius );
			if ( false == CMMMContext::GetInstance().CircleIntersectsGeometry( TargetBounds ) )
			{
				break;	// found a valid, allowable movement.
			}
			fStep -= 0.2f;
			vTestedMove = vMove * fTimeDelta * m_fSpeed * fStep;
		}
		// now update to the new position
		m_vPosition += vTestedMove;

		// finally what happens at the new position
		// is an acorn collected?
		if ( m_uNumAcorns != m_uMaxAcorns )
		{
			CAcorn* pLevelAcorns;
			UINT32 uNumLevelAcorns;
			CMMMContext::GetInstance().GetAcorns( pLevelAcorns, uNumLevelAcorns );
			for ( UINT32 i=0; i<uNumLevelAcorns; i++ )
			{
				if ( pLevelAcorns[i].GetState() == CAcorn::ES_Available )
				{
					if ( pLevelAcorns[i].Intersects( TargetBounds ) )
					{
						pLevelAcorns[i].SetState( CAcorn::ES_Carried );
						m_ppAcorns[m_uNumAcorns++] = pLevelAcorns+i;
						if ( m_uNumAcorns == m_uMaxAcorns )
						{
							break;	// cannont collect any more!
						}
					}
				}
			}
		}
		// is a tunnel reached?
		if ( m_uNumAcorns > 0 )
		{
			CTunnel*	pTunnels;
			UINT32		uNumTunnels;
			CMMMContext::GetInstance().GetTunnels( pTunnels, uNumTunnels );
			for ( UINT32 i=0; i<uNumTunnels; i++ )
			{
				if ( pTunnels[i].Intersects( TargetBounds ) )
				{
					// reached the tunnel.
					for ( UINT32 i=0; i<m_uNumAcorns; i++ )
					{
						m_ppAcorns[i]->SetState( CAcorn::ES_Collected );
						m_uScore++;
					}
					m_uNumAcorns = 0;
				}
			}
		}
	}

	m_fTimeToDisturbance -= fTimeDelta;
	if ( m_fTimeToDisturbance <= 0.0f )
	{
		// schedule the next disturbance.
		m_fTimeToDisturbance = FLOAT32(rand())/FLOAT32(RAND_MAX);
		m_fTimeToDisturbance *= m_fMaxDistSep-m_fMinDistSep;
		m_fTimeToDisturbance += m_fMinDistSep;

		// create this disturbance:
		FLOAT32 fRad = m_fLastDistDelay=0.0f?0.0f:m_fDistTimeMoving/m_fLastDistDelay;
//		DbgPrint( "Creating Disturbance strength %0.2f, next delay %0.2f\n", fRad,m_fTimeToDisturbance );
		fRad *= m_fMaxDistRad-m_fMinDistRad;
		fRad += m_fMinDistRad;

		if ( fRad >= 0.0f )
		{
			CCircle Dist;
			Dist.Initialise( m_vPosition, fRad );
			CMMMContext::GetInstance().CreateDisturbance( Dist );
		}
		m_fDistTimeMoving = 0.0f;
		m_fLastDistDelay = m_fTimeToDisturbance;
	}



}
コード例 #13
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::UpdatePosition(float _fTimeDelta)
{
	CCircle SelfCircle;
	CWall* pWalls = 0;
	CAcorn* pAcorns = 0;
	CMole* pMoles = 0;
	int iNumWalls = 0;
	int iNumAcorns = 0;
	int iNumMoles = 0;
	bool bCollision = false;


	// Create heading vector
	CFVec2 vHeading(0.0f, -1.0f);
	vHeading.RotateZ(m_fHeading);


	float fMovementVelocity = m_fMovementVelocity + (DIFFICULTY_MOVEMENT_VELOCITY_INCR * m_iDifficultyLevel);


	CFVec2 vNextPosition = m_vPosition;
	vNextPosition += vHeading * (fMovementVelocity * _fTimeDelta);


	SelfCircle.Initialise(vNextPosition, m_fRadius);


	CMMMContext& rMMMContext = CMMMContext::GetInstance();
	rMMMContext.GetWalls(pWalls, iNumWalls);
	rMMMContext.GetAcorns(pAcorns, iNumAcorns);
	rMMMContext.GetMoles(pMoles, iNumMoles);

	

	CCircle EntityCircle;
	SelfCircle.Initialise(vNextPosition, m_fRadius);


	// Check collision against other moles
	for (int i = 0; i < iNumMoles; ++ i)
	{
		if (&pMoles[i] != this)
		{
			EntityCircle.Initialise(pMoles[i].GetPosition(), pMoles[i].GetRadius());


			if (SelfCircle.Overlaps(EntityCircle))
			{
				bCollision = true;
				break;
			}
			else
			{
				// Do nothing
			}
		}
	}


	if (!bCollision)
	{
		// Check collision against walls
		for (int i = 0; i < iNumWalls; ++ i)
		{
			if (SelfCircle.OverlapsLineSegment(pWalls[i].GetEnd0(), pWalls[i].GetEnd1()))
			{
				bCollision = true;


				break;
			}
		}
	}


	if (!bCollision)
	{
		m_vPosition = vNextPosition;
	}
}
コード例 #14
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::Update(float _fTimeDelta, CSquirrel& _rSquirrel)
{
	// Check interection with squirrel
	CCircle Bounds;
	Bounds.Initialise( m_vPosition, m_fRadius );


	if (_rSquirrel.Intersects(Bounds))
	{
		_rSquirrel.LoseLife();
	}


	if (!m_Tasks.empty())
	{
		ProcessStuckManager(_fTimeDelta);


		CTask& rCurrentTask = m_Tasks.top();


		// Check if mole is not patrolling
		if (!m_bHasPatrolTask &&
			rCurrentTask.GetType() != CTask::TYPE_PATROL ||
			rCurrentTask.GetType() != CTask::TYPE_SNOOZE)
		{
			// Try and bags an acorn to patrol, if any
			BagsAcorn();
		}


		switch (rCurrentTask.GetType())
		{
		case CTask::TYPE_EXPLORE:
			ProcessExplore(_fTimeDelta, rCurrentTask);
			break;

		case CTask::TYPE_PATROL:
			ProcessPatrol(_fTimeDelta, rCurrentTask);
			break;

		case CTask::TYPE_SNOOZE:
			ProcessSnooze(_fTimeDelta, rCurrentTask);
			break;

		case CTask::TYPE_HUNT:
			ProcessHunt(_fTimeDelta, rCurrentTask);
			break;

		case CTask::TYPE_STUCK:
			ProcessStuck(_fTimeDelta, rCurrentTask);
			break;
		}
	}
	else
	{
		assert_now("Mole has no assignments");
	}


	s_pSharedPath->NotifyAccessablePosition(m_vPosition, m_fRadius);
	UpdateWhiskers();
	m_Repulsor.Initialise(m_vPosition, fMOLE_RADIUS, 40.0f);
}
コード例 #15
0
ファイル: Mole.cpp プロジェクト: roosen5/media-design-school
bool CMole::Intersects( const CBox2D& Box ) const
{
	CCircle Bounds;
	Bounds.Initialise( m_vPosition, fMOLE_RADIUS );
	return Box.Intersects( Bounds );
}
コード例 #16
0
ファイル: Mole.cpp プロジェクト: roosen5/media-design-school
bool CMole::Intersects( const CCircle& Circle ) const
{
	CCircle Bounds;
	Bounds.Initialise( m_vPosition, fMOLE_RADIUS );
	return Circle.Overlaps( Bounds );
}