public Update ( |
||
gameTime | The GameTime which contains how much time has passed since the last update. | |
return | void |
public void UpdateCollisionTest() { WorldObject object1 = new WorldObject(); object1.Position = new Vector2(0.0f, 0.0f); object1.Radius = 0.51f; WorldObject object2 = new WorldObject(); object2.Position = new Vector2(0.0f, 1.0f); object2.Radius = 0.5f; WorldObject object3 = new WorldObject(); object3.Position = new Vector2(200, 200); object3.Radius = 0.3f; WorldObject object4 = new WorldObject(); object4.Position = new Vector2(200, 201); object4.Radius = 0.8f; WorldObject object5 = new WorldObject(); object5.Position = new Vector2(200, 200.5f); object5.Radius = 0.1f; world.AddWorldObject(object1); world.AddWorldObject(object2); mockCollisionHandler.Setup(m => m.OnCollision(object1, object2)); target = new SimplePhysicsAlgorithm(mockCollisionHandler.Object, world, configuration); target.Update(new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 1))); world.AddWorldObject(object3); world.AddWorldObject(object4); world.AddWorldObject(object5); target.Update(new GameTime(new TimeSpan(0, 0, 10, 3, 1), new TimeSpan(0, 0, 0, 0, 1))); mockCollisionHandler.Verify(m => m.OnCollision(object1, object2), Times.Exactly(1)); mockCollisionHandler.Verify(m => m.OnCollision(object3, object4), Times.Exactly(1)); mockCollisionHandler.Verify(m => m.OnCollision(object4, object5), Times.Exactly(1)); }
public void UpdateDifficultyTest() { Mock<ConfigurationRetriever> mockConfRet = new Mock<ConfigurationRetriever>(); mockConfRet.SetupGet(m => m.Difficulty).Returns(1); // set up a big planet Planet bigPlanet = new Planet(); bigPlanet.IsFlexible = false; bigPlanet.Position = new Vector2(0, 0); bigPlanet.Radius = 300; world.AddWorldObject(bigPlanet); // set up a small planet float desiredDistance = 700; Planet smallPlanet = new Planet(); smallPlanet.IsFlexible = true; smallPlanet.Position = new Vector2(desiredDistance, 0); // calculate velocity needed to circuit in orbit float smallPlanetVelocity = (float)Math.Sqrt(bigPlanet.Mass * G / desiredDistance / (N * 1000)); smallPlanet.Velocity = new Vector2(0, smallPlanetVelocity); smallPlanet.Radius = 150; world.AddWorldObject(smallPlanet); target = new SimplePhysicsAlgorithm(mockCollisionHandler.Object, world, mockConfRet.Object); target.Update(new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 5, 10))); // check whether the distance between the planets is still about the same float distance = Vector2.Distance(bigPlanet.Position, smallPlanet.Position); Assert.IsTrue(distance <= desiredDistance + 30); }
public void UpdateMaxSpeedTest() { float MAX_VELOCITY = 299792458.0f; // create worldObjects with different speeds WorldObject worldObject1 = new WorldObject(); worldObject1.Position = new Vector2(0.0f, 0.0f); worldObject1.Velocity = new Vector2(MAX_VELOCITY + 5.0f, MAX_VELOCITY + 1.0f); world.AddWorldObject(worldObject1); WorldObject worldObject2 = new WorldObject(); worldObject2.Position = new Vector2(200, 200); worldObject2.Velocity = Vector2.One; world.AddWorldObject(worldObject2); WorldObject worldObject3 = new WorldObject(); worldObject3.Position = new Vector2(-13.0f, 80.0f); /* a² + b² = c² * a = 50 * b = Sqrt(MAX_VELOCITY² - 50²) * */ worldObject3.Velocity = new Vector2(50, (float) Math.Sqrt(MAX_VELOCITY * MAX_VELOCITY - 50 * 50)); world.AddWorldObject(worldObject3); planet.Mass = 0.0; Vector2 expectedVelocity1 = worldObject1.Velocity; expectedVelocity1.Normalize(); expectedVelocity1 *= MAX_VELOCITY; Vector2 expectedVelocity2 = worldObject2.Velocity; Vector2 expectedVelocity3 = worldObject3.Velocity; target = new SimplePhysicsAlgorithm(mockCollisionHandler.Object, world, configuration); target.Update(new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 1))); Assert.AreEqual(worldObject1.Velocity, expectedVelocity1); Assert.AreEqual(worldObject2.Velocity, expectedVelocity2); Assert.AreEqual(worldObject3.Velocity, expectedVelocity3); }
public void UpdateDeleteExplosionTest() { // create explosions Explosion explosion1 = new Explosion(); Explosion explosion2 = new Explosion(); Explosion explosion3 = new Explosion(); explosion1.Health = 100; explosion2.Health = 100; explosion3.Health = 100; explosion1.CreationTime = new TimeSpan(0, 0, 0, 0, 1); // should be destroyed at (0, 0, 0, 0, 100) explosion2.CreationTime = new TimeSpan(0, 0, 0, 0, 250); // should be destroyed at (0, 0, 0, 0, 351) explosion3.CreationTime = new TimeSpan(0, 0, 0, 0, 34); // should be destroyed at (0, 0, 0, 0, 135) // create a mock world Mock<World> mockWorld = new Mock<World>(); WorldObject[] worldObjects = { explosion1, explosion2, explosion3 }; mockWorld.SetupGet(m => m.WorldObjects).Returns(worldObjects); mockWorld.Setup(m => m.RemoveWorldObject(explosion1)); mockWorld.Setup(m => m.RemoveWorldObject(explosion3)); // create target and call update target = new SimplePhysicsAlgorithm(mockCollisionHandler.Object, mockWorld.Object, configuration); target.Update(new GameTime(new TimeSpan(0, 0, 0, 0, 135), new TimeSpan(0, 0, 0, 0, 1))); // explosions 1 and 3 should be destroyed, explosion 2 should still be there Assert.IsTrue(explosion1.Health <= 0); Assert.IsTrue(explosion2.Health > 0); Assert.IsTrue(explosion3.Health <= 0); mockWorld.Verify(m => m.RemoveWorldObject(explosion1), Times.Exactly(1)); mockWorld.Verify(m => m.RemoveWorldObject(explosion3), Times.Exactly(1)); }