Example #1
0
void Physics::TestCollision(Circle *a, Circle *b) {
	Vector2D n = (b->GetCentroidPosition() - a->GetCentroidPosition());
	double depth = a->radius + b->radius - n.GetLength();
	if (depth < 0) return;
	n.Normalize();
	constraints.push_back(new Contact(a, b, a->GetCentroidPosition() + n * a->radius, n, depth));
}
Example #2
0
/**
 * Called when Flag is flying to the pole
 */
void CFlag::processFlipping()
{
	if(m_Pos != m_destination)
	{        
        Vector2D<int> dir = m_destination - m_Pos;
        const float length = dir.GetLength();
        Vector2D<float> base_dir( dir.x/length, dir.y/length );

		if( fabs(length) < SPEED )
		{
			moveTo(m_destination);
		}
		else
		{
			moveDir(base_dir*SPEED);
		}
	}
	else
	{
	    setAction(A_FLAG_WAVE);        
	    setActionSprite();
	    g_pSound->playSound( SOUND_FLAG_LAND );
	    
	    const auto episode = gpBehaviorEngine->getEpisode();
        if(episode == 6)
        {
            Vector2D<int> tilePos = m_Pos;

            tilePos.y = getYDownPos();

            Uint32 new_tile_no = mp_Map->getPlaneDataAt(1, tilePos)+1;
            tilePos = tilePos>>CSF;
            mp_Map->setTile(tilePos.x, tilePos.y, new_tile_no, true);
        }
        mp_Map->unlock();
	}
Example #3
0
float Vector2D::Distance(const Vector2D & v) const
{
	Vector2D mag = v - *this;
	return mag.GetLength();
}