protected override MeshData FaceDataDown(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3(x + blockSize, y - blockSize, z - blockSize));
            meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z - blockSize));
            meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z + blockSize));
            meshData.AddVertex(new Vector3(x + blockSize, y - blockSize, z + blockSize));

            meshData.AddQuadTriangles();
            return meshData;
        }
예제 #2
0
        public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            this.chunk = chunk;
            meshData.useRenderDataForCol = true;

            //DOWN
            meshData = FaceDataUp(chunk, x, y, z, meshData);

            meshData.uv.AddRange(FaceUVs(Direction.down));
            meshData.uv.AddRange(FaceUVs(Direction.down));
            meshData.uv.AddRange(FaceUVs(Direction.down));
            meshData.uv.AddRange(FaceUVs(Direction.down));

            //UP
            meshData = FaceDataDown(chunk, x, y, z, meshData);

            meshData.uv.AddRange(FaceUVs(Direction.up));
            meshData.uv.AddRange(FaceUVs(Direction.up));
            meshData.uv.AddRange(FaceUVs(Direction.up));
            meshData.uv.AddRange(FaceUVs(Direction.up));

            //SOUTH
            meshData = FaceDataNorth(chunk, x, y, z, meshData);

            meshData.uv.AddRange(FaceUVs(Direction.south));
            meshData.uv.AddRange(FaceUVs(Direction.south));
            meshData.uv.AddRange(FaceUVs(Direction.south));
            meshData.uv.AddRange(FaceUVs(Direction.south));

            //NORTH
            meshData = FaceDataSouth(chunk, x, y, z, meshData);

            meshData.uv.AddRange(FaceUVs(Direction.north));
            meshData.uv.AddRange(FaceUVs(Direction.north));
            meshData.uv.AddRange(FaceUVs(Direction.north));
            meshData.uv.AddRange(FaceUVs(Direction.north));

            //WEST
            meshData = FaceDataEast(chunk, x, y, z, meshData);

            meshData.uv.AddRange(FaceUVs(Direction.west));
            meshData.uv.AddRange(FaceUVs(Direction.west));
            meshData.uv.AddRange(FaceUVs(Direction.west));
            meshData.uv.AddRange(FaceUVs(Direction.west));

            //EAST
            meshData = FaceDataWest(chunk, x, y, z, meshData);

            meshData.uv.AddRange(FaceUVs(Direction.east));
            meshData.uv.AddRange(FaceUVs(Direction.east));
            meshData.uv.AddRange(FaceUVs(Direction.east));
            meshData.uv.AddRange(FaceUVs(Direction.east));

            return meshData;
        }
예제 #3
0
        public void UpdateOrientation(Chunk chunk, MapPosition pos)
        {
            Block westBlock = chunk.world.GetBlock(pos.x - 1, pos.y + 1, pos.z);
            Block eastBlock = chunk.world.GetBlock(pos.x + 1, pos.y + 1, pos.z);
            Block northBlock = chunk.world.GetBlock(pos.x, pos.y + 1, pos.z + 1);
            Block southBlock = chunk.world.GetBlock(pos.x, pos.y + 1, pos.z - 1);

            this.orientation[1] = northBlock.IsRoad() || northBlock is BlockHighlight;
            this.orientation[3] = eastBlock.IsRoad() || eastBlock is BlockHighlight;
            this.orientation[5] = southBlock.IsRoad() || southBlock is BlockHighlight;
            this.orientation[7] = westBlock.IsRoad() || westBlock is BlockHighlight;
        }
        public static void SetBlock(int x, int y, int z, Block block, Chunk chunk, bool replaceBlocks = false)
        {
            x -= chunk.pos.x;
            y -= chunk.pos.y;
            z -= chunk.pos.z;

            if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z))
            {
                if (replaceBlocks || chunk.blocks[x, y, z] == null)
                    chunk.SetBlock(x, y, z, block);
            }
        }
        public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            this.chunk = chunk;
            meshData.useRenderDataForCol = true;

            if (chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up))
            {
                meshData = FaceDataDown(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.down));
            }

            return meshData;
        }
예제 #6
0
        public static void SaveChunk(Chunk chunk)
        {
            Save save = new Save(chunk);
            if (save.blocks.Count == 0)
                return;

            string saveFile = SaveLocation(chunk.world.worldName);
            saveFile += FileName(chunk.pos);

            IFormatter formatter = new BinaryFormatter();
            using (Stream stream = new FileStream(saveFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                formatter.Serialize(stream, save);
            }
        }
        public Chunk ChunkColumnGenerator(Chunk chunk, int x, int z)
        {
            int stoneHeight = Mathf.FloorToInt(stoneBaseHeight);
            stoneHeight += GetNoise(x, 0, z, stoneMountainFrequency, Mathf.FloorToInt(stoneMountainHeight));

            if (stoneHeight < stoneMinHeight)
                stoneHeight = Mathf.FloorToInt(stoneMinHeight);

            stoneHeight += GetNoise(x, 0, z, stoneBaseNoise, Mathf.FloorToInt(stoneBaseNoiseHeight));

            int sandHeight = stoneHeight + Mathf.FloorToInt(sandBaseHeight);
            sandHeight += GetNoise(x, 100, z, sandNoise, Mathf.FloorToInt(sandNoiseHeight));

            for (int y = chunk.pos.y; y < chunk.pos.y + Chunk.chunkSize; y++)
            {

                int caveChance = GetNoise(x, y, z, caveFrequency, 100);

                if (y <= stoneHeight && caveSize < caveChance)
                {
                    SetBlock(x, y, z, new BlockDirt(), chunk);
                }
                else if (y <= sandHeight && caveSize < caveChance)
                {
                    SetBlock(x, y, z, new BlockSand(), chunk);

                    if (y == sandHeight && GetNoise(x, 0, z, treeFrequency, 100) < treeDensity)
                    {
                        CreateTree(x, y + 1, z, chunk);
                    }
                    else
                    {
                        if (y == sandHeight && GetNoise(x, 0, z, waterFrequency, 150) < waterDensity)
                        {
                            CreateWater(x, y, z, chunk);
                        }
                    }

                }
                else
                {
                    SetBlock(x, y, z, new BlockAir(), chunk);
                }

            }

            return chunk;
        }
예제 #8
0
        public Save(Chunk chunk)
        {
            for (int x = 0; x < Chunk.chunkSize; x++)
            {
                for (int y = 0; y < Chunk.chunkSize; y++)
                {
                    for (int z = 0; z < Chunk.chunkSize; z++)
                    {
                        if (!chunk.blocks[x, y, z].changed)
                            continue;

                        MapPosition pos = new MapPosition(x, y, z);
                        blocks.Add(pos, chunk.blocks[x, y, z]);
                    }
                }
            }
        }
예제 #9
0
        public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            this.chunk = chunk;
            meshData.useRenderDataForCol = true;

            if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.down))
            {
                meshData = FaceDataUp(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.down));
            }

            if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up))
            {
                meshData = FaceDataDown(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.up));

            }

            if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.south))
            {
                meshData = FaceDataNorth(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.south));
            }

            if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.north))
            {
                meshData = FaceDataSouth(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.north));
            }

            if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.west))
            {
                meshData = FaceDataEast(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.west));
            }

            if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.east))
            {
                meshData = FaceDataWest(chunk, x, y, z, meshData);
                meshData.uv.AddRange(FaceUVs(Direction.east));
            }

            return meshData;
        }
예제 #10
0
        public static bool Load(Chunk chunk)
        {
            string saveFile = SaveLocation(chunk.world.worldName);
            saveFile += FileName(chunk.pos);

            if (!File.Exists(saveFile))
                return false;

            IFormatter formatter = new BinaryFormatter();
            using (FileStream stream = new FileStream(saveFile, FileMode.Open))
            {
                Save save = (Save)formatter.Deserialize(stream);

                foreach (var block in save.blocks)
                {
                    chunk.blocks[block.Key.x, block.Key.y, block.Key.z] = block.Value;
                }
            }
            return true;
        }
        void CreateWater(int x, int y, int z, Chunk chunk)
        {
            //create water
            Block water = new BlockWater();
            Block air = new BlockAir();

            //Land buffer
            SetBlock(x, y, z, air, chunk, true);
            SetBlock(x, y - 1, z, air, chunk, true);

            for(var i = 2; i < waterDepth; i++)
            {
                SetBlock(x, y - i, z, water, chunk, true);
            }
        }
예제 #12
0
        protected virtual MeshData FaceDataWest(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z + blockSize));
            meshData.AddVertex(new Vector3(x - blockSize, y + blockSize, z + blockSize));
            meshData.AddVertex(new Vector3(x - blockSize, y + blockSize, z - blockSize));
            meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z - blockSize));

            meshData.AddQuadTriangles();
            return meshData;
        }
예제 #13
0
        //TODO: ORIENTATION
        //http://gamedev.stackexchange.com/questions/29524/choose-tile-based-on-adjacent-tiles
        //http://www.angryfishstudios.com/2011/04/adventures-in-bitmasking/
        private static bool _setRoad(Chunk chunk, MapPosition pos)
        {
            if (chunk.world.GetBlock(pos.x, pos.y, pos.z).IsSolid(Direction.up) && chunk.world.GetBlock(pos.x, pos.y + 1, pos.z) is BlockHighlight)
            {
                chunk.world.SetBlock(pos.x, pos.y + 1, pos.z, new BlockRoad());
                return true;
            }

            return false;
        }
예제 #14
0
 public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
 {
     return meshData;
 }
 public Chunk ChunkGenerator(Chunk chunk)
 {
     for (int x = chunk.pos.x; x < chunk.pos.x + Chunk.chunkSize; x++)
     {
         for (int z = chunk.pos.z; z < chunk.pos.z + Chunk.chunkSize; z++)
         {
             chunk = ChunkColumnGenerator(chunk, x, z);
         }
     }
     return chunk;
 }
 void CreateTree(int x, int y, int z, Chunk chunk)
 {
     //create tree
     Block tree = (Random.value > 0.05) ? (Random.value > 0.5) ? new BlockTreeYellow() : new BlockTreeRed() as Block : new BlockTreeGreen() as Block;
     SetBlock(x, y, z, tree, chunk, true);
 }
예제 #17
0
        protected override MeshData FaceDataDown(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), (z - treeOffset) - blockSize));
            meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), (z - treeOffset) - blockSize));
            meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), (z - treeOffset) + blockSize));
            meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), (z - treeOffset) + blockSize));

            meshData.AddQuadTriangles();

            meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), z - blockSize));
            meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), z - blockSize));
            meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), z + blockSize));
            meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), z + blockSize));

            meshData.AddQuadTriangles();

            meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), z - blockSize));
            meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), z - blockSize));
            meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), z + blockSize));
            meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), z + blockSize));

            meshData.AddQuadTriangles();

            meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), (z + treeOffset) - blockSize));
            meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), (z + treeOffset) - blockSize));
            meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), (z + treeOffset) + blockSize));
            meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), (z + treeOffset) + blockSize));

            meshData.AddQuadTriangles();
            return meshData;
        }