EtherDuels.Game.Model.SimplePhysicsAlgorithm.Update C# (CSharp) Method

Update() public method

Updates gravity effects, calculates the new positions of all world objects and then reports all new collisions to the collisionHandler.
public Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime The GameTime which contains how much time has passed since the last update.
return void
        public void Update(GameTime gameTime)
        {
            worldObjects = world.WorldObjects;

            if (difficulty != configRetriever.Difficulty)
            {
                difficulty = configRetriever.Difficulty;
                UpdateDifficulty();
            }

            UpdateExplosions(gameTime);

            GameTime reducedGameTime = new GameTime(gameTime.TotalGameTime, new TimeSpan(0, 0, 0, 0, 1));
            TimeSpan countingTimeSpan = new TimeSpan(0, 0, 0, 0, 0);
            while (countingTimeSpan < gameTime.ElapsedGameTime)
            {
                countingTimeSpan += reducedGameTime.ElapsedGameTime;
                UpdateGravity(reducedGameTime);
                UpdatePositions(reducedGameTime);
            }

            foreach (Planet planet in world.Planets)
            {
                planet.Rotation += 0.0005f;
            }

            foreach (WorldObject[] collision in GetNewCollisions())
            {
                collisionHandler.OnCollision(collision[0], collision[1]);
            }
        }

Usage Example

        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));
        }
All Usage Examples Of EtherDuels.Game.Model.SimplePhysicsAlgorithm::Update