Ejemplo 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));
        }
Ejemplo n.º 3
0
        public static EarthBlock GetInstance()
        {
            if (null != instance)
            {
                return(instance);
            }

            instance = new EarthBlock();
            return(instance);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 7
0
        private void DrawEarth(SpriteBatch spriteBatch)
        {
            //Draw latteral
            for (int i = 1; i <= 10; i++)
            {
                EarthBlocks[i.ToString()].Draw(spriteBatch);
                EarthBlocks[i.ToString() + "R"].Draw(spriteBatch);
            }

            //Draw central
            //Block 8 starts the 12,13 chain
            //Block 9 starts the 11, 14 chain

            int w = EarthBlock.Width;

            int beginX = (int)EarthBlocks["8"].Position.X;
            int beginY = (int)EarthBlocks["8"].Position.Y;

            EarthBlock block;

            for (int i = 0; i < CentralCount; i++)
            {
                string key = (12 + (i % 2)).ToString();
                block          = EarthBlocks[key];
                block.Position = new Vector2(beginX + (i + 1) * w, beginY);

                EarthBlock.Draw(spriteBatch, block);
            }

            beginX = (int)EarthBlocks["10"].Position.X;
            beginY = (int)EarthBlocks["10"].Position.Y;
            for (int i = 0; i < CentralCount; i++)
            {
                string key = (i % 2 == 0 ? 11 : 14).ToString();
                block          = EarthBlocks[key];
                block.Position = new Vector2(beginX + (i + 1) * w, beginY);

                EarthBlock.Draw(spriteBatch, block);
            }
            //Draw last

            for (int i = 0; i < GetRealWidth() / w; i++)
            {
                block          = EarthBlocks["0"];
                block.Position = new Vector2(i * w, GetRealHeight() - EarthBlock.Height);

                EarthBlock.Draw(spriteBatch, block);
            }

            DrawEarthBackground(spriteBatch);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 11
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));
        }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
            public static void Draw(SpriteBatch spriteBatch, EarthBlock block)
            {
                Vector2 Position = new Vector2(Source.GetRealX() + block.Position.X, Source.GetRealY() + block.Position.Y);

                spriteBatch.Draw(block.Atlas, sourceRectangle: block.SourceRectangle, position: Position, effects: block.Effects, layerDepth: block.LayerDepth);
            }
Ejemplo n.º 15
0
        private void DrawEarthBackground(SpriteBatch spriteBatch)
        {
            EarthBlock block;

            /*
             * //Block 1
             * block = EarthBlocks["1B"];
             * block.Position = Vector2.Zero;
             *
             * EarthBlock.Draw(spriteBatch, block);
             *
             *
             * block.Position = new Vector2(GetRealWidth() - EarthBlock.Width, 0);
             *
             * EarthBlock.Draw(spriteBatch, block);
             *
             * //Block 2
             * block = EarthBlocks["2B"];
             * block.Position = new Vector2(EarthBlock.Width, 0);
             *
             * EarthBlock.Draw(spriteBatch, block);
             *
             *
             * block.Position = new Vector2(GetRealWidth() - 2 * EarthBlock.Width, 0);
             *
             * EarthBlock.Draw(spriteBatch, block);
             *
             */

            //Chains (3-4 chain starts at block 4, 5-6 chain starts at block 6)
            int startX = (int)EarthBlocks["3"].Position.X;
            int startY = (int)EarthBlocks["3"].Position.Y;

            for (int i = 0; i < CentralCount + 2; i++) //One for each latteral side
            {
                string key = (3 + (i % 2)).ToString() + "B";
                block          = EarthBlocks[key];
                block.Position = new Vector2(startX + (i + 1) * EarthBlock.Width, startY);

                EarthBlock.Draw(spriteBatch, block);
            }


            startX = (int)EarthBlocks["5"].Position.X;
            startY = (int)EarthBlocks["5"].Position.Y;

            for (int i = 0; i < CentralCount + 2; i++) //One for each latteral side
            {
                string key = (5 + (i % 2)).ToString() + "B";
                block          = EarthBlocks[key];
                block.Position = new Vector2(startX + (i + 1) * EarthBlock.Width, startY);

                EarthBlock.Draw(spriteBatch, block);
            }

            startX = (int)EarthBlocks["8"].Position.X;
            startY = (int)EarthBlocks["8"].Position.Y;

            for (int i = 0; i < CentralCount; i++)
            {
                string key = (7 + (i % 2)).ToString() + "B";
                block          = EarthBlocks[key];
                block.Position = new Vector2(startX + (i + 1) * EarthBlock.Width, startY);

                EarthBlock.Draw(spriteBatch, block);
            }
        }