Update BombService.cs
- Matched bombs now explode one at a time
This commit is contained in:
@@ -118,75 +118,55 @@ namespace Services
|
||||
|
||||
while (waveQueue.Count > 0)
|
||||
{
|
||||
// current wave (per bomb)
|
||||
List<Vector2Int> waveBombs = new List<Vector2Int>();
|
||||
while (waveQueue.Count > 0)
|
||||
{
|
||||
Vector2Int b = waveQueue.Dequeue();
|
||||
if (processedBombs.Contains(b))
|
||||
Vector2Int bombPos = waveQueue.Dequeue();
|
||||
|
||||
if (processedBombs.Contains(bombPos))
|
||||
continue;
|
||||
|
||||
if (!GemUtils.IsInBounds(b, gameBoard))
|
||||
if (!GemUtils.IsInBounds(bombPos, gameBoard))
|
||||
continue;
|
||||
|
||||
Gem g = gameBoard.GetGemAt(b);
|
||||
Gem g = gameBoard.GetGemAt(bombPos);
|
||||
if (g is not { Type: GemType.Bomb })
|
||||
continue;
|
||||
|
||||
processedBombs.Add(b);
|
||||
waveBombs.Add(b);
|
||||
}
|
||||
processedBombs.Add(bombPos);
|
||||
|
||||
if (waveBombs.Count == 0)
|
||||
continue;
|
||||
|
||||
// delay once per wave
|
||||
if (waveDelayMs > 0)
|
||||
// delay once per bomb
|
||||
await UniTask.Delay(waveDelayMs);
|
||||
|
||||
HashSet<Vector2Int> nextWaveBombs = new HashSet<Vector2Int>();
|
||||
HashSet<Vector2Int> toDestroyNow = new HashSet<Vector2Int>();
|
||||
|
||||
for (int i = 0; i < waveBombs.Count; i++)
|
||||
{
|
||||
Vector2Int bombPos = waveBombs[i];
|
||||
|
||||
// destroy self when it detonates
|
||||
toDestroyNow.Add(bombPos);
|
||||
|
||||
foreach (Vector2Int p in DiamondAreaInclusive(bombPos, this.gameVariables.bombRadius))
|
||||
foreach (Vector2Int position in DiamondAreaInclusive(bombPos, this.gameVariables.bombRadius))
|
||||
{
|
||||
if (!GemUtils.IsInBounds(p, gameBoard))
|
||||
if (!GemUtils.IsInBounds(position, gameBoard))
|
||||
continue;
|
||||
|
||||
if (p == bombPos)
|
||||
if (position == bombPos)
|
||||
continue;
|
||||
|
||||
Gem cellGem = gameBoard.GetGemAt(p);
|
||||
Gem cellGem = gameBoard.GetGemAt(position);
|
||||
if (cellGem == null)
|
||||
continue;
|
||||
|
||||
if (cellGem.Type == GemType.Bomb)
|
||||
{
|
||||
// bombs in range are NOT destroyed now. triggered to explode in a later wave.
|
||||
if (!processedBombs.Contains(p))
|
||||
nextWaveBombs.Add(p);
|
||||
// bombs in range are NOT destroyed now. triggered to explode in a later "step".
|
||||
if (!processedBombs.Contains(position))
|
||||
waveQueue.Enqueue(position);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Non-bomb gem gets destroyed by this bomb
|
||||
toDestroyNow.Add(p);
|
||||
}
|
||||
toDestroyNow.Add(position);
|
||||
}
|
||||
|
||||
// Destroy everything for this wave (non-bombs in range and the detonating bombs themselves)
|
||||
// Destroy everything for this specific bomb detonation
|
||||
foreach (Vector2Int p in toDestroyNow)
|
||||
await destroyAtAsync(p);
|
||||
|
||||
// Schedule the next wave (triggered bombs)
|
||||
foreach (Vector2Int b in nextWaveBombs)
|
||||
waveQueue.Enqueue(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user