示例#1
0
        public void LeavingTheObstacle()
        {
            var obstaclePosition = new Vector2(0, 0);
            var obstacleSize = new Vector2(1, 1);
            var bulletPosition = new Vector2(0.5f, 0);
            var bulletSize = new Vector2(1, 1);
            var path = new Vector2(1, 0);

            //Arrange
            var world = WorldFactory.CreateWorld();
            var bullet = new Body(bulletPosition, bulletSize);
            var expectedObstacle = new Body(obstaclePosition, obstacleSize);
            world.Add(expectedObstacle);

            //Act
            var actualMulticollisionEvent = world.GetCollisions(bullet, path).Single();

            //Assert
            Assert.IsNotNull(actualMulticollisionEvent);
            Assert.AreEqual(1, actualMulticollisionEvent.Collisions.Count);
            Assert.AreEqual((bulletPosition.X - obstaclePosition.X) / path.X, actualMulticollisionEvent.Traversed);
            var collision = actualMulticollisionEvent.Collisions.Single();
            var actualObstacle = collision.Bodies.Single();
            Assert.AreEqual(expectedObstacle, actualObstacle);
            Assert.AreEqual(CollisionType.Leaving, collision.Type);
            Assert.AreEqual(Direction.Right, collision.NormalDirection);
        }
示例#2
0
        public void EnteringIntoObstacle()
        {
            const float distance = 10;
            var bulletPosition = new Vector2(0, 0);
            var bulletSize = new Vector2(1, 1);
            var obstaclePosition = new Vector2(bulletPosition.X + bulletSize.X + distance, 0);
            var obstacleSize = new Vector2(1, 1);
            var path = new Vector2(distance + obstacleSize.X/2, 0);

            //Arrange
            var world = WorldFactory.CreateWorld();
            var bullet = new Body(bulletPosition, bulletSize);
            var expectedObstacle = new Body(obstaclePosition, obstacleSize);
            world.Add(expectedObstacle);

            //Act
            var actualMulticollisionEvent = world.GetCollisions(bullet, path).Single();

            //Assert
            Assert.IsNotNull(actualMulticollisionEvent);
            Assert.AreEqual(1, actualMulticollisionEvent.Collisions.Count);
            Assert.AreEqual(distance / path.X, actualMulticollisionEvent.Traversed);
            var collision = actualMulticollisionEvent.Collisions.Single();
            var actualObstacle = collision.Bodies.Single();
            Assert.AreEqual(expectedObstacle, actualObstacle);
            Assert.AreEqual(CollisionType.Entering, collision.Type);
            Assert.AreEqual(Direction.Left, collision.NormalDirection);
        }
示例#3
0
        public void PassingThroughObstacle()
        {
            const float distance = 10;
            var bulletPosition = new Vector2(0, 0);
            var bulletSize = new Vector2(1, 1);
            var obstaclePosition = new Vector2(bulletPosition.X + bulletSize.X + distance, 0);
            var obstacleSize = new Vector2(1, 1);
            var path = new Vector2(distance + obstacleSize.X + bulletSize.X, 0);

            //Arrange
            var world = WorldFactory.CreateWorld();
            var bullet = new Body(bulletPosition, bulletSize);
            var expectedObstacle = new Body(obstaclePosition, obstacleSize);
            world.Add(expectedObstacle);

            //Act
            var actualMulticollisionEvents = world.GetCollisions(bullet, path).ToArray();

            //Assert
            Assert.AreEqual(2, actualMulticollisionEvents.Length);
            var enteringEvent = actualMulticollisionEvents[0];
            var leavingEvent = actualMulticollisionEvents[1];

            Assert.AreEqual(distance / path.X, enteringEvent.Traversed);
            var collision = enteringEvent.Collisions.Single();
            var actualObstacle = collision.Bodies.Single();
            Assert.AreEqual(expectedObstacle, actualObstacle);
            Assert.AreEqual(CollisionType.Entering, collision.Type);
            Assert.AreEqual(Direction.Left, collision.NormalDirection);

            Assert.AreEqual((distance + bulletSize.X + obstacleSize.X) / path.X, leavingEvent.Traversed);
            collision = leavingEvent.Collisions.Single();
            actualObstacle = collision.Bodies.Single();
            Assert.AreEqual(expectedObstacle, actualObstacle);
            Assert.AreEqual(CollisionType.Leaving, collision.Type);
            Assert.AreEqual(Direction.Right, collision.NormalDirection);
        }