TO SQUASH: Fixed oozeball split animation.

This commit is contained in:
2026-08-03 02:37:41 -04:00
parent 17051821b5
commit 6351d69fb1
5 changed files with 94 additions and 44 deletions
+54 -11
View File
@@ -39,7 +39,35 @@ public class BallSpawner : MonoBehaviour
StartCoroutine(SpawnBalls());
}
private void SpawnBall(GameObject ballPrefab)
public void SpawnBallOfType(string ballType, Vector2? position = null)
{
switch (ballType)
{
case "BasicBall":
SpawnBall(basicBallPrefab, position);
break;
case "NuclearBall":
SpawnBall(nuclearBallPrefab, position);
break;
case "GlassBall":
SpawnBall(glassBallPrefab, position);
break;
case "EyeBall":
SpawnBall(eyeBallPrefab, position);
break;
case "OozeBall":
SpawnBall(oozeBallPrefab, position);
break;
case "FruitBall":
SpawnBall(fruitBallPrefab, position);
break;
default:
Debug.LogWarning($"Unknown ball type: {ballType}");
break;
}
}
private void SpawnBall(GameObject ballPrefab, Vector2? position = null)
{
if (ballPrefab == null || gameBoard == null)
{
@@ -47,9 +75,20 @@ public class BallSpawner : MonoBehaviour
return;
}
Vector3 spawnPosition = GetRandomPositionInsideGameBoard();
Vector3 spawnPosition = position.HasValue ?
new Vector3(position.Value.x, position.Value.y, gameBoard.transform.position.z) :
GetRandomPositionInsideGameBoard();
var newBall = Instantiate(ballPrefab, spawnPosition, Quaternion.identity);
if (ballPrefab == oozeBallPrefab)
{
var oozeBallScript = newBall.GetComponent<OozeBall>();
if (oozeBallScript != null)
{
oozeBallScript.spawner = this;
}
}
balls.Enqueue(newBall);
}
@@ -81,15 +120,7 @@ public class BallSpawner : MonoBehaviour
return new Vector3(randomX, randomY, gameBoard.transform.position.z);
}
private IEnumerator SpawnBalls()
{
while (ballQueue.Count > 0)
{
System.Action spawnAction = ballQueue.Dequeue();
spawnAction.Invoke();
yield return _waitForSeconds0_5;
}
public void FixCollisions() {
// Disable collision between existing balls of certain types.
// Only basic balls and fruit balls will collide with each other, while ooze,
// nuclear, glass, and eye balls will not collide with any other balls.
@@ -117,4 +148,16 @@ public class BallSpawner : MonoBehaviour
}
}
}
private IEnumerator SpawnBalls()
{
while (ballQueue.Count > 0)
{
System.Action spawnAction = ballQueue.Dequeue();
spawnAction.Invoke();
yield return _waitForSeconds0_5;
}
FixCollisions();
}
}
+30 -8
View File
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections;
public class OozeBall : MonoBehaviour
{
@@ -16,19 +17,24 @@ public class OozeBall : MonoBehaviour
public AudioClip stoppedSound;
public BallSpawner spawner;
private AudioSource audioSource;
private SpriteRenderer spriteRenderer;
private Vector2 speed;
private float splitTimer = 30.0f;
private float splitTimer = 10.0f;
private float tickTimer = 1.0f;
private float tickTimer = 0.5f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
speed = new Vector2(Random.Range(-0.002f, 0.002f), Random.Range(-0.002f, 0.002f));
audioSource.PlayOneShot(spawnSound);
@@ -39,7 +45,7 @@ public class OozeBall : MonoBehaviour
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName("OozeBallMove")) {
if (stateInfo.IsName("OozeBallMove") || stateInfo.IsName("OozeBallSplit")) {
transform.Translate(speed);
}
@@ -48,13 +54,12 @@ public class OozeBall : MonoBehaviour
if (splitTimer <= 0.0f)
{
Split();
Destroy(gameObject);
animator.SetTrigger("split");
}
if (tickTimer <= 0.0f)
{
tickTimer = 1.0f;
tickTimer = 0.5f;
audioSource.PlayOneShot(timerSound);
}
@@ -72,9 +77,26 @@ public class OozeBall : MonoBehaviour
void Split()
{
animator.SetTrigger("split");
StartCoroutine(SplitCoroutine());
}
private IEnumerator SplitCoroutine()
{
spriteRenderer.enabled = false;
audioSource.PlayOneShot(splitSound);
// TODO: Implement the logic for splitting the OozeBall into smaller balls
for (int i = 0; i < Random.Range(5, 8); i++)
{
Vector3 spawnPosition = transform.position +
new Vector3(Random.Range(-0.12f, 0.12f), Random.Range(-0.12f, 0.12f), 0);
spawner.SpawnBallOfType("BasicBall", spawnPosition);
}
spawner.FixCollisions();
yield return new WaitForSeconds(1.0f);
Destroy(gameObject);
}
void Halt()