Exemple #1
0
    void FindChunksToLoad()
    {
        //Get the position of this gameobject to generate around
        TileWorldPos playerPos = new TileWorldPos(
            Mathf.FloorToInt(transform.position.x / TileChunk.ChunkSizeX) * TileChunk.ChunkSizeX, Mathf.FloorToInt(transform.position.y / TileChunk.ChunkSizeY) * TileChunk.ChunkSizeY);

        //If there aren't already chunks to generat
        //Cycle through the array of positions
        for (int i = 0; i < ChunkPosition.Count; i++)
        {
            //translate the player position and array position into chunk position
            TileWorldPos newChunkPos = new TileWorldPos(ChunkPosition[i].x * TileChunk.ChunkSizeX + playerPos.x, ChunkPosition[i].y * TileChunk.ChunkSizeY + playerPos.y);

            //Get the chunk in the defined position
            TileChunk newChunk = World.GetChunk(newChunkPos.x, newChunkPos.y);

            //If the chunk already exists and it's already
            //rendered or in queue to be rendered continue
            if (newChunk != null)
            {
                continue;
            }

            //load a column of chunks in this position

            updateList.Add(new TileWorldPos(newChunkPos.x, newChunkPos.y));
        }
    }
    public static bool SetTile(TileWorld World, Tile tile, Vector2 Pos)
    {
        TileChunk chunk = World.GetChunk(Mathf.RoundToInt(Pos.x), Mathf.RoundToInt(Pos.y));
        if (chunk == null)
            return false;

        TileWorldPos pos = GetTilePos(Pos);

        chunk.World.SetTile(pos.x, pos.y, tile);

        return true;
    }
Exemple #3
0
    public static bool SetTile(TileWorld World, Tile tile, Vector2 Pos)
    {
        TileChunk chunk = World.GetChunk(Mathf.RoundToInt(Pos.x), Mathf.RoundToInt(Pos.y));

        if (chunk == null)
        {
            return(false);
        }

        TileWorldPos pos = GetTilePos(Pos);

        chunk.World.SetTile(pos.x, pos.y, tile);

        return(true);
    }