コード例 #1
0
ファイル: WorldTests.cs プロジェクト: polly5315/NBump
        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
ファイル: WorldTests.cs プロジェクト: polly5315/NBump
        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
ファイル: WorldTests.cs プロジェクト: polly5315/NBump
        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);
        }