TO SQUASH: Ball reset.

This commit is contained in:
2026-08-27 16:12:47 -04:00
parent 04ccf01eb4
commit 414ebc99ff
3 changed files with 116 additions and 14 deletions
+111 -11
View File
@@ -18,12 +18,16 @@ public class BallSpawner : Spawner
public GameObject gameBoard;
public Player player;
private static WaitForSeconds _waitForSeconds0_5 = new WaitForSeconds(0.5f);
private Queue<System.Action> ballQueue = new Queue<System.Action>();
private Queue<GameObject> balls = new Queue<GameObject>();
private int basicBallCount = 0;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
@@ -31,17 +35,7 @@ public class BallSpawner : Spawner
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(oozeBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(nuclearBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab));
basicBallCount = 2;
StartCoroutine(SpawnBalls());
}
@@ -74,6 +68,112 @@ public class BallSpawner : Spawner
}
}
public void ResetBalls()
{
// Clear all balls.
int nukeBallCount = 0;
int glassBallCount = 0;
int eyeBallCount = 0;
int oozeBallCount = 0;
int fruitBallCount = 0;
foreach (var ball in balls)
{
if (ball != null)
{
if (ball.CompareTag("NuclearBall"))
{
nukeBallCount++;
}
else if (ball.CompareTag("GlassBall"))
{
glassBallCount++;
}
else if (ball.CompareTag("EyeBall"))
{
eyeBallCount++;
}
else if (ball.CompareTag("OozeBall"))
{
oozeBallCount++;
}
else if (ball.CompareTag("FruitBall"))
{
fruitBallCount++;
}
Destroy(ball);
}
}
balls.Clear();
// Always spawn one basic ball more than in the previous level.
basicBallCount++;
// At special levels force spawn certain types of balls.
if (player.level % 5 == 0)
{
// One nuclear ball each five levels.
nukeBallCount++;
if (player.level >= 10)
{
// Glass balls after level 10.
glassBallCount += Random.Range(1, 3);
}
if (player.level >= 15)
{
// An extra nuke ball after level 15.
nukeBallCount++;
// Eye balls after level 15.
eyeBallCount++;
}
if (player.level >= 20)
{
// Ooze balls after level 20.
oozeBallCount++;
}
// No extra basic ball when a special ball spawns for the first time.
basicBallCount--;
}
// Spawn balls.
for (int i = 0; i < basicBallCount; i++)
{
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
}
for (int i = 0; i < nukeBallCount; i++)
{
ballQueue.Enqueue(() => SpawnBall(nuclearBallPrefab));
}
for (int i = 0; i < glassBallCount; i++)
{
ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
}
for (int i = 0; i < eyeBallCount; i++)
{
ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab));
}
for (int i = 0; i < oozeBallCount; i++)
{
ballQueue.Enqueue(() => SpawnBall(oozeBallPrefab));
}
for (int i = 0; i < fruitBallCount; i++)
{
ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
}
StartCoroutine(SpawnBalls());
}
private void SpawnBall(GameObject ballPrefab, Vector2? position = null)
{
if (ballPrefab == null || gameBoard == null)