TO SQUASH: A lot of things.

This commit is contained in:
2026-08-05 04:52:06 -04:00
parent 1c00bebb40
commit a9db378127
111 changed files with 63162 additions and 6833 deletions
+3 -3
View File
@@ -29,8 +29,8 @@ public class BallSpawner : MonoBehaviour
{
int currentLevel = PlayerPrefs.GetInt("CurrentLevel");
// ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
@@ -41,7 +41,7 @@ public class BallSpawner : MonoBehaviour
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab));
// ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab));
StartCoroutine(SpawnBalls());
}
+2
View File
@@ -14,6 +14,8 @@ public class BallBase : MonoBehaviour
protected Vector2 speed;
protected bool affectedByMagnet = true;
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.CompareTag("Bar"))
+3
View File
@@ -31,6 +31,9 @@ public class NukeBall : BallBase
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
// NukeBall is not affected by magnets, unlike other balls.
affectedByMagnet = false;
// Cache frequently used components once.
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
+40
View File
@@ -0,0 +1,40 @@
using UnityEngine;
public class Debris : MonoBehaviour
{
protected Vector2 speed;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
speed = new Vector2(Random.Range(-0.05f, 0.05f), Random.Range(-0.05f, 0.05f)).normalized * 0.05f;
}
// Update is called once per frame
void FixedUpdate()
{
transform.Translate(speed);
}
public void AnimationFinished()
{
Destroy(gameObject);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Wall"))
{
ContactPoint2D contact = collision.GetContact(0);
speed = Vector2.Reflect(speed, contact.normal);
}
else
{
Physics2D.IgnoreCollision(
gameObject.GetComponent<Collider2D>(),
collision.gameObject.GetComponent<Collider2D>(),
true
);
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: acd5329298ab7f303a1bcf5418aba1ba
+311 -26
View File
@@ -26,6 +26,10 @@ public class Player : MonoBehaviour
public AudioClip defeat;
public AudioClip denied;
public AudioClip victory;
public MusicManager musicManager;
public Fader fader;
@@ -34,6 +38,32 @@ public class Player : MonoBehaviour
public GameObject verticalBarrierPrefab;
public int lives = 8;
public int score = 0;
public int bonus = 3100;
public Animator gunAnimator;
public Animator muzzleAnimator;
public SpriteRenderer muzzleRenderer;
public GameObject debrisPrefab;
public int magnetCount = 0;
public int laserCount = 0;
public GameObject magnetLeft;
public GameObject magnetRight;
public GameObject magnetTop;
public GameObject magnetBottom;
private bool flipped = false;
private bool gameOver = false;
@@ -42,40 +72,96 @@ public class Player : MonoBehaviour
private bool canFire = true;
private float damageTimer = 0.0f;
private float damageCooldown = 0.5f;
private bool exploding = false;
private Bounds playerBounds;
private Bounds boardBounds;
private bool laserActive = false;
private bool magnetActive = false;
private float magnetDuration = 5.0f;
private float magnetTimer = 0.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
Cursor.visible = false;
if (!TryGetWorldBounds(gameObject, out playerBounds))
{
Debug.LogWarning("Could not get world bounds for player.");
}
if (!TryGetWorldBounds(gameBoard, out boardBounds))
{
Debug.LogWarning("Could not get world bounds for gameBoard.");
return;
}
// Initialize the magnets.
magnetLeft.GetComponent<SpriteRenderer>().enabled = false;
magnetRight.GetComponent<SpriteRenderer>().enabled = false;
magnetTop.GetComponent<SpriteRenderer>().enabled = false;
magnetBottom.GetComponent<SpriteRenderer>().enabled = false;
magnetLeft.transform.position = new Vector3(
boardBounds.min.x + magnetLeft.GetComponent<SpriteRenderer>().bounds.extents.x,
transform.position.y,
transform.position.z
);
magnetRight.transform.position = new Vector3(
boardBounds.max.x - magnetRight.GetComponent<SpriteRenderer>().bounds.extents.x,
transform.position.y,
transform.position.z
);
magnetTop.transform.position = new Vector3(
transform.position.x,
boardBounds.max.y - magnetTop.GetComponent<SpriteRenderer>().bounds.extents.y,
transform.position.z
);
magnetBottom.transform.position = new Vector3(
transform.position.x,
boardBounds.min.y + magnetBottom.GetComponent<SpriteRenderer>().bounds.extents.y,
transform.position.z
);
}
// Update is called once per frame
void Update()
{
if (gameBoard == null || Camera.main == null || Mouse.current == null)
if (damageTimer > 0.0f)
{
return;
damageTimer -= Time.fixedDeltaTime;
}
if (!TryGetWorldBounds(gameBoard, out Bounds boardBounds) || !TryGetWorldBounds(gameObject, out Bounds playerBounds))
if (!exploding)
{
Debug.LogWarning("Could not get world bounds for gameBoard or player.");
return;
Vector2 mouseScreen = Mouse.current.position.ReadValue();
Camera cam = Camera.main;
// Keep movement on the same depth plane as the current player position.
float screenZ = cam.WorldToScreenPoint(transform.position).z;
Vector3 mouseWorld = cam.ScreenToWorldPoint(new Vector3(mouseScreen.x, mouseScreen.y, screenZ));
Vector3 extents = playerBounds.extents;
float clampedX = Mathf.Clamp(mouseWorld.x, boardBounds.min.x + extents.x / 2.0f, boardBounds.max.x - extents.x / 2.0f);
float clampedY = Mathf.Clamp(mouseWorld.y, boardBounds.min.y + extents.y / 2.0f, boardBounds.max.y - extents.y / 2.0f);
transform.position = new Vector3(clampedX, clampedY, transform.position.z);
}
Vector2 mouseScreen = Mouse.current.position.ReadValue();
Camera cam = Camera.main;
// Keep movement on the same depth plane as the current player position.
float screenZ = cam.WorldToScreenPoint(transform.position).z;
Vector3 mouseWorld = cam.ScreenToWorldPoint(new Vector3(mouseScreen.x, mouseScreen.y, screenZ));
Vector3 extents = playerBounds.extents;
float clampedX = Mathf.Clamp(mouseWorld.x, boardBounds.min.x + extents.x / 2.0f, boardBounds.max.x - extents.x / 2.0f);
float clampedY = Mathf.Clamp(mouseWorld.y, boardBounds.min.y + extents.y / 2.0f, boardBounds.max.y - extents.y / 2.0f);
transform.position = new Vector3(clampedX, clampedY, transform.position.z);
if (Keyboard.current != null)
{
if (Keyboard.current.spaceKey.wasPressedThisFrame)
@@ -89,20 +175,46 @@ public class Player : MonoBehaviour
{
gameOver = true;
}
if (Keyboard.current.wKey.wasPressedThisFrame)
{
if (laserActive)
{
DisableLaser();
}
else
{
EnableLaser();
}
}
if (Keyboard.current.dKey.wasPressedThisFrame)
{
if (magnetActive)
{
DisableMagnet();
}
else
{
EnableMagnet();
}
}
}
if (Mouse.current.leftButton.wasPressedThisFrame && canFire)
if (Mouse.current.leftButton.wasPressedThisFrame && canFire && !exploding)
{
canFire = false;
audioSource.PlayOneShot(normalShoot);
if (flipped)
if (laserActive)
{
Instantiate(verticalBarrierPrefab, transform.position, Quaternion.identity);
FireLaser();
}
else if (magnetActive)
{
FireMagnet();
}
else
{
Instantiate(horizontalBarrierPrefab, transform.position, Quaternion.identity);
FireNormal();
}
}
@@ -111,6 +223,18 @@ public class Player : MonoBehaviour
StartCoroutine(EndGame());
gameOver = false; // Reset gameOver to prevent multiple coroutine starts
}
if (magnetTimer > 0.0f)
{
magnetTimer -= Time.deltaTime;
if (magnetTimer <= 0.0f)
{
magnetLeft.GetComponent<SpriteRenderer>().enabled = false;
magnetRight.GetComponent<SpriteRenderer>().enabled = false;
magnetTop.GetComponent<SpriteRenderer>().enabled = false;
magnetBottom.GetComponent<SpriteRenderer>().enabled = false;
}
}
}
private static bool TryGetWorldBounds(GameObject target, out Bounds bounds)
@@ -153,9 +277,170 @@ public class Player : MonoBehaviour
canFire = true;
}
public IEnumerator SetGameOver()
{
yield return new WaitForSeconds(3.0f);
gameOver = true;
}
private void EnableLaser()
{
if (laserCount > 0)
{
laserActive = true;
magnetActive = false;
audioSource.PlayOneShot(laserCharge);
gunAnimator.SetBool("laserActivated", true);
gunAnimator.SetBool("magnetActivated", false);
}
else
{
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(denied);
}
}
}
private void EnableMagnet()
{
if (magnetCount > 0)
{
laserActive = false;
magnetActive = true;
audioSource.PlayOneShot(magnetIdle);
gunAnimator.SetBool("laserActivated", false);
gunAnimator.SetBool("magnetActivated", true);
}
else
{
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(denied);
}
}
}
private void DisableLaser()
{
if (laserActive)
{
laserActive = false;
audioSource.PlayOneShot(laserDischarge);
gunAnimator.SetBool("laserActivated", false);
}
}
private void DisableMagnet()
{
if (magnetActive)
{
magnetActive = false;
gunAnimator.SetBool("magnetActivated", false);
}
}
private void FireNormal()
{
canFire = false;
audioSource.PlayOneShot(normalShoot);
muzzleAnimator.SetTrigger("firing");
if (flipped)
{
Instantiate(verticalBarrierPrefab, transform.position, Quaternion.identity);
}
else
{
Instantiate(horizontalBarrierPrefab, transform.position, Quaternion.identity);
}
}
private void FireLaser()
{
canFire = false;
audioSource.PlayOneShot(laserShoot);
muzzleAnimator.SetTrigger("firing");
laserCount--;
// if (flipped)
// {
// Instantiate(verticalBarrierPrefab, transform.position, Quaternion.identity);
// }
// else
// {
// Instantiate(horizontalBarrierPrefab, transform.position, Quaternion.identity);
// }
DisableLaser();
}
private void FireMagnet()
{
audioSource.PlayOneShot(magnetShoot);
muzzleAnimator.SetTrigger("firing");
magnetCount--;
magnetTimer = magnetDuration;
if (flipped)
{
magnetTop.GetComponent<SpriteRenderer>().enabled = true;
magnetBottom.GetComponent<SpriteRenderer>().enabled = true;
}
else
{
magnetLeft.GetComponent<SpriteRenderer>().enabled = true;
magnetRight.GetComponent<SpriteRenderer>().enabled = true;
}
DisableMagnet();
}
private void Explode()
{
if (exploding)
{
return;
}
exploding = true;
gunAnimator.SetTrigger("playerKilled");
muzzleRenderer.enabled = false;
audioSource.PlayOneShot(death);
for (int i = 0; i < 8; i++)
{
SpawnDebris();
}
}
private void SpawnDebris()
{
Vector2 randomOffset = Random.insideUnitCircle * playerBounds.extents.magnitude;
Instantiate(
debrisPrefab,
transform.position + new Vector3(randomOffset.x, randomOffset.y, 0),
Quaternion.identity
);
}
public void OnBarHit()
{
// TODO: Lose a life or end the game
if (damageTimer > 0.0f)
{
return;
}
lives--;
damageTimer = damageCooldown;
if (lives <= 0)
{
Explode();
StartCoroutine(SetGameOver());
}
canFire = true; // Allow firing again after bar hit
}
}
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
public class PlayerGun : MonoBehaviour
{
public Player player;
private Animator animator;
private SpriteRenderer spriteRenderer;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
}
public void AnimationFinished()
{
if (player.lives > 0)
{
animator.SetTrigger("revived");
}
else
{
spriteRenderer.enabled = false;
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d8f50aeaa35e8b0e7bd0bb61282f92bd