示例#1
0
        public Vector2D(Point2D a, Point2D b)
        {
            double i = (a - b).X;
            double j = (a - b).Y;

            this.Magnitude = Math.Sqrt(i * i + j * j);
            this.Direction = Math.Atan2(i, j) * (180 / Math.PI);
        }
 public void Offset(Vector2D vector)
 {
     for(int i = 0; i < Vertices.Count; ++i)
     {
         Point2D vertex = Vertices[i];
         Vertices[i] = new Point2D(vertex.X + vector.i, vertex.Y + vector.j);
     }
 }
示例#3
0
        /// <summary>
        /// Entity Constructor, sets the inital values for entity details.
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="hitboxes"></param>
        /// <param name="hitpoints"></param>
        /// <param name="point"></param>
        public Entity(Point2D point, List<Bounding> hitboxes, uint hitpoints, string bitmap)
        {
            _position = point;
            _hitboxes = hitboxes;
            _hitpoints = hitpoints;
            _bitmap = bitmap;

            Tick = 0;
        }
        /// <summary>
        /// ItemEntity Constructor, initalises item.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="itemType"></param>
        public ItemEntity(Point2D point, ItemType itemType)
            : base(point, InitaliseBounding(point, itemType), 1, "Item" + itemType.ToString())
        {
            _itemType = itemType;

            _movement = new GravitationalMovement(new Velocity2D(-3.0, 90.0), new Acceleration2D(new Vector2D(0, 0.1), 1.8));
            _flagMovement = new VectorMovement(new Velocity2D(5.0, 90.0));

            _flag = _itemType == UnrealMechanismCS.ItemType.Star;
        }
        public static List<Bounding> InitaliseBounding(Point2D point, ItemType itemType)
        {
            List<Bounding> result = new List<Bounding>();

            result.Add(new Bounding(new Point2D[]
            {
                new Point2D(point.X + GameResources.GameImage("Item" + itemType.ToString()).Width,point.Y - GameResources.GameImage("Item" + itemType.ToString()).Height),
                new Point2D(point.X - GameResources.GameImage("Item" + itemType.ToString()).Width,point.Y - GameResources.GameImage("Item" + itemType.ToString()).Height),
                new Point2D(point.X - GameResources.GameImage("Item" + itemType.ToString()).Width,point.Y + GameResources.GameImage("Item" + itemType.ToString()).Height),
                new Point2D(point.X + GameResources.GameImage("Item" + itemType.ToString()).Width,point.Y + GameResources.GameImage("Item" + itemType.ToString()).Height)
            }));

            return result;
        }
        public static List<Bounding> InitaliseBounding(Point2D point)
        {
            List<Bounding> result = new List<Bounding>();

            result.Add(new Bounding(new Point2D[]
            {
                new Point2D(point.X + 2, point.Y - 2),
                new Point2D(point.X - 2, point.Y - 2),
                new Point2D(point.X - 2, point.Y + 2),
                new Point2D(point.X + 2, point.Y + 2)
            }));

            return result;
        }
        public Polygon2D(Point2D[] vertices)
        {
            Vertices = new List<Point2D>(vertices);

            Edges = new List<Vector2D>();

            for (int i = 0; i < Vertices.Count; ++i)
            {
                if (i == Vertices.Count - 1)
                {
                    Edges.Add(new Vector2D(Vertices[i], Vertices[0]));
                }
                else
                {
                    Edges.Add(new Vector2D(Vertices[i], Vertices[i + 1]));
                }
            }
        }
        public void TestVectorMovement()
        {
            Velocity2D testVelosity = new Velocity2D(5.0, 36.86989764584402);
            Movement testMovement = new VectorMovement(testVelosity);
            Point2D testPoint = new Point2D(0.0, 0.0);

            double[] expectedX = new double[] { 4.0, 8.0, 12.0, 16.0, 20.0, 24.0, 28.0, 32.0, 36.0, 40.0 };
            double[] expectedY = new double[] { 3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0, 27.0, 30.0 };

            for (int i = 0; i < 10; i++)
            {
                testMovement.Step();

                testPoint.X += testMovement.DeltaX;
                testPoint.Y += testMovement.DeltaY;

                Assert.AreEqual(expectedX[i], testPoint.X, "failure with x on iteration " + i);
                Assert.AreEqual(expectedY[i], testPoint.Y, "failure with y on iteration " + i);
            }
        }
        public void TestGravitationalMovement()
        {
            Acceleration2D testAcceleration = new Acceleration2D(new Vector2D(5.0, 0.0), 200.0);
            Velocity2D testVelosity = new Velocity2D(5.0, 36.86989764584402);
            Movement testMovement = new GravitationalMovement(testVelosity, testAcceleration);
            Point2D testPoint = new Point2D(0.0, 0.0);

            double[] expectedX = new double[] { 8.0, 20.0, 36.0, 56.0, 80.0, 108.0, 140.0, 176.0, 216.0, 260.0 };
            double[] expectedY = new double[] { 6.0, 15.0, 27.0, 42.0, 60.0, 81.0, 105.0, 132.0, 162.0, 195.0 };

            for (int i = 0; i < 10; i++)
            {
                testMovement.Step();

                testPoint.X += testMovement.DeltaX;
                testPoint.Y += testMovement.DeltaY;

                Assert.AreEqual(expectedX[i], testPoint.X, "failure with x on iteration " + i);
                Assert.AreEqual(expectedY[i], testPoint.Y, "failure with y on iteration " + i);
            }
        }
示例#10
0
 public void Offset(Point2D point)
 {
     for (int i = 0; i < Vertices.Count; ++i)
     {
         Point2D vertex = Vertices[i];
         Vertices[i] = new Point2D(vertex.X + point.X, vertex.Y + point.Y);
     }
 }
        public static void ProcessPlayer()
        {
            _player.ProcessEvents();

            if (_player.Hitpoints == 0)
            {
                Point2D pnt = new Point2D(270, 430);
                GameScores.Player -= 1;

                _player.Position = pnt;

                Point2D[] point = new Point2D[]
                {
                    new Point2D(-2,-6),
                    new Point2D(0, 0)
                };

                for (int i = 0; i < _player.Hitboxes.Count; ++i)
                {
                    _player.Hitboxes[i].Offset(pnt);
                }
            }
            _player.Hitpoints = 1;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="a">Point a.</param>
 /// <param name="b">Point b.</param>
 /// <returns></returns>
 public double CalculateDistanceBetweenPoints(Point2D a, Point2D b)
 {
     return Math.Sqrt((b.X - a.X) + (b.Y - a.Y));
 }
 /// <summary>
 /// CalculateAmplitude Method, calculates and returns the amplitude based on a pair of points.
 /// </summary>
 /// <param name="a">Point a.</param>
 /// <param name="b">Point b.</param>
 /// <returns>Amplitude based on coordinates (half the distance between points).</returns>
 public double CalculateAmplitude(Point2D a, Point2D b)
 {
     return CalculateDistanceBetweenPoints(a, b) / 2;
 }
示例#14
0
 public void Offset(Point2D point)
 {
     _position = new Point2D(_position.X + point.X, _position.Y + point.Y);
 }
示例#15
0
 public void Offset(Vector2D vector)
 {
     _position = new Point2D(_position.X + vector.i, _position.Y + vector.j);
 }
示例#16
0
 public double Dot(Point2D vector)
 {
     return Magnitude * Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y) * Math.Cos(Direction - Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y));
 }