예제 #1
0
        public void TestMovingEntities()
        {
            GameController ga = new GameController();

            MovingEntity mover = new MovingEntity(ga);

            mover.Rotate(-Math.PI / 4);
            mover.Move(10);
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(mover.Centre.Xd, 7), "Test move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(mover.Centre.Yd, 7), "Test move y");

            Missile m = new Missile(ga, mover.Orientation, new MatrixPoint(0, 0), 1000);
            m.Move(5);

            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(m.Centre.Xd, 7), "Missile move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(m.Centre.Yd, 7), "Missile move y");

            Line trace = m.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(0.0, 7), Math.Round(trace.Point1.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(0.0, 7), Math.Round(trace.Point1.Yd, 7), "Trace move y");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point2.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point2.Yd, 7), "Trace move y");

            m.Move(10);
            trace = m.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point1.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point1.Yd, 7), "Trace move y");
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Yd, 7), "Trace move y");

            m.Move(10);
            trace = m.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point1.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point1.Yd, 7), "Trace move y");
            Assert.AreEqual(Math.Round(3 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(3 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Yd, 7), "Trace move y");

            PlayerVehicle veh1 = new PlayerVehicle(ga);
            Missile miss = new Missile(ga, new Angle(-3.0499999999999972), new MatrixPoint(-7.2369182872595275, 99.435069414788984), 1000);

            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-7.2369182872595275, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(99.435069414788984, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y");
            Assert.AreEqual(Math.Round(-7.2369182872595275, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(99.435069414788984, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 1");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-7.2369182872595275, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(99.435069414788984, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y");
            Assert.AreEqual(Math.Round(-6.3222718999999996, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(89.476986199999999, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 2");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-6.3222718999999996, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(89.476986199999999, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(-5.4076253999999997, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(79.5189029, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 3");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-5.4076253999999997, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(79.5189029, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(-4.4929790000000001, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(69.560819699999996, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 4");

            miss.Move(10);
            miss.Move(10);
            miss.Move(10);
            miss.Move(10);
            miss.Move(10);

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(0.080253099999999994, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(19.7704035, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(0.99489950000000005, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(9.8123202000000003, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.True(miss.DetectProximity(veh1).Collision, "Collison check 5");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(0.99489950000000005, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(9.8123202000000003, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(1.9095458999999999, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(-0.145763, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 6");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(1.9095458999999999, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(-0.145763, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(2.8241923999999998, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(-10.103846300000001, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.True(miss.DetectProximity(veh1).Collision, "Collison check 7");
        }
예제 #2
0
 public void FireMissile()
 {
     Missile m = new Missile(parent, this.Orientation, this.gunTip.Point1, 1000);
 }