Exemplo n.º 1
0
        private void CreateBlocksBasedOnHeightMap()
        {
            for (int i = 0; i < heightMap.GetLength(0); i++)
            {
                for (int j = 0; j < heightMap.GetLength(1); j++)
                {
                    int blockPillarHeight = heightMap[i, j];

                    for (int k = 0; k < blockPillarHeight; k++)
                    {
                        BlockPosition blockPosition = new BlockPosition(i, k, j);

                        if (k < blockPillarHeight - 2)
                        {
                            result.PlaceBlockAt(RockBlock.GetInstance(), blockPosition);
                        }
                        else if (k < blockPillarHeight - 1)
                        {
                            result.PlaceBlockAt(EarthBlock.GetInstance(), blockPosition);
                        }
                        else
                        {
                            result.PlaceBlockAt(GrassyEarthBlock.GetInstance(), blockPosition);
                        }
                    }
                }
            }
        }
        public IEnumerator BlockTypeIsEarth()
        {
            EarthBlock testCandidate = EarthBlock.GetInstance();

            yield return(null);

            Assert.That(testCandidate, Is.Not.Null);
            Assert.That(testCandidate.GetBlockType(), Is.EqualTo(BlockTypes.EARTH));
        }
Exemplo n.º 3
0
        public IEnumerator CannotPlaceBlockOutsideZDimension()
        {
            Island        testCandidate = new Island(64);
            Block         testBlock     = EarthBlock.GetInstance();
            BlockPosition blockPosition = new BlockPosition(54, 13, 64);

            yield return(null);

            Assert.Throws <BlockPositionOutOfBoundsException>(() => testCandidate.PlaceBlockAt(testBlock, blockPosition));
        }
        public IEnumerator AllBlockFacesAreCovering()
        {
            EarthBlock testCandidate = EarthBlock.GetInstance();

            yield return(null);

            Assert.IsTrue(testCandidate.GetFrontFaceIsCovering());
            Assert.IsTrue(testCandidate.GetRightFaceIsCovering());
            Assert.IsTrue(testCandidate.GetBackFaceIsCovering());
            Assert.IsTrue(testCandidate.GetLeftFaceIsCovering());
            Assert.IsTrue(testCandidate.GetBottomFaceIsCovering());
            Assert.IsTrue(testCandidate.GetTopFaceIsCovering());
        }
        public IEnumerator LeftFaceIsShownWhenItsNotCovering()
        {
            SolidBlockFaceHidingStrategy testCandidate = new SolidBlockFaceHidingStrategy();

            Block coveredBlock  = AirBlock.GetInstance();
            Block coveringBlock = EarthBlock.GetInstance();

            bool result = testCandidate.FaceIsHidden(coveredBlock, coveringBlock, BlockFaceDirections.LEFT);

            yield return(null);

            Assert.IsFalse(result);
        }
Exemplo n.º 6
0
        public IEnumerator CanPlaceBlockAtMaximumHeight()
        {
            Island        testCandidate = new Island(64);
            Block         testBlock     = EarthBlock.GetInstance();
            BlockPosition blockPosition = new BlockPosition(63, 255, 63);

            testCandidate.PlaceBlockAt(testBlock, blockPosition);

            Block blockAt = testCandidate.GetBlockAt(blockPosition);

            yield return(null);

            Assert.That(blockAt, Is.SameAs(testBlock));
        }
Exemplo n.º 7
0
        public IEnumerator BottomFaceOfBlockIsVisibleWhenAtBottomEdgeOfIsland()
        {
            Island        testCandidate = new Island(64);
            BlockPosition blockPosition = new BlockPosition(0, 0, 0);

            Block testBlock = EarthBlock.GetInstance();

            testCandidate.PlaceBlockAt(testBlock, blockPosition);

            bool result = testCandidate.BlockFaceAtPositionIsHidden(BlockFaceDirections.BOTTOM, blockPosition);

            yield return(null);

            Assert.That(result, Is.EqualTo(false));
        }
        public void TestThatCoveredMiddleBlockIsNotRendered()
        {
            Island islandToRender = new Island(46);

            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(34, 3, 18));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(35, 3, 18));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(36, 3, 18));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(34, 3, 19));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(35, 3, 19));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(36, 3, 19));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(34, 3, 20));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(35, 3, 20));
            islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(36, 3, 20));

            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(34, 2, 18));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(35, 2, 18));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(36, 2, 18));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(34, 2, 19));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(35, 2, 19));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(36, 2, 19));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(34, 2, 20));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(35, 2, 20));
            islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(36, 2, 20));

            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(34, 1, 18));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(35, 1, 18));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(36, 1, 18));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(34, 1, 19));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(35, 1, 19));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(36, 1, 19));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(34, 1, 20));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(35, 1, 20));
            islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(36, 1, 20));

            ChunkPresenter testCandidate = new ChunkPresenter();

            testCandidate.PresentChunk(islandToRender, 2, 1);

            VisualChunkData lastRenderedChunkData = ChunkRendererMock.GetLastRenderChunkCallData();

            Assert.That(lastRenderedChunkData, Is.Not.Null);
            Assert.That(lastRenderedChunkData.GetWorldX(), Is.EqualTo(2));
            Assert.That(lastRenderedChunkData.GetWorldY(), Is.EqualTo(1));
            Assert.That(lastRenderedChunkData.GetVertices().Length, Is.EqualTo(648));
            Assert.That(lastRenderedChunkData.GetIndices().Length, Is.EqualTo(324));
            Assert.That(lastRenderedChunkData.GetNormals().Length, Is.EqualTo(648));
            Assert.That(lastRenderedChunkData.GetUvCoordinates().Length, Is.EqualTo(432));
        }
Exemplo n.º 9
0
        public IEnumerator BottomFaceOfBlockIsVisibleWhenNotCovered()
        {
            Island        testCandidate    = new Island(64);
            BlockPosition blockPositionOne = new BlockPosition(0, 5, 0);
            BlockPosition blockPositionTwo = new BlockPosition(0, 4, 0);

            Block testBlock = EarthBlock.GetInstance();
            Block neighbor  = AirBlock.GetInstance();

            testCandidate.PlaceBlockAt(testBlock, blockPositionOne);
            testCandidate.PlaceBlockAt(neighbor, blockPositionTwo);

            bool result = testCandidate.BlockFaceAtPositionIsHidden(BlockFaceDirections.BOTTOM, blockPositionOne);

            yield return(null);

            Assert.That(result, Is.EqualTo(false));
        }
Exemplo n.º 10
0
        public IEnumerator RightFaceOfBlockIsVisibleWhenNotFullyCovering()
        {
            Island        testCandidate    = new Island(64);
            BlockPosition blockPositionOne = new BlockPosition(46, 0, 0);
            BlockPosition blockPositionTwo = new BlockPosition(45, 0, 0);

            Block testBlock = AirBlock.GetInstance();
            Block neighbor  = EarthBlock.GetInstance();

            testCandidate.PlaceBlockAt(testBlock, blockPositionOne);
            testCandidate.PlaceBlockAt(neighbor, blockPositionTwo);

            bool result = testCandidate.BlockFaceAtPositionIsHidden(BlockFaceDirections.RIGHT, blockPositionOne);

            yield return(null);

            Assert.That(result, Is.EqualTo(false));
        }
Exemplo n.º 11
0
        public IEnumerator FrontFaceOfEarthBlockIsHiddenWhenCovered()
        {
            Island        testCandidate    = new Island(64);
            BlockPosition blockPositionOne = new BlockPosition(0, 0, 7);
            BlockPosition blockPositionTwo = new BlockPosition(0, 0, 8);

            Block testBlock = EarthBlock.GetInstance();
            Block neighbor  = GrassyEarthBlock.GetInstance();

            testCandidate.PlaceBlockAt(testBlock, blockPositionOne);
            testCandidate.PlaceBlockAt(neighbor, blockPositionTwo);

            bool result = testCandidate.BlockFaceAtPositionIsHidden(BlockFaceDirections.FRONT, blockPositionOne);

            yield return(null);

            Assert.That(result, Is.EqualTo(true));
        }