Beispiel #1
0
        public void DeployAttack(SpecialAttack attack)
        {
            var direction = Vector2Extension.AngleToVector2(Rotation);

            attack.Position = Position + direction * Size / 2;

            attack.ApplyForce(direction * attack.MaxSpeed, instantaneous: true);
            ApplyForce(-direction * attack.Mass, instantaneous: true);

            Level.AddEntity(attack);
        }
Beispiel #2
0
        public async Task <bool> FireLaser(CancellationToken cancellation)
        {
            if (MainWeaponAmmo.IsEmpty)
            {
                return(false);
            }

            var direction = Vector2Extension.AngleToVector2(Rotation);

            var laser = new Laser(this, Momentum, Position, direction);

            laser.ApplyAcceleration(direction * laser.MaxSpeed, instantaneous: true);
            ApplyForce(-direction * laser.Mass, instantaneous: true);

            MainWeaponAmmo.Quantity--;
            SoundManager.PlaySound("Shoot01");
            Level.AddEntity(laser);

            await UpdateContext.Delay(MainWeaponDelay);

            return(true);
        }
Beispiel #3
0
        public void Accelerate(GameTime gameTime, float thrust)
        {
#if DEBUG
            if (Math.Abs(thrust) > 1)
            {
                throw new ArgumentOutOfRangeException("thrust", "Thrust must be between -1 and 1.");
            }
#endif
            _accelerating = 0;
            if (Math.Abs(thrust) < 0.1f)
            {
                return;
            }

            var fuelNeeded = (int)(gameTime.ElapsedGameTime.TotalMilliseconds * Math.Abs(thrust));

            if (Fuel.Quantity > fuelNeeded)
            {
                _accelerating  = thrust;
                Fuel.Quantity -= fuelNeeded;
                ApplyForce(Vector2Extension.AngleToVector2(Rotation) * thrust * ThrotleForce);
            }
        }