public void UpdateControls()
    {
        UpdateThrust();
        UpdateTurn();

        void UpdateThrust()
        {
            if (thrusting)
            {
                var rotationRads = rotationDegrees * Math.PI / 180;

                Velocity += XY.Polar(rotationRads, thrust);
                thrusting = false;
                fuel--;
            }
        }

        void UpdateTurn()
        {
            if (rotating != Rotating.None)
            {
                if (rotating == Rotating.CCW)
                {
                    rotationDegrees += turningSpeed;
                }
                else if (rotating == Rotating.CW)
                {
                    rotationDegrees -= turningSpeed;
                }
                rotating = Rotating.None;
            }
        }
    }
示例#2
0
    public void Interact(Projectile other)
    {
        if (other.source != owner)
        {
            return;
        }
        if (cloned.Contains(other))
        {
            return;
        }
        cloned.Add(other);

        //other.velocity = other.velocity.WithMagnitude(400);
        var world = owner.world;

        Clone(offset.angleRad + Math.PI / 8);
        Clone(offset.angleRad - Math.PI / 8);
        Clone(offset.angleRad + Math.PI * 2 / 8);
        Clone(offset.angleRad - Math.PI * 2 / 8);
        Clone(offset.angleRad + Math.PI * 3 / 8);
        Clone(offset.angleRad - Math.PI * 3 / 8);

        /*
         * for(double angle = offset.angleRad - Math.PI / 2; angle = offset.angleRad + Math.PI / 2; angle++) {
         *
         * }
         */


        void Clone(double angle)
        {
            var velocity = other.velocity + XY.Polar(angle, other.velocity.magnitude / 2);
            var p        = new Projectile(other.source, other.fragment, other.position, velocity, angle, other.maneuver);

            cloned.Add(p);
            world.AddEntity(p);
        }

        return;
    }
        public void UpdateControls()
        {
            UpdateThrust();
            UpdateTurn();

            void UpdateThrust()
            {
                if (thrusting)
                {
                    var rotationRads = rotationDegrees * Math.PI / 180;

                    var exhaust = new EffectParticle(Position + XY.Polar(rotationRads, -1),
                                                     Velocity + XY.Polar(rotationRads, -thrust),
                                                     new ColoredGlyph(Color.Yellow, Color.Transparent, '.'),
                                                     4);
                    World.AddEffect(exhaust);

                    Velocity += XY.Polar(rotationRads, thrust);
                    thrusting = false;
                }
            }

            void UpdateTurn()
            {
                if (rotating != Rotating.None)
                {
                    if (rotating == Rotating.CCW)
                    {
                        rotationDegrees += turningSpeed;
                    }
                    else if (rotating == Rotating.CW)
                    {
                        rotationDegrees -= turningSpeed;
                    }
                    rotating = Rotating.None;
                }
            }
        }
    public override void Render(TimeSpan drawTime)
    {
        this.Clear();
        int top = Height - 1;

        void Draw(int x, int y, ColoredGlyph symbol)
        {
            this.SetCellAppearance(x, top - y, symbol);
        }

        foreach (var cloud in clouds)
        {
            var(x, y) = cloud.pos;
            Draw(x, y, cloud.symbol);
        }

        var pos = playership.Position.clone;

        Draw(pos.xi, pos.yi, playership.Tile);

        if (playership.thrusting)
        {
            var p = pos + XY.Polar(playership.rotationDegrees * Math.PI / 180, -1);
            Draw(p.xi, p.yi, new ColoredGlyph(Color.Yellow, Color.Transparent, '.'));
        }

        for (int i = 0; i < 10; i++)
        {
            pos += XY.Polar(playership.rotationDegrees * Math.PI / 180, 1);
            Draw(pos.xi, pos.yi, new ColoredGlyph(Color.White, Color.Transparent, '.'));
        }

        this.Print(1, 1, $"{new string('=', playership.fuel / 15)}");

        base.Render(drawTime);
    }