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,11 +60,14 @@ 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 (ringDelayMs > 0)
await UniTask.Delay(ringDelayMs);
foreach (Vector2Int n in DiamondRing(bombPos, dist))
{ {
if (!inBounds(n)) if (!inBounds(n))
continue; continue;
@@ -82,6 +85,7 @@ namespace Services
await destroyAtAsync(n); await destroyAtAsync(n);
} }
}
int selfDelayMs = Mathf.Max(0, Mathf.RoundToInt(bombSelfDelaySeconds * 1000f)); int selfDelayMs = Mathf.Max(0, Mathf.RoundToInt(bombSelfDelaySeconds * 1000f));
if (selfDelayMs > 0) if (selfDelayMs > 0)
@@ -93,17 +97,19 @@ namespace Services
} }
} }
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;
} }