TO SQUASH: Added shooting bars.

This commit is contained in:
2026-08-05 01:23:47 -04:00
parent 2c7e02887c
commit c91a405227
30 changed files with 7987 additions and 98 deletions
+17 -13
View File
@@ -1,29 +1,19 @@
using UnityEngine;
public class NukeBall : MonoBehaviour
public class NukeBall : BallBase
{
private Animator animator;
public AudioClip spawnSound;
public AudioClip bounceSound;
public AudioClip hitSound;
public AudioClip criticalSound;
public AudioClip explosionSound;
private AudioSource audioSource;
private Vector2 speed;
// Tracks escalating danger/critical phases for audio cues.
private int criticalState = 0;
private float criticalTime = 1.0f;
private float criticalTimer = 0.0f;
// Initial resting height the ball bounces back toward after a floor hit.
private float height;
private Collider2D selfCollider;
@@ -41,13 +31,17 @@ public class NukeBall : MonoBehaviour
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
// Cache frequently used components once.
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
selfCollider = GetComponent<Collider2D>();
// Start with a small random horizontal drift.
speed = new Vector2(Random.Range(-0.09f, 0.09f), 0.0f);
height = GetComponent<Transform>().position.y;
fallTargetY = height;
// Find the closest valid floor point under the current position.
UpdateFallTargetFromCurrentPosition();
audioSource.PlayOneShot(spawnSound);
@@ -68,12 +62,14 @@ public class NukeBall : MonoBehaviour
bounceTimer += Time.fixedDeltaTime;
float t = Mathf.Clamp01(bounceTimer / bounceDuration);
// Ease-out ascent: fast start, gentle finish near target height.
float easedT = 1.0f - Mathf.Pow(1.0f - t, 2.0f);
currentPosition.y = Mathf.Lerp(bounceStartY, height, easedT);
if (t >= 1.0f)
{
// Reached top of bounce arc; resume falling phase.
isBouncingToHeight = false;
bounceTimer = 0.0f;
currentPosition.y = height;
@@ -85,6 +81,7 @@ public class NukeBall : MonoBehaviour
bounceTimer += Time.fixedDeltaTime;
float t = Mathf.Clamp01(bounceTimer / bounceDuration);
// Ease-in descent: gentle start, faster approach to floor.
float easedT = t * t;
currentPosition.y = Mathf.Lerp(height, fallTargetY, easedT);
@@ -110,6 +107,7 @@ public class NukeBall : MonoBehaviour
audioSource.PlayOneShot(criticalSound);
}
// Restart timing window for the next critical beep.
criticalTimer = 0.0f;
}
}
@@ -120,6 +118,8 @@ public class NukeBall : MonoBehaviour
if (collision.gameObject.CompareTag("Wall"))
{
ContactPoint2D contact = collision.GetContact(0);
// Reflect horizontal movement from wall surfaces.
speed = Vector2.Reflect(speed, contact.normal);
speed.y = 0.0f;
@@ -130,6 +130,8 @@ public class NukeBall : MonoBehaviour
{
isBouncingToHeight = true;
bounceTimer = 0.0f;
// Use exact contact point as bounce origin so visual contact feels grounded.
bounceStartY = contact.point.y;
fallTargetY = bounceStartY;
@@ -142,8 +144,10 @@ public class NukeBall : MonoBehaviour
private void UpdateFallTargetFromCurrentPosition()
{
// Default to current y in case no valid floor is found.
fallTargetY = transform.position.y;
// Probe straight down and choose nearest upward-facing wall surface.
RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, Vector2.down, 100.0f);
float closestDistance = float.MaxValue;