Esempio n. 1
0
    private void Update()
    {
        if (Playing && !InGui)
        {
            if (!cLock && Input.GetMouseButtonDown(0))
            {
                cLock = true;
            }
            else if (cLock && Input.GetKeyDown(KeyCode.Escape))
            {
                cLock = false;
            }
        }
        else if (Playing)
        {
            cLock = true;
        }

        if (InGui)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;
        }

        Vector3 playerPosition = PlayerController.getInstance().transform.position;

        BlockPos playerPos = new BlockPos(Mathf.FloorToInt(playerPosition.x), Mathf.FloorToInt(playerPosition.y), Mathf.FloorToInt(playerPosition.z));



        ChunkPos pos = cWorld.getChunkPosAt(playerPos);

        Debug.Log("x: " + pos.getX() + " - y: " + playerPos.getY() + " - y: " + pos.getZ());

        for (int x = pos.getX() - 1; x < pos.getX() + 1; x++)
        {
            for (int z = pos.getZ() - 1; z < pos.getZ() + 1; z++)
            {
                ChunkPos thisOne = new ChunkPos(x, z);
                if (cWorld.getChunkAt(thisOne) == null)
                {
                    cWorld.loadChunk(pos);
                }
            }
        }
    }
Esempio n. 2
0
 public Chunk getChunkAt(ChunkPos pos)
 {
     foreach (Chunk c in chunks)
     {
         if (c.getPos().getX() == pos.getX() && c.getPos().getZ() == pos.getZ())
         {
             return(c);
         }
     }
     return(null);
 }
Esempio n. 3
0
    IEnumerator blockMake()
    {
        for (int x = 0 + (pos.getX() * 16); x < 16 + (pos.getX() * 16); x++)
        {
            for (int y = 0; y < 4; y++)
            {
                for (int z = 0 + (pos.getZ() * 16); z < 16 + (pos.getZ() * 16); z++)
                {
                    GameObject block = GameObject.Instantiate(blockTemplate);

                    BlockHolder b = block.AddComponent <BlockHolder>();
                    b.pos = new BlockPos(x, y, z);
                    block.transform.position = new Vector3(x, y, z);

                    if (y == 3)
                    {
                        b.blockNameForTestingBecauseImTooLazyTooWriteMoreCodeForThis = "dirt";
                    }
                    else if (y == 0)
                    {
                        b.blockNameForTestingBecauseImTooLazyTooWriteMoreCodeForThis = "bedrock";
                    }
                    else
                    {
                        b.blockNameForTestingBecauseImTooLazyTooWriteMoreCodeForThis = "stone";
                    }

                    b.updateSides();

                    blocks.Add(b);

                    yield return(new WaitForSeconds(0.1f));
                }
            }
        }
    }