Exemplo n.º 1
0
        /// <summary>
        /// ProcessMovement, overide method, determines item movement.
        /// </summary>
        public override void ProcessMovement()
        {
            if (_itemType == ItemType.Star)
            {
                _vectorMovement.Step();

                _vectorMovement.SetDirection(GameObjects.Player.X, GameObjects.Player.Y, X, Y);

                X += _vectorMovement.DeltaX;
                Y += _vectorMovement.DeltaY;

                foreach (HitBox hitBox in HitBoxes)
                {
                    hitBox.X += _vectorMovement.DeltaX;
                    hitBox.Y += _vectorMovement.DeltaY;
                }
            }
            else
            {
                _gravMovement.Step();

                X += _gravMovement.DeltaX;
                Y += _gravMovement.DeltaY;

                foreach (HitBox hitBox in HitBoxes)
                {
                    hitBox.X += _gravMovement.DeltaX;
                    hitBox.Y += _gravMovement.DeltaY;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// ProcessMovement Method, steps items through their movement patterns
        /// </summary>
        public override void ProcessMovement()
        {
            switch (_flag)
            {
            case true:
                _flagMovement.Step();

                _flagMovement.SetDirection(GameObjects.Player.Position, this.Position);

                X += _flagMovement.DeltaX;
                Y += _flagMovement.DeltaY;

                foreach (Bounding hitBox in Hitboxes)
                {
                    hitBox.Offset(_flagMovement.Delta);
                }
                break;

            case false:
                _movement.Step();

                X += _movement.DeltaX;
                Y += _movement.DeltaY;

                foreach (Bounding hitBox in Hitboxes)
                {
                    hitBox.Offset(_movement.Delta);
                }
                break;
            }
        }
Exemplo n.º 3
0
        public void TestGravitationalMovement()
        {
            //inital delta = 0, acceleration = 1 unit/tick^2, terminal velosity = 10 units/tick
            Movement testMovement = new GravitationalMovement(0.0, 0.0, 1.0, 0.0, 10.0, 0.0);

            testMovement.Step();

            double x = 0;
            double y = 0;

            double[] expectedX = new double[] { 2.0, 5.0, 9.0, 14.0, 20.0, 27.0, 35.0, 44.0, 54.0, 64.0 };
            double[] expectedY = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

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

                x += testMovement.DeltaX;
                y += testMovement.DeltaY;

                Assert.AreEqual(expectedX[i], x, "failure with x on iteration " + i);
                Assert.AreEqual(expectedY[i], y, "failure with y on iteration " + i);
            }
        }
        public void TestGravitationalMovement()
        {
            //inital delta = 0, acceleration = 1 unit/tick^2, terminal velosity = 10 units/tick
            Movement testMovement = new GravitationalMovement(0.0, 0.0, 1.0, 0.0, 10.0, 0.0);

            testMovement.Step();

            double x = 0;
            double y = 0;

            double[] expectedX = new double[] { 2.0, 5.0, 9.0, 14.0, 20.0, 27.0, 35.0, 44.0, 54.0, 64.0 };
            double[] expectedY = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

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

                x += testMovement.DeltaX;
                y += testMovement.DeltaY;

                Assert.AreEqual(expectedX[i], x, "failure with x on iteration " + i);
                Assert.AreEqual(expectedY[i], 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);
            }
        }
        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);
            }
        }