TO SQUASH: Added yummy cake.

This commit is contained in:
2026-08-06 20:00:41 -04:00
parent 49ea95bfe5
commit 456b5d998e
9 changed files with 230 additions and 92 deletions
+11 -11
View File
@@ -31,17 +31,17 @@ public class BallSpawner : MonoBehaviour
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));
// 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));
StartCoroutine(SpawnBalls());
}
+62 -3
View File
@@ -2,15 +2,74 @@ using UnityEngine;
public class CakeSpawner : MonoBehaviour
{
public GameObject cakePrefab;
public SpriteRenderer gameBoardSpriteRenderer;
private Bounds cakeBounds;
private Bounds gameBoardBounds;
private float spawnTimer = 0f;
private float spawnInterval = 10f;
private Vector2 spawnPosition;
private bool spawned = false;
private static float spawnProbability = 0.9f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
gameBoardBounds = gameBoardSpriteRenderer.bounds;
cakeBounds = cakePrefab.GetComponent<SpriteRenderer>().bounds;
Reset();
}
// Update is called once per frame
void Update()
void FixedUpdate()
{
if (!spawned)
{
spawnTimer += Time.fixedDeltaTime;
if (spawnTimer >= 1f)
{
spawnTimer = 0f;
if (Random.value < spawnProbability)
{
GameObject cake = Instantiate(cakePrefab, spawnPosition, Quaternion.identity);
}
spawned = true;
}
}
else
{
spawnTimer += Time.fixedDeltaTime;
if (spawnTimer >= spawnInterval)
{
Reset();
}
}
}
public void Reset()
{
spawned = false;
spawnTimer = 0f;
spawnPosition = new Vector2(
Random.Range(
gameBoardBounds.min.x + cakeBounds.extents.x,
gameBoardBounds.max.x - cakeBounds.extents.x
),
Random.Range(
gameBoardBounds.min.y + cakeBounds.extents.y,
gameBoardBounds.max.y - cakeBounds.extents.y
)
);
}
}
+104 -4
View File
@@ -2,15 +2,115 @@ using UnityEngine;
public class YummyCake : MonoBehaviour
{
public AudioClip spawnSound;
public AudioClip breakSound;
public AudioClip missedSound;
public AudioClip stormSound;
public GameObject lightningPrefab;
public GameObject laserPrefab;
public GameObject magnetPrefab;
public GameObject keyPrefab;
private AudioSource audioSource;
private Animator animator;
private static float laserProbability = 0.4f;
private static float magnetProbability = 0.2f;
private static float keyProbability = 0.1f;
private static float manyProbability = 0.2f;
private static float stormProbability = 0.01f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
audioSource.PlayOneShot(spawnSound);
}
// Update is called once per frame
void Update()
public void BreakOrMiss()
{
// TODO: Implement logic to check if the cake is in a clear area or not
bool inClearArea = true;
if (inClearArea)
{
animator.SetTrigger("break");
audioSource.PlayOneShot(breakSound);
Break();
}
else
{
animator.SetTrigger("miss");
audioSource.PlayOneShot(missedSound);
}
}
public void OnAnimationComplete()
{
Destroy(gameObject);
}
private void SpawnItem(float randomValue)
{
if (randomValue < laserProbability)
{
Instantiate(laserPrefab, transform.position, Quaternion.identity);
}
else if (randomValue < magnetProbability)
{
Instantiate(magnetPrefab, transform.position, Quaternion.identity);
}
else if (randomValue < keyProbability)
{
Instantiate(keyPrefab, transform.position, Quaternion.identity);
}
else
{
Instantiate(lightningPrefab, transform.position, Quaternion.identity);
}
}
private void Break()
{
float isStorm = Random.value;
if (isStorm < stormProbability)
{
// Trigger a storm event, ie. spawn multiple items at once.
audioSource.PlayOneShot(stormSound);
for (int i = 0; i < Random.Range(8, 12); i++)
{
float randomValue = Random.value;
SpawnItem(randomValue);
}
}
else
{
// The first yummy is guaranteed.
float randomValue = 0.0f;
while (randomValue < manyProbability)
{
SpawnItem(randomValue);
// Update randomValue to determine if we should spawn another item.
randomValue = Random.value;
}
}
}
}