예제 #1
0
bool IsSpaceEmpty( CBaseEntity *pEntity )
{
	bool bEmpty = true;

	Vector vecMins, vecMaxs;
	pEntity->GetAbsBounds( &vecMins, &vecMaxs );

	// World bounds!
	if ( !g_ScreenRect.contains( vecMins ) || !g_ScreenRect.contains( vecMaxs ) )
	{
		// Screen edges are always solid.
		bEmpty = false;
	}

	for ( int i = 0; i < MAX_ENTITIES; i++ )
	{
		CBaseEntity *pOther = g_EntityList[i];
		if ( !pOther || pOther == pEntity || pOther->GetSolidType() == SOLID_NO )
			continue;

		Vector vecOtherMins, vecOtherMaxs;
		pOther->GetAbsBounds( &vecOtherMins, &vecOtherMaxs );

		if ( IsBoxIntersectingBox( vecMins, vecMaxs, vecOtherMins, vecOtherMaxs ) )
		{
			if ( pOther->IsSolid() )
			{
				bEmpty = false;
			}
		}
	}

	return bEmpty;
}
예제 #2
0
//-----------------------------------------------------------------------------
// Purpose: "Physics" simulation.
//-----------------------------------------------------------------------------
void CBaseEntity::ProcessMovement( void )
{
	// Test new position.
	Vector vecNewOrigin = m_vecOrigin + m_vecVelocity * g_FrameTime;
	Vector vecMins = vecNewOrigin + m_vecMins;
	Vector vecMaxs = vecNewOrigin + m_vecMaxs;

	// Test collision against other entities.
	// Since movement amount depends on frame time and we only test the final position
	// this whole system goes out of the window at low framerates.
	bool bCanMove = true;

	if ( GetSolidType() != SOLID_NO )
	{
		// World bounds!
		if ( !g_ScreenRect.contains( vecMins ) || !g_ScreenRect.contains( vecMaxs ) )
		{
			TouchScreenEdge( vecNewOrigin );

			// Screen edges are always solid.
			if ( IsSolid() )
			{
				bCanMove = false;
			}
		}

		for ( int i = 0; i < MAX_ENTITIES; i++ )
		{
			CBaseEntity *pEntity = g_EntityList[i];
			if ( !pEntity || pEntity == this || pEntity->GetSolidType() == SOLID_NO )
				continue;

			Vector vecOtherMins, vecOtherMaxs;
			pEntity->GetAbsBounds( &vecOtherMins, &vecOtherMaxs );

			if ( IsBoxIntersectingBox( vecMins, vecMaxs, vecOtherMins, vecOtherMaxs ) )
			{
				OnCollide( pEntity );

				if ( IsSolid() && pEntity->IsSolid() )
				{
					bCanMove = false;
				}
			}
		}
	}

	if ( bCanMove )
		m_vecOrigin = vecNewOrigin;

	// Move the sprite if we have one.
	if ( m_pSprite )
	{
		m_pSprite->setPosition( m_vecOrigin );
		m_pSprite->setRotation( m_flAngle );
	}
}