Example #1
0
	Vector2D Surface::GetTangentialForceOfGravity( Vector2D velocity, float mass )
	{
		if( _surfaceEdge._point1._x == _surfaceEdge._point2._x )
		{
			/* Surface is vertical, tangential force of acceleration is just gravity */
			return Vector2D( 0, ACCELERATION_OF_GRAVITY );
		}
		else if( _surfaceEdge._point1._y == _surfaceEdge._point2._y )
		{
			/* Surface is horizontal, need to determine whether we hit the top or bottom using angle of velocity */
			if( velocity.Angle() >= 0 && velocity.Angle() <= 180 )
			{
				/* Hit bottom of surface bottom */
				return Vector2D( 0, ACCELERATION_OF_GRAVITY );
			}
			else
			{
				/* Hit top of surface */
				return Vector2D();
			}
		}
		else
		{
			/* Surface is skewed */
			return Vector2D();
		}
	}
Example #2
0
void Ship::Shoot(const Vector2D &direction,
                 const Resource_Projectile_t &projectile, Vector2D offset)
{
    Projectile *p = (Projectile*)GetGameContext()->CreateEntityNoSpawn("projectile");

    Q_ASSERT(p != nullptr);

    float volume = IsPlayer() ? 0.5f : 0.3f;

    offset.Rotate(GetAngle());

    p->SetOwner(this);
    p->Teleport(GetOrigin() + offset);
    p->SetAngle(direction.Angle());
    p->Init(projectile, IsPlayer());
    p->Launch(direction, volume);

    if (projectile.fire_rate > 0.0f)
        shootDelay = GetGameContext()->GetGameTime() + 1.0f / projectile.fire_rate;

    GetGameContext()->SpawnEntity(p);
}