Exemplo n.º 1
0
 public static void Init()
 {
     DIRT       = new DirtBlock();
     GRASS      = new GrassBlock();
     STONE      = new StoneBlock();
     SAND       = new SandBlock();
     WATER      = new WaterBlock();
     LOG_OAK    = new OakLogBlock();
     LEAVES_OAK = new LeavesOakBlock();
     PLANKS_OAK = new OakWoodPlanks();
 }
Exemplo n.º 2
0
        public void PutBlock(Ray ray, float range)
        {
            if (Physics.Raycast(ray, out RaycastHit hit, range))
            {
                Vector3 position = hit.point + 0.5f * hit.normal;

                if (dimension.Blocks[position].Traits.IsReplaceable())
                {
                    var block = new GrassBlock();
                    dimension.Blocks[position] = block;
                    terrainRenderer.Redraw(position);
                }
            }
        }
Exemplo n.º 3
0
    public Block BuildBlock(string code)
    {
        Block b = new Block();

        setIdFromCode(code);
        setSubIdFromCode(code);

        switch (id)
        {
        case 0:
            AirBlock airBlock = new AirBlock(subId);
            b.TexturePath  = airBlock.TexturePath;
            b.IsCollidable = airBlock.IsCollidable;
            break;

        case 1:
            GroundBlock groundBlock = new GroundBlock(subId);
            b.TexturePath  = groundBlock.TexturePath;
            b.IsCollidable = groundBlock.IsCollidable;
            break;

        case 2:
            GrassBlock grassBlock = new GrassBlock(subId);
            b.TexturePath  = grassBlock.TexturePath;
            b.IsCollidable = grassBlock.IsCollidable;
            break;

        case 3:
            BridgeBlock bridgeBlock = new BridgeBlock(subId);
            b.TexturePath  = bridgeBlock.TexturePath;
            b.IsCollidable = bridgeBlock.IsCollidable;
            break;

        case 4:
            DirtBlock dirtBlock = new DirtBlock(subId);
            b.TexturePath  = dirtBlock.TexturePath;
            b.IsCollidable = dirtBlock.IsCollidable;
            break;

        default:
            AirBlock derivedBlock = new AirBlock(subId);
            b.TexturePath  = derivedBlock.TexturePath;
            b.IsCollidable = derivedBlock.IsCollidable;
            break;
        }
        return(b);
    }
Exemplo n.º 4
0
                public static Vector2[] GetTexture(TextureType textureType, TextureSide textureSide)
                {
                    switch (textureType)
                    {
                    case TextureType.Grass:
                        return(GrassBlock.GetTexture(textureSide));

                    case TextureType.Gravel:
                        return(GravelBlock.GetTexture(textureSide));

                    case TextureType.Stone:
                        return(StoneBlock.GetTexture(textureSide));

                    default:
                        throw new ArgumentOutOfRangeException(nameof(textureType), textureType, null);
                    }
                }
Exemplo n.º 5
0
        public Chunk()
        {
            Blocks = new IBlock[CHUNKSIZE_X, CHUNKSIZE_Y, CHUNKSIZE_Z];

            for (int z = 0; z < CHUNKSIZE_Z; z++)
            {
                for (int y = 0; y < CHUNKSIZE_Y; y++)
                {
                    for (int x = 0; x < CHUNKSIZE_X; x++)
                    {
                        //...
                        if (y < 20)
                        {
                            Blocks[x, y, z] = new GrassBlock();
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        GetComponent <MeshFilter>().mesh = MeshUtility.CreateCube(1f, Vector3.zero);
        BlockManager.Init(chunkPrefab);
        TextureManager.Init(texMap, tileSize);

        for (int x = 0; x < 100; x++)
        {
            for (int y = 0; y < 100; y++)
            {
                IBlock block = new GrassBlock(Vector3.left * x + (Vector3.up * TerrainUtility.GetBlockHeight(x, y)) + Vector3.forward * y);
                for (int i = 0; i < block.Position.y; i++)
                {
                    IBlock block1 = new DirtBlock(new Vector3(block.Position.x, i, block.Position.z));
                    BlockManager.AddBlock(block1);
                }
                BlockManager.AddBlock(block);
            }
        }


        //Block block = new Block(Vector3.one);
        //BlockManager.AddBlock(block);
    }
Exemplo n.º 7
0
        public Chunk Create()
        {
            var chunk     = new Chunk(dimension, address);
            var heightMap = new HeightMap(dimension.Seed.Dimension.Value, address, MaxHeight);
            var biomeMap  = new BiomeMap(dimension.Seed.Temperature.Value, dimension.Seed.Humidity.Value, address);

            heightMap.Generate();
            biomeMap.Generate();

            for (int x = 0; x < Chunk.Size; x++)
            {
                for (int z = 0; z < Chunk.Size; z++)
                {
                    var yMax      = heightMap[x, z];
                    var yMaxValue = Mathf.RoundToInt(yMax);
                    if (yMaxValue > MaxHeight)
                    {
                        yMaxValue = MaxHeight;
                    }

                    for (int y = 0; y <= yMaxValue; y++)
                    {
                        BaseBlock block;
                        if (y > WaterHeight + 10)
                        {
                            block = new StoneBlock();
                        }
                        else if (y > WaterHeight + 0)
                        {
                            block = new GrassBlock();
                        }
                        else
                        {
                            block = new SandBlock();
                        }
                        if (y >= WaterHeight)
                        {
                            var biome = biomeMap[x, z];
                            if (biome == "desert")
                            {
                                block = new SandBlock();
                            }
                            else if (biome == "stone")
                            {
                                block = new StoneBlock();
                            }
                            else if (biome == "grass")
                            {
                                block = new GrassBlock();
                            }
                            else
                            {
                                block = new GrassBlock();
                            }
                        }
                        else
                        {
                            block = new SandBlock();
                        }
                        chunk[x, y, z] = block;
                    }

                    for (int y = yMaxValue + 1; y < Chunk.Depth; y++)
                    {
                        BaseBlock block;
                        if (y < WaterHeight)
                        {
                            block = new WaterBlock();
                        }
                        else
                        {
                            block = new AirBlock();
                        }
                        chunk[x, y, z] = block;
                    }
                }
            }

            return(chunk);
        }
Exemplo n.º 8
0
    /// <summary>
    /// Creates a Chunk.
    /// Populates the Chunk based on Fractal Brownian Motion
    /// </summary>
    private void BuildChunk()
    {
        bool fileData = false;

        // fileData = Load();

        m_ChunkData = new Block[World.CHUNKSIZE, 2, World.CHUNKSIZE];

        for (int y = 0; y < 2; y++)
        {
            for (int z = 0; z < World.CHUNKSIZE; z++)
            {
                for (int x = 0; x < World.CHUNKSIZE; x++)
                {
                    // Block position
                    Vector3 pos = new Vector3(x, y, z);
                    // Block position in the World to compare to NoiseMap
                    int worldX = (int)(x + m_Chunk.transform.position.x);
                    int worldY = (int)(y + m_Chunk.transform.position.y);
                    int worldZ = (int)(z + m_Chunk.transform.position.z);

                    if (fileData)
                    {
                        m_ChunkData[x, y, z] = new Block(m_blockData.Matrix[x, y, z], pos, m_Chunk.gameObject, this, m_CubeAtlas);

                        continue;
                    }
                    else if (y == 1)
                    {
                        //m_ChunkData[x, y, z] = new PropPoint(m_ChunkData[x, y - 1, z].m_BlockType, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        continue;
                    }
                    // World Layers from bottom to top
                    // if (Utils.FBM3D(worldX, worldY, worldZ, 0.1f, 4) < 0.40f)
                    //     m_ChunkData[x, y, z] = new Block(Block.EBlockType.AIR, pos,
                    //                     m_Chunk.gameObject, this);
                    //if (worldY <= Utils.GenerateCliffHeight(worldX, worldZ))
                    //    m_ChunkData[x, y, z] = new Block(Block.EBlockType.AIR, pos,
                    //                   m_Chunk.gameObject, this);
                    // if (worldY == 1)
                    //    m_ChunkData[x, y, z] = new Block(Block.EBlockType.AIR, pos,
                    //                    m_Chunk.gameObject, this);

                    //else if (worldY == 0)
                    //    m_ChunkData[x, y, z] = new Block(Block.EBlockType.BEDROCK, pos,
                    //                    m_Chunk.gameObject, this);
                    else if (worldY <= Utils.GenerateStoneHeight(worldX, worldZ))
                    {
                        if (Utils.FBM3D(worldX, worldY, worldZ, 0.02f, 4) < 0.42f && worldY < 16)
                        {
                            m_ChunkData[x, y, z]     = new DiamondBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas);
                            m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.DIAMOND, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        }
                        else if (Utils.FBM3D(worldX, worldY, worldZ, 0.02f, 2) < 0.40f && worldY < 16)
                        {
                            m_ChunkData[x, y, z]     = new RedstoneBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas);
                            m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.REDSTONE, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        }
                        else
                        {
                            m_ChunkData[x, y, z]     = new StoneBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas);
                            m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.STONE, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        }
                    }
                    else if (worldY == Utils.GenerateHeight(worldX - 1, worldZ - 1)) // Grass equals the heightvalue returned by the function
                    {
                        m_ChunkData[x, y, z]     = new GrassBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.GRASS, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                    }
                    else if (worldY < Utils.GenerateHeight(worldX, worldZ))
                    {
                        m_ChunkData[x, y, z]     = new DirtBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.DIRT, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                    }
                    else
                    {
                        m_ChunkData[x, y, z]     = new AirBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas);
                        m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.AIR, pos, m_Chunk.gameObject, this, m_CubeAtlas);
                    }

                    m_CurrentStatus = EStatus.DRAW;
                }
            }
        }
        // Save();
    }
Exemplo n.º 9
0
    void BuildChunk()
    {
        bool dataFromFile = Load();

        chunkData = new Block[World.chunkSize, World.chunkSize, World.chunkSize];
        for (int z = 0; z < World.chunkSize; z++)
        {
            for (int y = 0; y < World.chunkSize; y++)
            {
                for (int x = 0; x < World.chunkSize; x++)
                {
                    Vector3 pos    = new Vector3(x, y, z);
                    int     worldX = (int)(x + chunk.transform.position.x);
                    int     worldY = (int)(y + chunk.transform.position.y);
                    int     worldZ = (int)(z + chunk.transform.position.z);

                    if (dataFromFile)
                    {
                        chunkData[x, y, z] = new Block(bd.matrix[x, y, z], pos, chunk.gameObject, this);
                        continue;
                    }

                    int surfaceHeight = Utils.GenHeight(worldX, worldZ);
                    if (worldY < 5)
                    {
                        chunkData[x, y, z] = new BedRockBlock(pos, chunk.gameObject, this);
                    }
                    else if (worldY <= Utils.GenStoneHeight(worldX, worldZ))
                    {
                        if (Utils.fBM3D(worldX, worldY, worldZ, 0.01f, 2) < 0.4f && worldY < 40)
                        {
                            chunkData[x, y, z] = new DiamondBlock(pos, chunk.gameObject, this);
                        }
                        if (Utils.fBM3D(worldX, worldY, worldZ, 0.03f, 3) < 0.41f && worldY < 20)
                        {
                            chunkData[x, y, z] = new RedStoneBlock(pos, chunk.gameObject, this);
                        }
                        else
                        {
                            chunkData[x, y, z] = new StoneBlock(pos, chunk.gameObject, this);
                        }
                    }
                    else if (worldY == surfaceHeight)
                    {
                        if (Utils.fBM3D(worldX, worldY, worldZ, 0.175f, 2) < 0.35f && worldY >= 65)
                        {
                            chunkData[x, y, z] = new TreeBlock(TreeBlock.TreeType.PINE, false, true, pos, chunk.gameObject, this);
                        }
                        else
                        {
                            chunkData[x, y, z] = new GrassBlock(pos, chunk.gameObject, this);
                        }
                        // chunkData[x, y, z] = new GrassBlock(pos, chunk.gameObject, this);
                    }
                    else if (worldY < surfaceHeight)
                    {
                        chunkData[x, y, z] = new DirtBlock(pos, chunk.gameObject, this);
                    }
                    else
                    {
                        chunkData[x, y, z] = new AirBlock(pos, chunk.gameObject, this);
                    }

                    if (chunkData[x, y, z].bType != Block.BlockType.WATER && Utils.fBM3D(worldX, worldY, worldZ, 0.08f, 3) < 0.42f)
                    {
                        chunkData[x, y, z] = new AirBlock(pos, chunk.gameObject, this);
                    }
                    if (worldY < 65 && chunkData[x, y, z].bType == Block.BlockType.AIR)
                    {
                        chunkData[x, y, z] = new WaterBlock(pos, fluid.gameObject, this);
                    }
                    if (worldY == 0)
                    {
                        chunkData[x, y, z] = new BedRockBlock(pos, chunk.gameObject, this);
                    }

                    status = ChunkStatus.DRAW;
                }
            }
        }
    }