From 716e35c6157731d815d9ec11b4515b4f0f8669bb Mon Sep 17 00:00:00 2001 From: Miguel Astor Date: Fri, 28 Aug 2026 17:44:31 -0400 Subject: [PATCH] TO SQUASH: Nuke ball fixes. --- Assets/Animations/Yummies/YummyKeyBounce.anim | 2 +- .../Yummies/YummyLigthningBounce.anim | 2 +- Assets/Scenes/Game.unity | 1 + Assets/Scripts/Game/Balls/NukeBall.cs | 32 +++++-- Assets/Scripts/Game/Player/Player.cs | 2 +- Assets/Scripts/Game/Spawners/BallSpawner.cs | 11 +++ Assets/Scripts/Game/Spawners/SharkSpawner.cs | 2 +- Assets/Scripts/Game/WorldFiller.cs | 20 +++- Assets/Scripts/Game/Yummies/YummyCake.cs | 2 +- ProjectSettings/ProjectSettings.asset | 94 ++++++++++++++++++- 10 files changed, 153 insertions(+), 15 deletions(-) diff --git a/Assets/Animations/Yummies/YummyKeyBounce.anim b/Assets/Animations/Yummies/YummyKeyBounce.anim index ccb8165..72c02d4 100644 --- a/Assets/Animations/Yummies/YummyKeyBounce.anim +++ b/Assets/Animations/Yummies/YummyKeyBounce.anim @@ -101,7 +101,7 @@ AnimationClip: m_Level: 0 m_CycleOffset: 0 m_HasAdditiveReferencePose: 0 - m_LoopTime: 0 + m_LoopTime: 1 m_LoopBlend: 0 m_LoopBlendOrientation: 0 m_LoopBlendPositionY: 0 diff --git a/Assets/Animations/Yummies/YummyLigthningBounce.anim b/Assets/Animations/Yummies/YummyLigthningBounce.anim index 4bb4c4b..bed3f65 100644 --- a/Assets/Animations/Yummies/YummyLigthningBounce.anim +++ b/Assets/Animations/Yummies/YummyLigthningBounce.anim @@ -107,7 +107,7 @@ AnimationClip: m_Level: 0 m_CycleOffset: 0 m_HasAdditiveReferencePose: 0 - m_LoopTime: 0 + m_LoopTime: 1 m_LoopBlend: 0 m_LoopBlendOrientation: 0 m_LoopBlendPositionY: 0 diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 1c923a3..837d34a 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -1187,6 +1187,7 @@ MonoBehaviour: fruitBallPrefab: {fileID: 3086586548818580311, guid: b67974a0c09fbe75aac299e30a0c665b, type: 3} gameBoard: {fileID: 297740150} player: {fileID: 1002905792} + worldFiller: {fileID: 2071167548} --- !u!4 &240489637 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/Balls/NukeBall.cs b/Assets/Scripts/Game/Balls/NukeBall.cs index 80e0709..a99ede0 100644 --- a/Assets/Scripts/Game/Balls/NukeBall.cs +++ b/Assets/Scripts/Game/Balls/NukeBall.cs @@ -6,10 +6,12 @@ public class NukeBall : BallBase public AudioClip explosionSound; + public WorldFiller worldFiller; + // Tracks escalating danger/critical phases for audio cues. private int criticalState = 0; - private float criticalTime = 1.0f; + private float criticalTime = 0.5f; private float criticalTimer = 0.0f; @@ -92,12 +94,16 @@ public class NukeBall : BallBase transform.position = currentPosition; } + } - // When in critical state 2, play the critical sound every half a second. - if (criticalState == 2) - { - criticalTimer = 0.5f; - } + void Update() + { + // Set critical state. + var area = worldFiller != null ? worldFiller.GetAreaPercentOfFreeRegion(transform.position) : -1.0f; + criticalState = (area < 0.2f) ? 2 : (area < 0.4f) ? 1 : 0; + + // State 1 beeps every 0.5s, state 2 beeps every 0.25s. + criticalTime = (criticalState == 2) ? 0.5f : 1.0f; // If in a critical state, increment the critical timer and play the // critical sound if the timer exceeds the critical time. @@ -108,9 +114,13 @@ public class NukeBall : BallBase if (criticalTimer >= criticalTime) { audioSource.PlayOneShot(criticalSound); - } - // Restart timing window for the next critical beep. + // Keep fractional overflow so cadence stays stable across frame rates. + criticalTimer -= criticalTime; + } + } + else + { criticalTimer = 0.0f; } } @@ -142,6 +152,12 @@ public class NukeBall : BallBase currentPosition.y = bounceStartY; transform.position = currentPosition; } + else if (contact.normal.y <= -0.5f) + { + isBouncingToHeight = false; + bounceTimer = 0.0f; + height = contact.point.y - 0.01f; + } } else { diff --git a/Assets/Scripts/Game/Player/Player.cs b/Assets/Scripts/Game/Player/Player.cs index e6ea867..ae705eb 100644 --- a/Assets/Scripts/Game/Player/Player.cs +++ b/Assets/Scripts/Game/Player/Player.cs @@ -251,7 +251,7 @@ public class Player : MonoBehaviour // Mouse input handling for firing lasers, magnets, or normal barriers. if ( Mouse.current.leftButton.wasPressedThisFrame && - worldFiller.IsPositionInFreeArea(transform.position) && + worldFiller.IsPositionInFreeRegion(transform.position) && canFire && !exploding ) diff --git a/Assets/Scripts/Game/Spawners/BallSpawner.cs b/Assets/Scripts/Game/Spawners/BallSpawner.cs index ec7cbdd..92b9a48 100644 --- a/Assets/Scripts/Game/Spawners/BallSpawner.cs +++ b/Assets/Scripts/Game/Spawners/BallSpawner.cs @@ -20,6 +20,8 @@ public class BallSpawner : Spawner public Player player; + public WorldFiller worldFiller; + private static WaitForSeconds _waitForSeconds0_5 = new WaitForSeconds(0.5f); private Queue ballQueue = new Queue(); @@ -35,6 +37,7 @@ public class BallSpawner : Spawner ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); + ballQueue.Enqueue(() => SpawnBall(nuclearBallPrefab)); basicBallCount = 2; StartCoroutine(SpawnBalls()); @@ -195,6 +198,14 @@ public class BallSpawner : Spawner oozeBallScript.spawner = this; } } + else if (ballPrefab == nuclearBallPrefab) + { + var nuclearBallScript = newBall.GetComponent(); + if (nuclearBallScript != null) + { + nuclearBallScript.worldFiller = worldFiller; + } + } balls.Enqueue(newBall); diff --git a/Assets/Scripts/Game/Spawners/SharkSpawner.cs b/Assets/Scripts/Game/Spawners/SharkSpawner.cs index 69421a5..6711479 100644 --- a/Assets/Scripts/Game/Spawners/SharkSpawner.cs +++ b/Assets/Scripts/Game/Spawners/SharkSpawner.cs @@ -32,7 +32,7 @@ public class SharkSpawner : Spawner { spawnTimer += Time.fixedDeltaTime; - if (spawnTimer >= 1f && isActive && isSpawning && player.level >= 1) + if (spawnTimer >= 1f && isActive && isSpawning && player.level >= 10) { spawnTimer = 0f; if (Random.value < spawnProbability) diff --git a/Assets/Scripts/Game/WorldFiller.cs b/Assets/Scripts/Game/WorldFiller.cs index 689edb1..eb80fd5 100644 --- a/Assets/Scripts/Game/WorldFiller.cs +++ b/Assets/Scripts/Game/WorldFiller.cs @@ -281,7 +281,7 @@ public class WorldFiller : MonoBehaviour boardArea = boardRect.width * boardRect.height; } - public bool IsPositionInFreeArea(Vector2 position) + public bool IsPositionInFreeRegion(Vector2 position) { if (freeAreas.Count == 0 && gameBoardSpriteRenderer != null) { @@ -299,6 +299,24 @@ public class WorldFiller : MonoBehaviour return false; } +public float GetAreaPercentOfFreeRegion(Vector2 position) + { + if (freeAreas.Count == 0 && gameBoardSpriteRenderer != null) + { + InitializeFreeAreas(); + } + + for (int i = 0; i < freeAreas.Count; i++) + { + if (RectContainsWithTolerance(freeAreas[i], position)) + { + return (freeAreas[i].width * freeAreas[i].height) / boardArea; + } + } + + return -1.0f; + } + public Vector2 GetRandomPositionInFreeAreas(Bounds? clearingArea = null) { if (freeAreas.Count == 0 && gameBoardSpriteRenderer != null) diff --git a/Assets/Scripts/Game/Yummies/YummyCake.cs b/Assets/Scripts/Game/Yummies/YummyCake.cs index c82418c..584b4f7 100644 --- a/Assets/Scripts/Game/Yummies/YummyCake.cs +++ b/Assets/Scripts/Game/Yummies/YummyCake.cs @@ -50,7 +50,7 @@ public class YummyCake : MonoBehaviour public void BreakOrMiss() { // TODO: Implement logic to check if the cake is in a clear area or not - bool inClearArea = worldFiller.IsPositionInFreeArea(transform.position); + bool inClearArea = worldFiller.IsPositionInFreeRegion(transform.position); if (inClearArea) { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 6930745..2edd30d 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -306,7 +306,99 @@ PlayerSettings: m_Width: 128 m_Height: 128 m_Kind: 0 - m_BuildTargetPlatformIcons: [] + m_BuildTargetPlatformIcons: + - m_BuildTarget: Android + m_Icons: + - m_Textures: [] + m_Width: 432 + m_Height: 432 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 324 + m_Height: 324 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 216 + m_Height: 216 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 162 + m_Height: 162 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 108 + m_Height: 108 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 81 + m_Height: 81 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 192 + m_Height: 192 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 144 + m_Height: 144 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 96 + m_Height: 96 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 72 + m_Height: 72 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 48 + m_Height: 48 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 36 + m_Height: 36 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 192 + m_Height: 192 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 144 + m_Height: 144 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 96 + m_Height: 96 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 72 + m_Height: 72 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 48 + m_Height: 48 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 36 + m_Height: 36 + m_Kind: 0 + m_SubKind: m_BuildTargetBatching: - m_BuildTarget: Standalone m_StaticBatching: 1