TO SQUASH: Lots of UI.
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class LevelEnder : MonoBehaviour
|
||||
{
|
||||
public WorldFiller worldFiller;
|
||||
|
||||
public BallSpawner ballSpawner;
|
||||
|
||||
public MultiplierSpawner multiplierSpawner;
|
||||
|
||||
public SharkSpawner sharkSpawner;
|
||||
|
||||
public CakeSpawner cakeSpawner;
|
||||
|
||||
public MusicManager musicManager;
|
||||
|
||||
public Player player;
|
||||
|
||||
public SpriteRenderer levelEndTally;
|
||||
|
||||
public SpriteRenderer levelEndTallyBackground;
|
||||
|
||||
public Animator levelEndTallyAnimator;
|
||||
|
||||
public AudioClip victory;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private bool levelEnded = false;
|
||||
|
||||
private bool accelerate = false;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Check for victory condition.
|
||||
if (
|
||||
player &&
|
||||
player.percentCovered >= 80 &&
|
||||
!levelEnded
|
||||
)
|
||||
{
|
||||
musicManager.PauseMusic();
|
||||
audioSource.PlayOneShot(victory);
|
||||
levelEnded = true;
|
||||
StartCoroutine(EndLevelAfterDelay());
|
||||
}
|
||||
|
||||
if (
|
||||
levelEnded &&
|
||||
(
|
||||
Mouse.current.leftButton.wasPressedThisFrame ||
|
||||
Keyboard.current.anyKey.wasPressedThisFrame
|
||||
)
|
||||
)
|
||||
{
|
||||
accelerate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void EndLevel()
|
||||
{
|
||||
// Stop all spawners.
|
||||
ballSpawner.StopSpawning();
|
||||
multiplierSpawner.StopSpawning();
|
||||
sharkSpawner.StopSpawning();
|
||||
cakeSpawner.StopSpawning();
|
||||
|
||||
// Show the level end tally.
|
||||
musicManager.PlayVictoryMusic();
|
||||
levelEndTally.enabled = true;
|
||||
levelEndTallyBackground.enabled = true;
|
||||
levelEndTallyAnimator.ResetTrigger("replay");
|
||||
levelEndTallyAnimator.SetTrigger("replay");
|
||||
|
||||
// Destroy all objects other than the player.
|
||||
ClearBoard();
|
||||
}
|
||||
|
||||
private void ClearBoard()
|
||||
{
|
||||
// Clear the game board by destroying all objects except the player.
|
||||
var yummies = GameObject.FindGameObjectsWithTag("Yummy");
|
||||
var multipliers = GameObject.FindGameObjectsWithTag("Multiplier");
|
||||
var shark = GameObject.FindGameObjectWithTag("Shark");
|
||||
|
||||
foreach (var yummy in yummies)
|
||||
{
|
||||
Destroy(yummy);
|
||||
}
|
||||
|
||||
foreach (var multiplier in multipliers)
|
||||
{
|
||||
Destroy(multiplier);
|
||||
}
|
||||
|
||||
if (shark != null)
|
||||
{
|
||||
Destroy(shark);
|
||||
}
|
||||
|
||||
worldFiller.ClearSpawnedWalls();
|
||||
}
|
||||
|
||||
private IEnumerator EndLevelAfterDelay()
|
||||
{
|
||||
yield return new WaitForSeconds(victory.length);
|
||||
EndLevel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c40f0a758267a8277aa5f979dc1c0cda
|
||||
@@ -10,12 +10,16 @@ public class MusicManager : MonoBehaviour
|
||||
|
||||
public AudioClip outro;
|
||||
|
||||
public AudioClip victory;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private Queue<AudioClip> clipsQueue;
|
||||
|
||||
private bool isPaused = false;
|
||||
|
||||
private bool needsReset = false;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
@@ -51,15 +55,29 @@ public class MusicManager : MonoBehaviour
|
||||
clipsQueue.Enqueue(outro);
|
||||
}
|
||||
|
||||
public void pauseMusic()
|
||||
public void PauseMusic()
|
||||
{
|
||||
audioSource.Pause();
|
||||
isPaused = true;
|
||||
}
|
||||
|
||||
public void resumeMusic()
|
||||
public void ResumeMusic()
|
||||
{
|
||||
if (needsReset)
|
||||
{
|
||||
clipsQueue.Clear();
|
||||
ResetQueue();
|
||||
needsReset = false;
|
||||
}
|
||||
|
||||
audioSource.UnPause();
|
||||
isPaused = false;
|
||||
}
|
||||
|
||||
public void PlayVictoryMusic()
|
||||
{
|
||||
audioSource.Stop();
|
||||
audioSource.PlayOneShot(victory);
|
||||
needsReset = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,12 @@ public class Pause : MonoBehaviour
|
||||
if (isPaused)
|
||||
{
|
||||
audioSource.PlayOneShot(pauseSound);
|
||||
musicManager.pauseMusic();
|
||||
musicManager.PauseMusic();
|
||||
Time.timeScale = 0.0f; // Pause the game
|
||||
}
|
||||
else
|
||||
{
|
||||
musicManager.resumeMusic();
|
||||
musicManager.ResumeMusic();
|
||||
Time.timeScale = 1.0f; // Resume the game
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ public class Player : MonoBehaviour
|
||||
|
||||
public AudioClip denied;
|
||||
|
||||
public AudioClip victory;
|
||||
|
||||
public MusicManager musicManager;
|
||||
|
||||
public Fader fader;
|
||||
@@ -42,6 +40,8 @@ public class Player : MonoBehaviour
|
||||
|
||||
public GameObject verticalLaserPrefab;
|
||||
|
||||
public int level = 1;
|
||||
|
||||
public int lives = 8;
|
||||
|
||||
public int score = 0;
|
||||
@@ -104,6 +104,10 @@ public class Player : MonoBehaviour
|
||||
|
||||
private bool killedByShark = false;
|
||||
|
||||
private float bonusTimer = bonusDecrementInterval;
|
||||
|
||||
private static float bonusDecrementInterval = 0.25f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
@@ -183,13 +187,31 @@ public class Player : MonoBehaviour
|
||||
transform.position = new Vector3(clampedX, clampedY, transform.position.z);
|
||||
}
|
||||
|
||||
// Handle bonus countdown and decrement.
|
||||
if (bonus > 0 && percentCovered < 80)
|
||||
{
|
||||
bonusTimer -= Time.deltaTime;
|
||||
|
||||
if (bonusTimer <= 0.0f)
|
||||
{
|
||||
bonus -= 10;
|
||||
|
||||
if (bonus < 0)
|
||||
{
|
||||
bonus = 0;
|
||||
}
|
||||
|
||||
bonusTimer = bonusDecrementInterval;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle keyboard input for flipping, game over, and toggling laser/magnet modes.
|
||||
if (Keyboard.current != null)
|
||||
// Disable keyboard input if the player has covered 80% or more of the area.
|
||||
if (Keyboard.current != null && percentCovered < 80)
|
||||
{
|
||||
if (Keyboard.current.spaceKey.wasPressedThisFrame)
|
||||
{
|
||||
flipped = !flipped;
|
||||
// transform.eulerAngles = new Vector3(0, 0, flipped ? 90 : 0);
|
||||
audioSource.PlayOneShot(flip);
|
||||
}
|
||||
|
||||
@@ -241,6 +263,13 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Player has covered enough area to win the level.
|
||||
if (percentCovered >= 80)
|
||||
{
|
||||
canFire = false;
|
||||
}
|
||||
|
||||
// Check for game over or revival conditions.
|
||||
if (gameOver)
|
||||
{
|
||||
@@ -322,7 +351,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private IEnumerator EndGame()
|
||||
{
|
||||
musicManager.pauseMusic();
|
||||
musicManager.PauseMusic();
|
||||
audioSource.PlayOneShot(defeat);
|
||||
yield return new WaitForSeconds(1.3f);
|
||||
fader.ResetFader();
|
||||
@@ -523,6 +552,21 @@ public class Player : MonoBehaviour
|
||||
public void OnWallSpawned(int areaPercentage)
|
||||
{
|
||||
canFire = true;
|
||||
// TODO: Award points based on the area of the spawned wall.
|
||||
percentCovered += areaPercentage;
|
||||
score += areaPercentage * 10;
|
||||
}
|
||||
|
||||
public void OnLevelEnd()
|
||||
{
|
||||
// Reset the player state for the next level.
|
||||
canFire = true;
|
||||
exploding = false;
|
||||
laserActive = false;
|
||||
magnetActive = false;
|
||||
bonus = 3100;
|
||||
level++;
|
||||
multiplier = 1.0f;
|
||||
flipped = false;
|
||||
percentCovered = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class BallSpawner : MonoBehaviour
|
||||
public class BallSpawner : Spawner
|
||||
{
|
||||
public GameObject basicBallPrefab;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MultiplierSpawner : MonoBehaviour
|
||||
public class MultiplierSpawner : Spawner
|
||||
{
|
||||
public GameObject multiplierPrefab;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MultiplierSpawner : MonoBehaviour
|
||||
{
|
||||
spawnTimer += Time.fixedDeltaTime;
|
||||
|
||||
if (spawnTimer >= 1f && isActive)
|
||||
if (spawnTimer >= 1f && isActive && isSpawning)
|
||||
{
|
||||
spawnTimer = 0f;
|
||||
if (Random.value < spawnProbability)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SharkSpawner : MonoBehaviour
|
||||
public class SharkSpawner : Spawner
|
||||
{
|
||||
public GameObject sharkPrefab;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SharkSpawner : MonoBehaviour
|
||||
|
||||
private bool isActive = true;
|
||||
|
||||
private static float spawnProbability = 0.1f;
|
||||
private static float spawnProbability = 0.05f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
@@ -28,7 +28,7 @@ public class SharkSpawner : MonoBehaviour
|
||||
{
|
||||
spawnTimer += Time.fixedDeltaTime;
|
||||
|
||||
if (spawnTimer >= 1f && isActive)
|
||||
if (spawnTimer >= 1f && isActive && isSpawning)
|
||||
{
|
||||
spawnTimer = 0f;
|
||||
if (Random.value < spawnProbability)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class Spawner : MonoBehaviour
|
||||
{
|
||||
protected bool isSpawning = true;
|
||||
|
||||
public void StopSpawning()
|
||||
{
|
||||
isSpawning = false;
|
||||
}
|
||||
|
||||
public void StartSpawning()
|
||||
{
|
||||
isSpawning = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4522281a93a1ffc088f8bb7abaf7f07
|
||||
@@ -0,0 +1,77 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
public Player player;
|
||||
|
||||
public Text scoreText;
|
||||
|
||||
public Text bonusText;
|
||||
|
||||
public Text levelText;
|
||||
|
||||
public Text livesText;
|
||||
|
||||
public Text percentCoveredText;
|
||||
|
||||
public Text lasersText;
|
||||
|
||||
public Text magnetsText;
|
||||
|
||||
public Text multiplierText;
|
||||
|
||||
public AudioClip lastLifeWarning;
|
||||
|
||||
public SpriteRenderer lastLifeLabel;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private float warningTimer = 0f;
|
||||
|
||||
private int Clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
value = min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
value = max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
scoreText.text = $"{Clamp(player.score, 0, 9999999)}";
|
||||
bonusText.text = $"{player.bonus}";
|
||||
levelText.text = $"{Clamp(player.level, 1, 99)}";
|
||||
percentCoveredText.text = $"{Clamp(player.percentCovered, 0, 100)}";
|
||||
lasersText.text = $"{Clamp(player.laserCount, 0, 99)}";
|
||||
magnetsText.text = $"{Clamp(player.magnetCount, 0, 99)}";
|
||||
|
||||
if (player.lives == 1)
|
||||
{
|
||||
lastLifeLabel.enabled = true;
|
||||
warningTimer += Time.deltaTime;
|
||||
|
||||
if (warningTimer >= 1.0f)
|
||||
{
|
||||
audioSource.PlayOneShot(lastLifeWarning);
|
||||
warningTimer = 0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastLifeLabel.enabled = false;
|
||||
livesText.text = $"{Clamp(player.lives, 0, 99)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e903431f12d766558b9534d142bd204
|
||||
@@ -24,6 +24,8 @@ public class WorldFiller : MonoBehaviour
|
||||
|
||||
private int wallCount = 0;
|
||||
|
||||
private Queue<GameObject> spawnedWalls = new Queue<GameObject>();
|
||||
|
||||
private List<Rect> freeAreas = new List<Rect>();
|
||||
|
||||
private float boardArea;
|
||||
@@ -44,6 +46,21 @@ public class WorldFiller : MonoBehaviour
|
||||
wallCount = 0;
|
||||
}
|
||||
|
||||
public void ClearSpawnedWalls()
|
||||
{
|
||||
while (spawnedWalls.Count > 0)
|
||||
{
|
||||
GameObject wall = spawnedWalls.Dequeue();
|
||||
|
||||
if (wall != null)
|
||||
{
|
||||
Destroy(wall);
|
||||
}
|
||||
}
|
||||
|
||||
spawnedWalls.Clear();
|
||||
}
|
||||
|
||||
public void SetWallPosition(Vector2 position)
|
||||
{
|
||||
if (wallCount >= wallPositions.Length)
|
||||
@@ -63,8 +80,6 @@ public class WorldFiller : MonoBehaviour
|
||||
// If both wall positions are set, spawn a wall.
|
||||
if (wallPositions[0] != null && wallPositions[1] != null)
|
||||
{
|
||||
Debug.Log($"Spawning wall with wall line: ({wallPositions[0]}, {wallPositions[1]})");
|
||||
|
||||
Vector2 wallPointA = wallPositions[0].Value;
|
||||
Vector2 wallPointB = wallPositions[1].Value;
|
||||
|
||||
@@ -176,6 +191,7 @@ public class WorldFiller : MonoBehaviour
|
||||
Rect paddedWallRect = ExpandRectInsideBounds(clampedWallRect, wallPaddingWorldUnits, boardRect);
|
||||
|
||||
ApplyWallTransform(wall.transform, wallRenderer, paddedWallRect);
|
||||
spawnedWalls.Enqueue(wall);
|
||||
var wallBounds = wallRenderer.bounds;
|
||||
|
||||
UpdateFreeAreas(paddedWallRect);
|
||||
@@ -248,7 +264,7 @@ public class WorldFiller : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeFreeAreas()
|
||||
public void InitializeFreeAreas()
|
||||
{
|
||||
gameBoardBounds = gameBoardSpriteRenderer.bounds;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CakeSpawner : MonoBehaviour
|
||||
public class CakeSpawner : Spawner
|
||||
{
|
||||
public GameObject cakePrefab;
|
||||
|
||||
@@ -31,7 +31,12 @@ public class CakeSpawner : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (!spawned)
|
||||
if (!isSpawning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!spawned )
|
||||
{
|
||||
spawnTimer += Time.fixedDeltaTime;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user