示例#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 void CreateTileChunk(int x, int y)
    {
        TileWorldPos worldPos = new TileWorldPos(x, y);

        GameObject newTileChunkObject = Instantiate(TileChunkPrefab, new Vector3(x, y, 0), Quaternion.identity) as GameObject;

        TileChunk newChunk = newTileChunkObject.GetComponent <TileChunk>();

        newChunk.pos   = worldPos;
        newChunk.World = this;

        chunks.Add(worldPos, newChunk);

        for (int xi = 0; xi < 16; xi++)
        {
            for (int yi = 0; yi < 16; yi++)
            {
                SetTile(x + xi, y + yi, new TileAir());
            }
        }

        var terrainGen = new TileTerrainGeneration();

        newChunk = terrainGen.ChunkGen(newChunk);
        newChunk.SetTileUnmodified();
    }
 void UpdateIfEqual(int value1, int value2, TileWorldPos pos)
 {
     if (value1 == value2)
     {
         TileChunk chunk = GetChunk(pos.x, pos.y);
         if (chunk != null)
         {
             chunk.ChunkUpdate = true;
         }
     }
 }
示例#4
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);
    }
    public TileChunk GetChunk(int x, int y)
    {
        TileWorldPos pos       = new TileWorldPos();
        float        multipleX = TileChunk.ChunkSizeX;
        float        multipleY = TileChunk.ChunkSizeY;

        pos.x = Mathf.FloorToInt(x / multipleX) * TileChunk.ChunkSizeX;
        pos.y = Mathf.FloorToInt(y / multipleY) * TileChunk.ChunkSizeY;

        TileChunk containerChunk = null;

        chunks.TryGetValue(pos, out containerChunk);

        return(containerChunk);
    }
示例#6
0
    public override bool Equals(object obj)
    {
        if (!(obj is TileWorldPos))
        {
            return(false);
        }
        TileWorldPos pos = (TileWorldPos)obj;

        if (pos.x != x || pos.y != y)
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
示例#7
0
    public static TileWorldPos GetTilePos(Vector2 pos)
    {
        TileWorldPos TilePos = new TileWorldPos(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y));

        return(TilePos);
    }
    public static TileWorldPos GetTilePos(Vector2 pos)
    {
        TileWorldPos TilePos = new TileWorldPos(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y));

        return TilePos;
    }