From dbed42424f9c00b7c43fbe88e2e7e2303d1662c5 Mon Sep 17 00:00:00 2001 From: Miguel Astor Date: Thu, 27 Aug 2026 22:05:44 -0400 Subject: [PATCH] TO SQUASH: Shark notifications. --- Assets/Prefabs/Shark.prefab | 2 + Assets/Scenes/Game.unity | 1 + Assets/Scripts/Game/NotifierBase.cs | 62 ++++++++++++++++++++ Assets/Scripts/Game/NotifierBase.cs.meta | 2 + Assets/Scripts/Game/Shark.cs | 16 ++++- Assets/Scripts/Game/Spawners/SharkSpawner.cs | 5 +- Assets/Scripts/Game/Yummies/YummyBase.cs | 57 +----------------- 7 files changed, 85 insertions(+), 60 deletions(-) create mode 100644 Assets/Scripts/Game/NotifierBase.cs create mode 100644 Assets/Scripts/Game/NotifierBase.cs.meta diff --git a/Assets/Prefabs/Shark.prefab b/Assets/Prefabs/Shark.prefab index e09b85e..6307b5c 100644 --- a/Assets/Prefabs/Shark.prefab +++ b/Assets/Prefabs/Shark.prefab @@ -308,6 +308,8 @@ MonoBehaviour: hitSound: {fileID: 8300000, guid: 0535a1781b9d2e8018f56aa45b71932a, type: 3} player: {fileID: 0} gameBoardSpriteRenderer: {fileID: 0} + notificationPrefab: {fileID: 6394082776706812922, guid: 5cb297a990ab535aa8ef2b8054c9db1b, type: 3} + canvas: {fileID: 0} normalMaxSpeed: 2.5 turnRateDegreesPerSecond: 180 speedChangeRate: 4 diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 16110dd..1c923a3 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -462,6 +462,7 @@ MonoBehaviour: sharkPrefab: {fileID: 1185323843861964289, guid: 4bb45ba16a3bbd351a45d39c3f0b62f9, type: 3} gameBoardSpriteRenderer: {fileID: 297740151} player: {fileID: 1002905792} + canvas: {fileID: 2071745861} --- !u!1 &83016091 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/NotifierBase.cs b/Assets/Scripts/Game/NotifierBase.cs new file mode 100644 index 0000000..c9bf75b --- /dev/null +++ b/Assets/Scripts/Game/NotifierBase.cs @@ -0,0 +1,62 @@ +using UnityEngine; +using System.Collections; + +public class NotifierBase : MonoBehaviour +{ + + public Canvas canvas; + + public GameObject notificationPrefab; + + protected GameObject notificationInstance; + + + protected void ShowNotification(string text) + { + if (notificationPrefab == null || canvas == null) + { + return; + } + + notificationInstance = Instantiate(notificationPrefab); + notificationInstance.transform.SetParent(canvas.transform, false); + notificationInstance.transform.localScale = Vector3.one; + + var notificationRect = notificationInstance.GetComponent(); + var canvasRect = canvas.GetComponent(); + var label = notificationInstance.GetComponent(); + + if (label != null) + { + label.text = text; + } + + if (notificationRect != null && canvasRect != null) + { + Camera worldCamera = canvas.worldCamera != null ? canvas.worldCamera : Camera.main; + Camera uiCamera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : worldCamera; + + if (worldCamera != null) + { + Vector2 screenPoint = worldCamera.WorldToScreenPoint(transform.position); + + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, uiCamera, out Vector2 localPoint)) + { + notificationRect.anchoredPosition = localPoint; + } + } + } + + StartCoroutine(HideNotification()); + } + + protected IEnumerator HideNotification() + { + yield return new WaitForSeconds(1.5f); + + if (notificationInstance != null) + { + Destroy(notificationInstance); + } + } +} diff --git a/Assets/Scripts/Game/NotifierBase.cs.meta b/Assets/Scripts/Game/NotifierBase.cs.meta new file mode 100644 index 0000000..8647155 --- /dev/null +++ b/Assets/Scripts/Game/NotifierBase.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c976d582b8415504b9c7e375271452a2 \ No newline at end of file diff --git a/Assets/Scripts/Game/Shark.cs b/Assets/Scripts/Game/Shark.cs index 97fa306..2527c9e 100644 --- a/Assets/Scripts/Game/Shark.cs +++ b/Assets/Scripts/Game/Shark.cs @@ -1,7 +1,7 @@ using UnityEngine; using System.Collections; -public class Shark : MonoBehaviour +public class Shark : NotifierBase { public AudioClip spawnSound; @@ -37,7 +37,7 @@ public class Shark : MonoBehaviour private float angryProbability = 0.1f; - private static int sharkKillPoints = 100; + private static int sharkKillPoints = 1000; private bool spawnFinished = false; @@ -167,7 +167,17 @@ public class Shark : MonoBehaviour } audioSource.PlayOneShot(deathSound); - player.score += sharkKillPoints; + player.score += sharkKillPoints + (isAngry ? 500 : 0); + + if (isAngry) + { + ShowNotification("1500"); + } + else + { + ShowNotification("1000"); + } + StartCoroutine(DestroyShark()); } diff --git a/Assets/Scripts/Game/Spawners/SharkSpawner.cs b/Assets/Scripts/Game/Spawners/SharkSpawner.cs index ea38731..69421a5 100644 --- a/Assets/Scripts/Game/Spawners/SharkSpawner.cs +++ b/Assets/Scripts/Game/Spawners/SharkSpawner.cs @@ -8,6 +8,8 @@ public class SharkSpawner : Spawner public Player player; + public Canvas canvas; + private Bounds gameBoardBounds; private float spawnTimer = 0f; @@ -30,7 +32,7 @@ public class SharkSpawner : Spawner { spawnTimer += Time.fixedDeltaTime; - if (spawnTimer >= 1f && isActive && isSpawning && player.level >= 10) + if (spawnTimer >= 1f && isActive && isSpawning && player.level >= 1) { spawnTimer = 0f; if (Random.value < spawnProbability) @@ -39,6 +41,7 @@ public class SharkSpawner : Spawner Shark sharkScript = shark.GetComponent(); sharkScript.gameBoardSpriteRenderer = gameBoardSpriteRenderer; sharkScript.player = player; + sharkScript.canvas = canvas; isActive = false; } } diff --git a/Assets/Scripts/Game/Yummies/YummyBase.cs b/Assets/Scripts/Game/Yummies/YummyBase.cs index 1c1d744..88f5602 100644 --- a/Assets/Scripts/Game/Yummies/YummyBase.cs +++ b/Assets/Scripts/Game/Yummies/YummyBase.cs @@ -1,7 +1,7 @@ using UnityEngine; using System.Collections; -public abstract class YummyBase : MonoBehaviour +public abstract class YummyBase : NotifierBase { public AudioClip bounceSound; @@ -9,12 +9,6 @@ public abstract class YummyBase : MonoBehaviour public AudioClip missedSound; - public Canvas canvas; - - public GameObject notificationPrefab; - - protected GameObject notificationInstance; - private AudioSource audioSource; private Animator animator; @@ -119,53 +113,4 @@ public abstract class YummyBase : MonoBehaviour } protected abstract void ObtainedCallback(Player player); - - protected void ShowNotification(string text) - { - if (notificationPrefab == null || canvas == null) - { - return; - } - - notificationInstance = Instantiate(notificationPrefab); - notificationInstance.transform.SetParent(canvas.transform, false); - notificationInstance.transform.localScale = Vector3.one; - - var notificationRect = notificationInstance.GetComponent(); - var canvasRect = canvas.GetComponent(); - var label = notificationInstance.GetComponent(); - - if (label != null) - { - label.text = text; - } - - if (notificationRect != null && canvasRect != null) - { - Camera worldCamera = canvas.worldCamera != null ? canvas.worldCamera : Camera.main; - Camera uiCamera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : worldCamera; - - if (worldCamera != null) - { - Vector2 screenPoint = worldCamera.WorldToScreenPoint(transform.position); - - if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, uiCamera, out Vector2 localPoint)) - { - notificationRect.anchoredPosition = localPoint; - } - } - } - - StartCoroutine(HideNotification()); - } - - protected IEnumerator HideNotification() - { - yield return new WaitForSeconds(1.5f); - - if (notificationInstance != null) - { - Destroy(notificationInstance); - } - } }