Beispiel #1
0
        public bool Shoot(Vector2 position, Vector2 velocity, float angle)
        {
            if (cyclesSinceShot < Constants.ShotDeltaCycles)
            {
                return(false);
            }

            cyclesSinceShot = 0;

            MyPointF shotPoint = new MyPointF(Constants.ShotVelocity, 0f);

            MyPointF rotatedPoint = shotPoint.Rotate(angle);
            Vector2  shotVelocity = new Vector2(rotatedPoint.X, rotatedPoint.Y);

            if (Constants.ShotAddShipVelocity)
            {
                shotVelocity += velocity;
            }

            foreach (Shot shot in shots)
            {
                if (!shot.Alive)
                {
                    shot.SetShot(position, shotVelocity);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        public void SetThrust(bool thrust)
        {
            SetFlame(thrust);

            if (thrust && (state == ShipState.Normal))
            {
                float angle = outline.Angle + 90f;

                double angleInRadians = angle * (Math.PI / 180.0f);

                MyPointF acceleration = new MyPointF(Constants.EngineThrust, 0f);
                acceleration = acceleration.Rotate(angle);


                velocity += new Vector2(acceleration.X, acceleration.Y);

                sounds |= Sounds.ShipThrust;
            }
            else
            {
                if ((sounds & Sounds.ShipThrust) != 0)
                {
                    sounds ^= Sounds.ShipThrust;
                }
            }
        }
 // add a line at all the rotations
 public static void AddLine(MyPointF end1, MyPointF end2, float scale)
 {
     float angleIncrement = 360f / Constants.RotateSteps;
     float angle = 0.0f;
     for (int step = 0; step < Constants.RotateSteps; step++) {
         Shape shape = (Shape) shapes[step];
         shape.AddLine(end1.Rotate(angle), end2.Rotate(angle), scale);
         angle += angleIncrement;
     }
 }
Beispiel #4
0
        // add a line at all the rotations
        public static void AddLine(MyPointF end1, MyPointF end2, float scale)
        {
            float angleIncrement = 360f / Constants.RotateSteps;
            float angle          = 0.0f;

            for (int step = 0; step < Constants.RotateSteps; step++)
            {
                Shape shape = (Shape)shapes[step];
                shape.AddLine(end1.Rotate(angle), end2.Rotate(angle), scale);
                angle += angleIncrement;
            }
        }
Beispiel #5
0
        static Ship()
        {
            // outline of the ship, with 3 flames...
            MyPointF pointNose  = new MyPointF(0f, 4f);
            MyPointF pointRight = new MyPointF(2f, -2f);
            MyPointF pointLeft  = new MyPointF(-2f, -2f);
            MyPointF flameBase  = new MyPointF(0f, -2f);
            MyPointF flameEnd1  = new MyPointF(0f, -4f);
            MyPointF flameEnd2  = new MyPointF(0.5f, -4f);
            MyPointF flameEnd3  = new MyPointF(-0.5f, -4f);

            RotatableShape.AddLine(pointNose, pointRight, Constants.ShipSize);
            RotatableShape.AddLine(pointNose, pointLeft, Constants.ShipSize);
            RotatableShape.AddLine(pointLeft, pointRight, Constants.ShipSize);
            RotatableShape.AddLine(flameBase, flameEnd1, Constants.ShipSize);
            RotatableShape.AddLine(flameBase, flameEnd2, Constants.ShipSize);
            RotatableShape.AddLine(flameBase, flameEnd3, Constants.ShipSize);
        }
        private int waitCount = 10; // wait count before state transition.

        #endregion Fields

        #region Constructors

        static Ship()
        {
            // outline of the ship, with 3 flames...
            MyPointF pointNose = new MyPointF(0f, 4f);
            MyPointF pointRight = new MyPointF(2f, -2f);
            MyPointF pointLeft = new MyPointF(-2f, -2f);
            MyPointF flameBase = new MyPointF(0f, -2f);
            MyPointF flameEnd1 = new MyPointF(0f, -4f);
            MyPointF flameEnd2 = new MyPointF(0.5f, -4f);
            MyPointF flameEnd3 = new MyPointF(-0.5f, -4f);

            RotatableShape.AddLine(pointNose, pointRight, Constants.ShipSize);
            RotatableShape.AddLine(pointNose, pointLeft, Constants.ShipSize);
            RotatableShape.AddLine(pointLeft, pointRight, Constants.ShipSize);
            RotatableShape.AddLine(flameBase, flameEnd1, Constants.ShipSize);
            RotatableShape.AddLine(flameBase, flameEnd2, Constants.ShipSize);
            RotatableShape.AddLine(flameBase, flameEnd3, Constants.ShipSize);
        }
        public bool Shoot(Vector2 position, Vector2 velocity, float angle)
        {
            if (cyclesSinceShot < Constants.ShotDeltaCycles)
                return false;

            cyclesSinceShot = 0;

            MyPointF shotPoint = new MyPointF(Constants.ShotVelocity, 0f);

            MyPointF rotatedPoint = shotPoint.Rotate(angle);
            Vector2 shotVelocity = new Vector2(rotatedPoint.X,rotatedPoint.Y);
            if (Constants.ShotAddShipVelocity) {
                shotVelocity += velocity;
            }

            foreach (Shot shot in shots) {
                if (!shot.Alive) {
                    shot.SetShot(position, shotVelocity);
                    return true;
                }
            }
            return false;
        }
 public static float Distance(MyPointF pt1, MyPointF pt2)
 {
     MyPointF delta = pt1 - pt2;
     return (float) Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y);
 }
Beispiel #9
0
        public static float Distance(MyPointF pt1, MyPointF pt2)
        {
            MyPointF delta = pt1 - pt2;

            return((float)Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y));
        }
        public void SetThrust(bool thrust)
        {
            SetFlame(thrust);

            if (thrust && (state == ShipState.Normal)) {

                float angle = outline.Angle + 90f;

                double angleInRadians = angle * (Math.PI / 180.0f);

                MyPointF acceleration = new MyPointF(Constants.EngineThrust, 0f);
                acceleration = acceleration.Rotate(angle);

                velocity += new Vector2(acceleration.X,acceleration.Y);

                sounds |= Sounds.ShipThrust;

            }
            else {
                if ((sounds & Sounds.ShipThrust) != 0)
                    sounds ^= Sounds.ShipThrust;
            }
        }