Пример #1
0
        public void SimulateWorld()
        {
            /*simulationPlayer.Velocity = new Vector2f(0.5f, 1.0f);
             * if (simulationPlayer.BoundingBox.Position.X > 250.0f || simulationPlayer.BoundingBox.Position.Y > 250.0f)
             * {
             *  simulationPlayer.BoundingBox.Position = new Vector2f(70.5f, 60.5f);
             * }*/

            if (SFML.Window.Keyboard.IsKeyPressed(Keyboard.Key.W))
            {
                simulationPlayer.Velocity = new Vector2f(simulationPlayer.Velocity.X, -0.5f);
            }
            else if (SFML.Window.Keyboard.IsKeyPressed(Keyboard.Key.S))
            {
                simulationPlayer.Velocity = new Vector2f(simulationPlayer.Velocity.X, 0.5f);
            }
            else
            {
                simulationPlayer.Velocity = new Vector2f(simulationPlayer.Velocity.X, 0.0f);
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                simulationPlayer.Velocity = new Vector2f(0.5f, simulationPlayer.Velocity.Y);
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                simulationPlayer.Velocity = new Vector2f(-0.5f, simulationPlayer.Velocity.Y);
            }
            else
            {
                simulationPlayer.Velocity = new Vector2f(0.0f, simulationPlayer.Velocity.Y);
            }

            //center the player
            if (Keyboard.IsKeyPressed(Keyboard.Key.I))
            {
                simulationPlayer.Velocity = new Vector2f(79.5f - simulationPlayer.BoundingBox.Position.X, 59.5f - simulationPlayer.BoundingBox.Position.Y);
                simulationPlayer.Move();
                simulationPlayer.Velocity = new Vector2f();
            }

            Vector2f tempPosition = simulationPlayer.BoundingBox.Position + simulationPlayer.Velocity;
            Vector2f testVector   = new Vector2f(80.0f, 99.5f);

            if (tempPosition.X == testVector.X && tempPosition.Y == testVector.Y)
            {
                int i = 0;
            }

            //Gravity
            //simulationPlayer.Velocity = new Vector2f(simulationPlayer.Velocity.X, simulationPlayer.Velocity.Y + 0.5f);

            foreach (CollisionObject collisionObject in simulatedObjects)
            {
                collisionObject.RevertToOriginalColor();
            }

            //Reset the colors and figure out collisions

            /*for ( int i = 0; i < simulatedObjects.Count; i++ )
             * {
             *  CollisionObject collisionObject = simulatedObjects[i];
             *  for (int z = i + 1; z < simulatedObjects.Count; z++)
             *  {
             *      CollisionObject otherObject = simulatedObjects[z];
             *
             *      CollisionResults collisionResults = CollisionManager.TestCollisions(collisionObject, otherObject);
             *
             *      if (collisionResults.Type != CollisionType.enNone)
             *      {
             *          collisionObject.OnCollision(collisionResults);
             *          otherObject.OnCollision(collisionResults);
             *      }
             *  }
             * }*/

            foreach (CollisionObject collisionObject in simulatedObjects)
            {
                if (collisionObject == simulationPlayer)
                {
                    continue;
                }

                CollisionResults results = CollisionManager.TestCollisions(simulationPlayer, collisionObject);

                if (results.Type != CollisionType.enNone)
                {
                    simulationPlayer.OnCollision(results);
                    collisionObject.OnCollision(results);
                }
            }

            //Process collisions
            foreach (CollisionObject collisionObject in simulatedObjects)
            {
                collisionObject.ProcessCollisions();
            }

            //Draw the objects.
            foreach (CollisionObject collisionObject in simulatedObjects)
            {
                collisionObject.Move();
                window.Draw(collisionObject);
            }

            foreach (CollisionObject collisionObject in simulatedObjects)
            {
                if (collisionObject == simulationPlayer)
                {
                    continue;
                }

                CollisionResults results = CollisionManager.TestCollisions(simulationPlayer, collisionObject);

                if (results.Type == CollisionType.enAbsolute)
                {
                    int i = 0;
                }
            }

            foreach (CollisionObject collisionObject in simulatedObjects)
            {
                collisionObject.PostFrame();
            }
        }