Example #1
0
        /// <summary>
        /// Constructor for bullet class.
        /// </summary>
        /// <param name="position">Inital position of the bullet.</param>
        /// <param name="velocity">Inital velosity of the bullet.</param>
        /// <param name="drawDirection">Direction to draw the bullet.</param>
        /// <param name="bulletColour">Colour of the bullet</param>
        /// <param name="bulletType">Type of the bullet</param>
        /// <param name="owner">Owner of the bullet</param>
        public BulletEntity(Point2D position, Velocity2D velocity, double drawDirection, BulletColour bulletColour, BulletType bulletType, Entity owner) : base(position, InitaliseBounding(position, bulletColour, bulletType), 1, bulletType.ToString() + bulletColour.ToString())
        {
            _owner         = owner;
            _drawDirection = drawDirection;
            _bulletColour  = bulletColour;
            _bulletType    = bulletType;

            _movement = new VectorMovement(velocity);
        }
        /// <summary>
        /// TrigMovement Constructor, 
        /// </summary>
        /// <param name="amplitude">amlitude of sinusodal movement</param>
        /// <param name="period">period of sinusodal movement</param>
        /// <param name="phase">phase of sinusodal movement</param>
        /// <param name="shift">shift of sinusodal movement</param>
        /// <param name="tick">tick of game object</param>
        /// <param name="delta">velosity to move down path</param>
        /// <param name="direction">overall direction of movement (irrespective of sinusodal movement)</param>
        public TrigMovement(double amplitude, double period, double phase, double shift, uint tick, Velocity2D velocity)
            : base(velocity)
        {
            //Note: wave is in form - amplitude sin(period * tick - phase) + shift
            _amplitude = amplitude;
            _period = period;
            _phase = period;
            _shift = shift;

            //Note: angle of movement is - (amplitude * period cos(period * tick + phase)) + direction
            _angle = (amplitude * period * Math.Cos(period * tick - phase)) + Velocity2D.Velocity.Direction;
        }
        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 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);
            }
        }
        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);
            }
        }
Example #7
0
 /// <summary>
 /// CalculateCartesianDelta,
 /// </summary>
 /// <param name="velocity"></param>
 /// <returns></returns>
 public static Point2D CalculateCartesianDelta(Velocity2D velocity)
 {
     return(new Point2D(velocity.Velocity.Magnitude * Math.Cos(velocity.Velocity.Direction * (Math.PI / 180)), velocity.Velocity.Magnitude * Math.Sin(velocity.Velocity.Direction * (Math.PI / 180))));
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="velocity"></param>
 public Movement(Velocity2D velocity)
 {
     _velocity = velocity;
 }
Example #9
0
        /// <summary>
        /// TrigMovement Constructor,
        /// </summary>
        /// <param name="amplitude">amlitude of sinusodal movement</param>
        /// <param name="period">period of sinusodal movement</param>
        /// <param name="phase">phase of sinusodal movement</param>
        /// <param name="shift">shift of sinusodal movement</param>
        /// <param name="tick">tick of game object</param>
        /// <param name="delta">velosity to move down path</param>
        /// <param name="direction">overall direction of movement (irrespective of sinusodal movement)</param>
        public TrigMovement(double amplitude, double period, double phase, double shift, uint tick, Velocity2D velocity) : base(velocity)
        {
            //Note: wave is in form - amplitude sin(period * tick - phase) + shift
            _amplitude = amplitude;
            _period    = period;
            _phase     = period;
            _shift     = shift;

            //Note: angle of movement is - (amplitude * period cos(period * tick + phase)) + direction
            _angle = (amplitude * period * Math.Cos(period * tick - phase)) + Velocity2D.Velocity.Direction;
        }
 /// <summary>
 /// GravitationalMovement Constructor, sets inital values for velosity and acceleration.
 /// </summary>
 /// <param name="velocity"></param>
 /// <param name="acceleration"></param>
 public GravitationalMovement(Velocity2D velocity, Acceleration2D acceleration)
     : base(velocity)
 {
     _acceleration = acceleration;
 }
 /// <summary>
 /// GravitationalMovement Constructor, sets inital values for velosity and acceleration.
 /// </summary>
 /// <param name="velocity"></param>
 /// <param name="acceleration"></param>
 public GravitationalMovement(Velocity2D velocity, Acceleration2D acceleration) : base(velocity)
 {
     _acceleration = acceleration;
 }