public void TestSupport() { // We need an actual world for this var world = new TrueCraft.Core.World.World("test", new FlatlandGenerator()); world.SetBlockID(Coordinates3D.Zero, 1); world.SetBlockID(Coordinates3D.OneY, 2); var blockProvider = new Mock<BlockProvider> { CallBase = true }; var updated = new BlockDescriptor { ID = 2, Coordinates = Coordinates3D.Up }; var source = new BlockDescriptor { ID = 2, Coordinates = Coordinates3D.Right }; blockProvider.Setup(b => b.GetSupportDirection(It.IsAny<BlockDescriptor>())).Returns(Coordinates3D.Down); var supportive = new Mock<IBlockProvider>(); supportive.SetupGet(p => p.Opaque).Returns(true); var unsupportive = new Mock<IBlockProvider>(); unsupportive.SetupGet(p => p.Opaque).Returns(false); BlockRepository.Setup(r => r.GetBlockProvider(It.Is<byte>(b => b == 1))).Returns(supportive.Object); BlockRepository.Setup(r => r.GetBlockProvider(It.Is<byte>(b => b == 3))).Returns(unsupportive.Object); blockProvider.Object.BlockUpdate(updated, source, Server.Object, world); World.Verify(w => w.SetBlockID(Coordinates3D.OneY, 0), Times.Never); world.SetBlockID(Coordinates3D.Zero, 3); blockProvider.Object.BlockUpdate(updated, source, Server.Object, world); Assert.AreEqual(0, world.GetBlockID(Coordinates3D.OneY)); EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 2))); }
public void TestAdjacentFall() { // Tests an entity that falls alongside a wall var repository = GetBlockRepository(); var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator()); var physics = new PhysicsEngine(world, repository); var entity = new TestEntity(); entity.Position = new Vector3(0, 10, 0); entity.AccelerationDueToGravity = 1; physics.AddEntity(entity); // Create a wall for (int y = 0; y < 12; y++) { world.SetBlockID(new Coordinates3D(1, y, 0), StoneBlock.BlockID); } // Test physics.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual(9, entity.Position.Y); Assert.IsFalse(entity.CollisionOccured); }
public void TestSupport() { // We need an actual world for this var world = new TrueCraft.Core.World.World("test", new FlatlandGenerator()); world.SetBlockID(Coordinates3D.Zero, 1); world.SetBlockID(Coordinates3D.OneY, 2); var blockProvider = new Mock <BlockProvider> { CallBase = true }; var updated = new BlockDescriptor { ID = 2, Coordinates = Coordinates3D.Up }; var source = new BlockDescriptor { ID = 2, Coordinates = Coordinates3D.Right }; blockProvider.Setup(b => b.GetSupportDirection(It.IsAny <BlockDescriptor>())).Returns(Coordinates3D.Down); var supportive = new Mock <IBlockProvider>(); supportive.SetupGet(p => p.Opaque).Returns(true); var unsupportive = new Mock <IBlockProvider>(); unsupportive.SetupGet(p => p.Opaque).Returns(false); BlockRepository.Setup(r => r.GetBlockProvider(It.Is <byte>(b => b == 1))).Returns(supportive.Object); BlockRepository.Setup(r => r.GetBlockProvider(It.Is <byte>(b => b == 3))).Returns(unsupportive.Object); blockProvider.Object.BlockUpdate(updated, source, Server.Object, world); World.Verify(w => w.SetBlockID(Coordinates3D.OneY, 0), Times.Never); world.SetBlockID(Coordinates3D.Zero, 3); blockProvider.Object.BlockUpdate(updated, source, Server.Object, world); Assert.AreEqual(0, world.GetBlockID(Coordinates3D.OneY)); EntityManager.Verify(m => m.SpawnEntity(It.Is <ItemEntity>(e => e.Item.ID == 2))); }
public void TestCollisionPoint() { var repository = GetBlockRepository(); var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator()); var physics = new PhysicsEngine(world, repository); var entity = new TestEntity(); entity.Position = new Vector3(0, 5, 0); entity.AccelerationDueToGravity = 1; entity.Drag = 0; physics.AddEntity(entity); world.SetBlockID(new Coordinates3D(0, 4, 0), StoneBlock.BlockID); // Test physics.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual(new Vector3(0, 4, 0), entity.CollisionPoint); }
public void TestHorizontalCollision() { var repository = GetBlockRepository(); var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator()); var physics = new PhysicsEngine(world, repository); var entity = new TestEntity(); entity.Position = new Vector3(0, 5, 0); entity.AccelerationDueToGravity = 0; entity.Drag = 0; entity.Velocity = new Vector3(1, 0, 0); physics.AddEntity(entity); world.SetBlockID(new Coordinates3D(1, 5, 0), StoneBlock.BlockID); // Test physics.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual(0, entity.Position.X); }
public void TestAdjacentFall() { // Tests an entity that falls alongside a wall var repository = GetBlockRepository(); var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator()); var physics = new PhysicsEngine(world, repository); var entity = new TestEntity(); entity.Position = new Vector3(0, 10, 0); entity.AccelerationDueToGravity = 1; physics.AddEntity(entity); // Create a wall for (int y = 0; y < 12; y++) world.SetBlockID(new Coordinates3D(1, y, 0), StoneBlock.BlockID); // Test physics.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual(9, entity.Position.Y); Assert.IsFalse(entity.CollisionOccured); }