Example #1
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            TileDestroyCalc other = (TileDestroyCalc)obj;

            if (other != null)
            {
                return(other.destroyDistance.CompareTo(destroyDistance));
            }
            else
            {
                throw new ArgumentException("Object is not a TileDestroyCalc");
            }
        }
Example #2
0
    // Reads all the tiles and returns an order for when every tile will collapse
    private static Queue <TileDestroyCalc> CreateTileMapDestroyCalc(Tile[,,] tiles, Vector2 center, float bufferRadius)
    {
        TileDestroyCalc[] toSort = new TileDestroyCalc[tiles.GetLength(0) * tiles.GetLength(2)];
        for (int col = 0; col < tiles.GetLength(0); ++col)   // Loop through every X and Z position in the tile map
        {
            for (int row = 0; row < tiles.GetLength(2); ++row)
            {
                Vector2Int pos = new Vector2Int(col, row);
                toSort[row * tiles.GetLength(0) + col] = new TileDestroyCalc(pos, (pos - center).magnitude + UnityEngine.Random.Range(-bufferRadius, bufferRadius)); // Get distance from center plus some noise
            }
        }
        Array.Sort(toSort);
        Queue <TileDestroyCalc> result = new Queue <TileDestroyCalc>();

        foreach (TileDestroyCalc t in toSort)
        {
            result.Enqueue(t);
        }
        return(result);
    }