示例#1
0
    /// <summary>
    /// Get the count of the surrounding tiles that match the passed in tile type. Radius of 1 = a 3x3 grid, radius of 2 = 5x5 grid... etc.
    /// </summary>
    /// <param name="tileType"></param>
    /// <param name="gridSize"></param>
    /// <param name="pos"></param>
    /// <returns></returns>
    public int GetSurroundingTiles(MapTile.Type tileType, int radius, Vector2 pos)
    {
        int     count = 0;
        Vector2 index = worldPosToIndex(pos.x, pos.y);

        Debug.Log("Tiles location: " + index.x + "," + index.y);

        for (int i = (int)index.x - radius; i <= index.x + radius; i++)
        {
            for (int j = (int)index.y - radius; j <= index.y + radius; j++)
            {
                if (i < 0 || i >= width - 1 || j < 0 || j >= height - 1)
                {
                    continue;
                }

                Debug.Log("Tiles location: " + i + "," + j);
                Debug.Log("Tile: " + map[i, j].getBiome() + " Location: " + tileType);
                if (map[i, j].getBiome() == tileType)
                {
                    count++;
                }
            }
        }

        return(count);
    }
示例#2
0
    public void addTile(MapTile.Type type, int x, int y)
    {
        MapTile tile = new MapTile(type);

        map[x, y] = tile;
    }