Пример #1
0
    public override Block BuildBlock(Vector3Int pos)
    {
        Block newBlock = null;

        if (blockType == FillArea.BlockType.BLOCK)
        {
            newBlock = new Block();
        }
        else if (blockType == FillArea.BlockType.GRASS)
        {
            newBlock = new BlockGrass();
        }
        else if (blockType == FillArea.BlockType.DESERT)
        {
            newBlock = new BlockDesert();
        }
        else if (blockType == FillArea.BlockType.CLOUD)
        {
            newBlock = new BlockCloud();
        }
        else if (blockType == FillArea.BlockType.WATER)
        {
            newBlock = new BlockWater();
        }
        else
        {
            newBlock = new BlockAir();
        }

        return(newBlock);
    }
Пример #2
0
    /** Instantiate all block types and store them in the array */
    static Block()
    {
        blocks          = new Block[ushort.MaxValue + 1];
        blocks[AIR]     = new BlockAir();
        blocks[BEDROCK] = new BlockBedrock();
        for (uint i = 0; i < STONE.Length; i++)
        {
            blocks[STONE[i]] = new BlockStone(i);
        }
        blocks[DIRT]       = new BlockDirt();
        blocks[GRASS]      = new BlockGrass();
        blocks[ROCKY_DIRT] = new BlockDirtStone();
        blocks[SAND]       = new BlockSand();
        for (uint i = 0; i < WATER.Length; i++)
        {
            blocks[WATER[i]] = new BlockWater(i);
        }

        for (int i = 0; i < blocks.Length; i++)
        {
            if (blocks[i] != null)
            {
                blocks[i].id = (ushort)i;
            }
        }
    }
Пример #3
0
    /**
     *  @brief  지형 블럭을 생성한다.
     *  @return 만들어진 지형을 반환한다.
     */
    private Block CreateBlock(Vector3Int worldPos)
    {
        Block newBlock = null;
        var   info     = planetInfo.terrainInfo;

        float coreRange = info.radius * info.coreRate;

        //코어의 표면은 블럭으로 생성
        int isInVertCnt = MyUtil.IsCubeInRange(worldPos, 1, coreRange);

        if (isInVertCnt > 0 && isInVertCnt < 8)
        {
            newBlock        = new Block();
            newBlock.isLock = true;
        }
        //코어 외부는 Mode에 따라 함수를 통해 생성
        else if (isInVertCnt == 0)
        {
            if (MyUtil.GetSNoise(worldPos.x, worldPos.y, worldPos.z, 0.05f, 50) > 20)
            {
                float noise = (MyUtil.Get3DNoise(worldPos.x, worldPos.y, worldPos.z, info.frequency,
                                                 info.octave, info.persistence) + 1.0f) * 0.5f;
                //int holeChance = MyUtil.GetSNoise(worldPos.x, worldPos.y, worldPos.z, 0.05f, 50);

                noise = Mathf.Clamp01(noise);

                if (noise <= info.blockRate)
                {
                    newBlock = new Block();
                }
                else if (noise <= info.desertRate)
                {
                    newBlock = new BlockDesert();
                }
                else if (noise <= info.grassRate)
                {
                    newBlock = new BlockGrass();
                }
            }
        }

        //Ocean BLock
        if (newBlock == null)
        {
            float height = Mathf.Max(Mathf.Abs(worldPos.x + 0.5f), Mathf.Abs(worldPos.y + 0.5f), Mathf.Abs(worldPos.z + 0.5f));

            if (height <= info.oceanHeight && height > info.oceanHeight - info.oceanDepth)
            {
                newBlock        = new BlockWater();
                newBlock.isLock = true;
            }
        }

        if (newBlock == null)
        {
            newBlock = new BlockAir();
        }

        return(newBlock);
    }
Пример #4
0
    public Chunk ChunkGenColumn(Chunk chunk, int x, int z, int posx, int posy, int posz)
    {
        if (chunk.world.plane)
        {
            for (int y = posy; y < posy + Chunk.chunkHeight; y++)
            {
                if (y <= stoneBaseNoiseHeight)
                {
                    SetBlock(x - posx, y - posy, z - posz, new Block(), chunk);
                }
                else if (y < stoneBaseNoiseHeight + dirtNoiseHeight)
                {
                    SetBlock(x - posx, y - posy, z - posz, new BlockDirt(), chunk);
                }
                else if (y == stoneBaseNoiseHeight + dirtNoiseHeight)
                {
                    SetBlock(x - posx, y - posy, z - posz, new BlockGrass(), chunk);
                }
                else
                {
                    SetBlock(x - posx, y - posy, z - posz, new BlockAir(), chunk);
                }
            }

            return(chunk);
        }

        int biomeChance = GetNoise(x, 0, z, biomesFrequency, 100, chunk.world.GetGrainOffset(5));

        int stoneHeight = Mathf.FloorToInt(stoneBaseHeight);

        stoneHeight += GetNoise(x, 0, z, stoneMountainFrequency, Mathf.FloorToInt(stoneMountainHeight), chunk.world.GetGrainOffset(0));

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

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

        int dirtHeight = stoneHeight + Mathf.FloorToInt(dirtBaseHeight);

        dirtHeight += GetNoise(x, 100, z, dirtNoise, Mathf.FloorToInt(dirtNoiseHeight), chunk.world.GetGrainOffset(2));


        int lakesChance = GetNoise(x, 0, z, lakesFrequency, 100, chunk.world.GetGrainOffset(3));

        int treeChance = GetNoise(x, 0, z, treeFrequency, 100, chunk.world.GetGrainOffset(4));

        for (int y = posy; y < posy + Chunk.chunkHeight; y++)
        {
            /*if (x >= 0 && x <= 319 && z >= 0 && z <= 319) {
             *      if (y <= 10) {
             *              SetBlock (x - posx, y - posy, z - posz, new Block (), chunk);
             *      } else if (y <= 14) {
             *              SetBlock (x - posx, y - posy, z - posz, new BlockDirt (), chunk);
             *      } else if (y <= 16) {
             *              SetBlock (x - posx, y - posy, z - posz, new BlockGrass (), chunk);
             *      }
             *      if ((x%16 == 0 && z%16 == 0 && y==6)) {
             *              CreateTown (x, y, z, posx, posy, posz, chunk);
             *              SetBlock (x - posx, y - posy, z - posz, new BlockGrass (), chunk);
             *      }
             *      SetBlock (x - posx, y - posy, z - posz, new BlockAir (), chunk);
             * } else */if (x >= 0 && x <= 150 && z >= 0 && z <= 150)
            {
                if (y <= 10)
                {
                    SetBlock(x - posx, y - posy, z - posz, new Block(), chunk);
                }
                else if (y <= 14)
                {
                    SetBlock(x - posx, y - posy, z - posz, new BlockDirt(), chunk);
                }
                else if (y <= 16)
                {
                    SetBlock(x - posx, y - posy, z - posz, new BlockGrass(), chunk);
                }
                if ((x % 16 == 0 && z % 16 == 0 && y == 6))
                {
                    CreateTown(x, y, z, posx, posy, posz, chunk);
                    SetBlock(x - posx, y - posy, z - posz, new BlockGrass(), chunk);
                }
                SetBlock(x - posx, y - posy, z - posz, new BlockAir(), chunk);
            }
            else
            {
                if (y <= stoneHeight)
                {
                    SetBlock(x - posx, y - posy, z - posz, new Block(), chunk);
                }
                else if (y <= dirtHeight)
                {
                    if (lakesSize < lakesChance)
                    {
                        if (y == dirtHeight)
                        {
                            SetBlock(x - posx, y - posy, z - posz, new BlockGrass(), chunk);
                        }
                        else
                        {
                            SetBlock(x - posx, y - posy, z - posz, new BlockDirt(), chunk);
                        }
                        if (y == dirtHeight && treeChance < treeDensity)
                        {
                            CreateTree(x - posx, y - posy + 1, z - posz, chunk);
                        }
                    }
                    else
                    {
                        if (y > dirtHeight)
                        {
                            SetBlock(x - posx, y - posy, z - posz, new BlockAir(), chunk);
                        }
                        else
                        {
                            /*SetBlock (x, y, z, new BlockWater (), chunk);
                             * BlockWater newBlock = chunk.world.GetBlock (x, y, z) as BlockWater;
                             * newBlock.SetWorld (chunk.world, x, y, z);
                             * newBlock.RegisterForUpdate ();*/

                            BlockWater newBlock = new BlockWater();
                            newBlock.SetWorld(chunk.world, x, y, z);
                            //newBlock.RegisterForUpdate ();
                            chunk.SeepBlocks.Add(newBlock);
                            SetBlock(x - posx, y - posy, z - posz, newBlock, chunk);
                        }
                    }
                }
                else
                {
                    if (lakesSize < lakesChance || y > stoneBaseHeight + stoneBaseNoiseHeight)
                    {
                        SetBlock(x - posx, y - posy, z - posz, new BlockAir(), chunk);
                    }
                    else
                    {
                        BlockWater newBlock = new BlockWater();
                        newBlock.SetWorld(chunk.world, x, y, z);
                        chunk.SeepBlocks.Add(newBlock);
                        SetBlock(x - posx, y - posy, z - posz, newBlock, chunk);
                    }
                }
            }
        }

        /*for(int y = posy; y < posy + Chunk.chunkHeight; y++) {
         *
         *      if (y <= stoneHeight)
         *              SetBlock (x - posx, y - posy, z - posz, new Block (), chunk);
         *      else if (y <= dirtHeight) {
         *              if (lakesSize < lakesChance) {
         *                      if (y == dirtHeight)
         *                              SetBlock (x - posx, y - posy, z - posz, new BlockGrass (), chunk);
         *                      else
         *                              SetBlock (x - posx, y - posy, z - posz, new BlockDirt (), chunk);
         *                      if (y == dirtHeight && treeChance < treeDensity)
         *                              CreateTree (x - posx, y - posy + 1, z - posz, chunk);
         *              }
         *              else {
         *
         *                      if (y > stoneBaseHeight + stoneBaseNoiseHeight) {
         *                              SetBlock (x - posx, y - posy, z - posz, new BlockAir (), chunk);
         *                      } else {
         *                              /*SetBlock (x, y, z, new BlockWater (), chunk);
         *                              BlockWater newBlock = chunk.world.GetBlock (x, y, z) as BlockWater;
         *                              newBlock.SetWorld (chunk.world, x, y, z);
         *                              newBlock.RegisterForUpdate ();
         *
         *                              BlockWater newBlock = new BlockWater ();
         *                              newBlock.SetWorld (chunk.world, x, y, z);
         *                              //newBlock.RegisterForUpdate ();
         *                              chunk.SeepBlocks.Add(newBlock);
         *                              SetBlock (x - posx, y - posy, z - posz, newBlock, chunk);
         *                      }
         *
         *              }
         *      }
         *      else {
         *              if (lakesSize < lakesChance || y > stoneBaseHeight + stoneBaseNoiseHeight) {
         *                      SetBlock (x - posx, y - posy, z - posz, new BlockAir (), chunk);
         *              }
         *              else {
         *                      BlockWater newBlock = new BlockWater ();
         *                      newBlock.SetWorld (chunk.world, x, y, z);
         *                      chunk.SeepBlocks.Add(newBlock);
         *                      SetBlock (x - posx, y - posy, z - posz, newBlock, chunk);
         *              }
         *      }
         * }*/

        return(chunk);
    }
Пример #5
0
    void Update()
    {
        rotationX += Input.GetAxis("Mouse X") * cameraSensitivity * Time.deltaTime;
        rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity * Time.deltaTime;
        rotationY  = Mathf.Clamp(rotationY, -90, 90);

        transform.localRotation  = Quaternion.AngleAxis(rotationX, Vector3.up);
        transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);

        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            transform.position += transform.forward * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime;
            transform.position += transform.right * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
        {
            transform.position += transform.forward * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime;
            transform.position += transform.right * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime;
        }
        else
        {
            transform.position += transform.forward * normalMoveSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
            transform.position += transform.right * normalMoveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
        }


        if (Input.GetKey(KeyCode.Q))
        {
            transform.position += transform.up * climbSpeed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.E))
        {
            transform.position -= transform.up * climbSpeed * Time.deltaTime;
        }

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 100))
            {
                EditTerrain.SetBlock(hit, new BlockAir());
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 100))
            {
                EditTerrain.SetBlock(hit, new BlockGrass(), true);
            }
        }

        if (Input.GetMouseButtonDown(2))
        {
            RaycastHit hitInfo;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hitInfo))
            {
                int   x      = Mathf.CeilToInt(hitInfo.point.x);
                int   y      = Mathf.CeilToInt(hitInfo.point.y);
                int   z      = Mathf.CeilToInt(hitInfo.point.z);
                Block bl     = world.GetBlock(x, y, z);
                Block downBl = world.GetBlock(x, y - 1, z);

                //Check to see if we got a water block                                                                          ///---
                if (bl.GetType() == typeof(BlockAir) && downBl.GetType() != typeof(BlockWater))
                {
                    //set the new water block
                    world.SetBlock(x, y, z, new BlockWater());
                    //get the block we just placed
                    BlockWater newBlock = world.GetBlock(x, y, z) as BlockWater;
                    newBlock.SetWorld(world, x, y, z);
                    //and add it to register for update
                    newBlock.RegisterForUpdate();
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftAlt))
        {
            Cursor.lockState = (Cursor.lockState == CursorLockMode.Locked) ? CursorLockMode.Locked : CursorLockMode.None;
        }
    }
Пример #6
0
    //we ovveride the Tick from the upper class
    public override void Tick(float deltaTime)
    {
        timer += deltaTime;

        if (timer > tickInterval)
        {
            timer = 0;

            if (DistanceFromMain < 10)        //if there's still room to place
            {
                bool continueSideways = true; //we take it so that we can place blocks around it

                //However, if there's no block below us,
                Block bottomBlock = world.GetBlock(blockX, blockY - 1, blockZ);

                if (bottomBlock != null)
                {
                    if (bottomBlock.GetType() == typeof(BlockAir))
                    {
                        //then we can't place other blocks sideways
                        continueSideways = false;
                        //we set a new block of water below us
                        world.SetBlock(blockX, blockY - 1, blockZ, new BlockWater());

                        //the above function doesn't return the block
                        //so we have to take it manually
                        BlockWater newBlock = world.GetBlock(blockX, blockY - 1, blockZ) as BlockWater;

                        //If there is a new block to get, which means we are not on the edge of our grid
                        if (newBlock != null)
                        {
                            //then take the new block we just added
                            newBlock.SetWorld(world, blockX, blockY - 1, blockZ);
                            //and add it into the register for Update list
                            newBlock.RegisterForUpdate();
                        }
                    }
                    else    //We also cannot place any other water blocks sidewas if there's water below us
                    if (bottomBlock.GetType() == typeof(BlockWater))
                    {
                        continueSideways = false;
                    }
                }

                //If we checked what is below us, and we can place sideways
                if (continueSideways == true)
                {
                    //Then check for every direction, instead of up
                    Block forwardBlock = world.GetBlock(blockX, blockY, blockZ + 1);

                    //and basically do the same as above
                    if (forwardBlock != null)
                    {
                        if (forwardBlock.GetType() == typeof(BlockAir))
                        {
                            world.SetBlock(blockX, blockY, blockZ + 1, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX, blockY, blockZ + 1) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX, blockY, blockZ + 1);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromMain = DistanceFromMain + 1; //But add to the distance from main
                                //we only take into account the distance from the main water block when we are moving
                                //sideways because otherwise our water would have stopped mid air
                            }
                        }
                    }

                    //Do the same for all the directions, except up
                    Block backBlock = world.GetBlock(blockX, blockY, blockZ - 1);

                    if (backBlock != null)
                    {
                        if (backBlock.GetType() == typeof(BlockAir))
                        {
                            world.SetBlock(blockX, blockY, blockZ - 1, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX, blockY, blockZ - 1) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX, blockY, blockZ - 1);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromMain = DistanceFromMain + 1;
                            }
                        }
                    }

                    Block leftBlock = world.GetBlock(blockX - 1, blockY, blockZ);

                    if (leftBlock != null)
                    {
                        if (leftBlock.GetType() == typeof(BlockAir))
                        {
                            world.SetBlock(blockX - 1, blockY, blockZ, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX - 1, blockY, blockZ) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX - 1, blockY, blockZ);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromMain = DistanceFromMain + 1;
                            }
                        }
                    }

                    Block rightBlock = world.GetBlock(blockX + 1, blockY, blockZ);

                    if (rightBlock != null)
                    {
                        if (rightBlock.GetType() == typeof(BlockAir))
                        {
                            world.SetBlock(blockX + 1, blockY, blockZ, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX + 1, blockY, blockZ) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX + 1, blockY, blockZ);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromMain = DistanceFromMain + 1;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #7
0
    public override void Seep(float deltaTime)
    {
        timer += deltaTime;

        if (timer > seepInterval)
        {
            timer = 0;

            if (DistanceFromOrigin < 8)
            {
                bool continueSideways = true;

                Block bottomBlock = world.GetBlock(blockX, blockY - 1, blockZ);

                if (bottomBlock != null)
                {
                    if (bottomBlock.GetType().Equals(typeof(BlockAir)))
                    {
                        continueSideways = false;
                        world.SetBlock(blockX, blockY - 1, blockZ, new BlockWater());

                        BlockWater newBlock = world.GetBlock(blockX, blockY - 1, blockZ)  as BlockWater;

                        if (newBlock != null)
                        {
                            newBlock.SetWorld(world, blockX, blockY - 1, blockZ);
                            newBlock.RegisterForUpdate();
                        }
                    }
                    //else if(bottomBlock.GetType().Equals(typeof(BlockWater)))
                    //continueSideways = false;
                }

                if (continueSideways == true)
                {
                    Block northBlock = world.GetBlock(blockX, blockY, blockZ + 1);

                    if (northBlock != null)
                    {
                        if (northBlock.GetType().Equals(typeof(BlockAir)))
                        {
                            world.SetBlock(blockX, blockY, blockZ + 1, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX, blockY, blockZ + 1) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX, blockY, blockZ + 1);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromOrigin = DistanceFromOrigin + 1;
                            }
                        }
                    }

                    Block southBlock = world.GetBlock(blockX, blockY, blockZ - 1);

                    if (southBlock != null)
                    {
                        if (southBlock.GetType().Equals(typeof(BlockAir)))
                        {
                            world.SetBlock(blockX, blockY, blockZ - 1, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX, blockY, blockZ - 1) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX, blockY, blockZ - 1);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromOrigin = DistanceFromOrigin + 1;
                            }
                        }
                    }

                    Block westBlock = world.GetBlock(blockX + 1, blockY, blockZ);

                    if (westBlock != null)
                    {
                        if (westBlock.GetType().Equals(typeof(BlockAir)))
                        {
                            world.SetBlock(blockX + 1, blockY, blockZ, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX + 1, blockY, blockZ) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX + 1, blockY, blockZ);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromOrigin = DistanceFromOrigin + 1;
                            }
                        }
                    }

                    Block eastBlock = world.GetBlock(blockX - 1, blockY, blockZ);

                    if (eastBlock != null)
                    {
                        if (eastBlock.GetType().Equals(typeof(BlockAir)))
                        {
                            world.SetBlock(blockX - 1, blockY, blockZ, new BlockWater());
                            BlockWater newBlock = world.GetBlock(blockX - 1, blockY, blockZ) as BlockWater;

                            if (newBlock != null)
                            {
                                newBlock.SetWorld(world, blockX - 1, blockY, blockZ);
                                newBlock.RegisterForUpdate();
                                newBlock.DistanceFromOrigin = DistanceFromOrigin + 1;
                            }
                        }
                    }
                }
            }
        }
    }