Пример #1
0
 public Block GetBlock(TriPos triPos)
 {
     if (baseTriPos == null)
     {
         baseTriPos = pos.toTriPos();              //todo: cache better
     }
     if (InRangeX(triPos.x) && InRangeY(triPos.y))
     {
         return(blocks[baseTriPos.x - triPos.x, baseTriPos.y - triPos.y]);
     }
     return(world.GetBlock(triPos));
 }
Пример #2
0
    public void CreateChunk(ChunkPos chunkPos)
    {
        WorldPos worldPos = chunkPos.toWorldPos();

        //Instantiate the chunk at its world coordinates
        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(worldPos.x, worldPos.y),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = chunkPos;
        newChunk.world = this;

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(chunkPos, newChunk);

        TriPos startTriPos = chunkPos.toTriPos();

        for (int xi = 0; xi < chunkXSize; xi++)
        {
            for (int yi = 0; yi < chunkYSize; yi++)
            {
                TriPos triPos = new TriPos(startTriPos.x + xi, startTriPos.y + yi);
                SetBlock(triPos, new Block());
            }
        }
    }