Add win screen

This commit is contained in:
RochesterX
2025-03-08 13:33:19 -05:00
parent 63912cd2fd
commit 058cf261c8
18 changed files with 2055 additions and 127 deletions

View File

@@ -3,7 +3,7 @@ using UnityEngine;
[RequireComponent(typeof(Animator))]
public class AnimationPlayer : MonoBehaviour
{
public enum AnimationState { Idle, Run, Jump };
public enum AnimationState { Idle, Run, Jump, Walk };
public AnimationState state;
public bool backwards;

View File

@@ -85,10 +85,13 @@ public class GameManager : MonoBehaviour
if (gameMode == GameMode.freeForAll)
{
player.lives--;
if (player.lives <= 0)
if (player.lives <= 0 && !gameOver)
{
GameOver(player.gameObject);
Destroy(player.gameObject);
player.gameObject.SetActive(false);
if (AlivePlayers().Count <= 1)
{
GameOver();
}
}
else
{
@@ -116,20 +119,17 @@ public class GameManager : MonoBehaviour
}
}
private void GameOver(GameObject player)
private void GameOver()
{
Destroy(player);
player.SetActive(false);
if (AlivePlayers().Count <= 1)
{
gameOver = true;
EndGameEvent?.Invoke();
print(AlivePlayers()[0].name + " is the winner");
FindFirstObjectByType<PlayerCameraMovement>().WinScene(AlivePlayers()[0]);
}
gameOver = true;
EndGameEvent?.Invoke();
print(AlivePlayers()[0].name + " is the winner");
FindFirstObjectByType<PlayerCameraMovement>().WinScene(AlivePlayers()[0]);
WinScreen.Instance.ShowWinScreen(players.IndexOf(AlivePlayers()[0]) + 1);
FindFirstObjectByType<LifeDisplayManager>().HideLifeDisplay();
}
private List<GameObject> AlivePlayers()
public List<GameObject> AlivePlayers()
{
List<GameObject> alivePlayers = new();

View File

@@ -23,6 +23,8 @@ public class HealthBarManager : MonoBehaviour
foreach (var kvp in playerHealthBars)
{
GameObject player = kvp.Key;
if (player == null) continue;
GameObject healthBar = kvp.Value;
//healthBar.GetComponent<TerribleHealthBarScript>().fullHealthColor = GameManager.playerColors[GameManager.players.IndexOf(player)]; // Color health bars
healthBar.transform.SetPositionAndRotation(new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z), Quaternion.identity);

View File

@@ -38,4 +38,9 @@ public class LifeDisplayManager : MonoBehaviour
}
}
}
public void HideLifeDisplay()
{
players.SetActive(false);
}
}

View File

@@ -29,7 +29,7 @@ public class PlayerCameraMovement : MonoBehaviour
if (playerThatWon != null)
{
target = playerThatWon.transform.position;
transform.position = Vector3.Lerp(transform.position, new Vector3(target.x, target.y, target.z - 10), speed * 2 * Time.deltaTime);
transform.position = Vector3.Lerp(transform.position, new Vector3(target.x, target.y, target.z - 10), speed * 12 * Time.deltaTime);
}
return;

View File

@@ -1,5 +1,6 @@
using System.Collections;
using TMPro;
using Unity.IO.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -70,7 +71,8 @@ public class PlayerMovement : MonoBehaviour
private void Update()
{
if (damageable.dying || (GameManager.Instance != null && GameManager.Instance.gameOver)) return;
if (GameManager.Instance.gameOver) maxSpeed = 0.1f;
if (damageable.dying/* || (GameManager.Instance != null && GameManager.Instance.gameOver)*/) return;
Jump();
@@ -97,8 +99,8 @@ public class PlayerMovement : MonoBehaviour
animationPlayer.SetState(AnimationPlayer.AnimationState.Jump);
else
{
if (Mathf.Abs(body.linearVelocityX) >= 0.1f)
animationPlayer.SetState(AnimationPlayer.AnimationState.Run);
if (Mathf.Abs(body.linearVelocityX) >= 0.5f)
animationPlayer.SetState(GameManager.Instance.gameOver ? AnimationPlayer.AnimationState.Walk : AnimationPlayer.AnimationState.Run);
else
animationPlayer.SetState(AnimationPlayer.AnimationState.Idle);
}