Add a per distance detonation sequence for bombs

This commit is contained in:
2025-12-16 19:16:18 +08:00
parent 5f0af52710
commit 7224da5fce
2 changed files with 31 additions and 26 deletions

View File

@@ -60,27 +60,31 @@ namespace Services
processed.Add(bombPos); processed.Add(bombPos);
int neighborDelayMs = Mathf.Max(0, Mathf.RoundToInt(bombDelaySeconds * 1000f)); int ringDelayMs = Mathf.RoundToInt(bombDelaySeconds * 1000f);
if (neighborDelayMs > 0)
await UniTask.Delay(neighborDelayMs);
foreach (Vector2Int n in DiamondNeighbors(bombPos, radius)) for (int dist = 1; dist <= radius; dist++)
{ {
if (!inBounds(n)) if (ringDelayMs > 0)
continue; await UniTask.Delay(ringDelayMs);
Gem g = getGemAt(n); foreach (Vector2Int n in DiamondRing(bombPos, dist))
if (g == null)
continue;
if (g.Type == GemType.Bomb)
{ {
if (!processed.Contains(n)) if (!inBounds(n))
queue.Enqueue(n); continue;
continue;
}
await destroyAtAsync(n); Gem g = getGemAt(n);
if (g == null)
continue;
if (g.Type == GemType.Bomb)
{
if (!processed.Contains(n))
queue.Enqueue(n);
continue;
}
await destroyAtAsync(n);
}
} }
int selfDelayMs = Mathf.Max(0, Mathf.RoundToInt(bombSelfDelaySeconds * 1000f)); int selfDelayMs = Mathf.Max(0, Mathf.RoundToInt(bombSelfDelaySeconds * 1000f));
@@ -92,18 +96,20 @@ namespace Services
await destroyAtAsync(bombPos); await destroyAtAsync(bombPos);
} }
} }
private static IEnumerable<Vector2Int> DiamondNeighbors(Vector2Int center, int radius) private static IEnumerable<Vector2Int> DiamondRing(Vector2Int center, int distance)
{ {
for (int x = -radius; x <= radius; x++) for (int distanceX = -distance; distanceX <= distance; distanceX++)
{ {
int maxY = radius - Mathf.Abs(x); int distanceY = distance - Mathf.Abs(distanceX);
for (int y = -maxY; y <= maxY; y++) if (distanceY == 0)
{ {
if (x == 0 && y == 0) yield return new Vector2Int(center.x + distanceX, center.y);
continue; }
else
yield return new Vector2Int(center.x + x, center.y + y); {
yield return new Vector2Int(center.x + distanceX, center.y + distanceY);
yield return new Vector2Int(center.x + distanceX, center.y - distanceY);
} }
} }
} }

View File

@@ -29,7 +29,6 @@ namespace Services {
if (this.gemTypeToPools[type].Count > 0) { if (this.gemTypeToPools[type].Count > 0) {
gemView = this.gemTypeToPools[type].Pop(); gemView = this.gemTypeToPools[type].Pop();
gemView.transform.localPosition = vector2Position; gemView.transform.localPosition = vector2Position;
return gemView; return gemView;
} }