diff --git a/Assets/Scenes/Reparation.unity b/Assets/Scenes/Reparation.unity index 22b87bf..ae7d3da 100644 --- a/Assets/Scenes/Reparation.unity +++ b/Assets/Scenes/Reparation.unity @@ -14294,7 +14294,7 @@ RectTransform: m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} m_AnchoredPosition: {x: -100, y: 300} - m_SizeDelta: {x: 200, y: 50} + m_SizeDelta: {x: 400, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &707323441 MonoBehaviour: @@ -14316,7 +14316,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Fallaste! + m_text: Felicidades! m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -24736,8 +24736,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3dd46298c8b3a9f4d89244b0c898a0bb, type: 3} m_Name: m_EditorClassIdentifier: - blackScreen: {fileID: 0} - fadeDuration: 1 scoreExplanationText: {fileID: 89375942} scoreExplanationTextOutOfTen: {fileID: 754738739} timePlayedTextExplanation: {fileID: 886493360} @@ -24750,6 +24748,7 @@ MonoBehaviour: timePerPipeText: {fileID: 2014754360} oxygenWarningsAmountText: {fileID: 474630863} distanceCoveredText: {fileID: 16681213} + reticle: {fileID: 1374808373} --- !u!4 &1130256303 stripped Transform: m_CorrespondingSourceObject: {fileID: -5819118886272102141, guid: e0f672a015f8fee418afd70dfd718f0d, type: 3} @@ -29833,6 +29832,17 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1372892350} m_CullTransparentMesh: 1 +--- !u!114 &1374808373 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 4459864850190357395, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3} + m_PrefabInstance: {fileID: 848670198} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1376932302 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Character/Health.cs b/Assets/Scripts/Character/Health.cs index b64ff3f..52f21b3 100644 --- a/Assets/Scripts/Character/Health.cs +++ b/Assets/Scripts/Character/Health.cs @@ -12,6 +12,7 @@ public class Health : MonoBehaviour /// The player's current health value. /// [Tooltip("The player's health.")] + [Range(0,100)] public float health = 100f; /// diff --git a/Assets/Scripts/Logic/WaterLogic.cs b/Assets/Scripts/Logic/WaterLogic.cs index 7b0f305..9460f2e 100644 --- a/Assets/Scripts/Logic/WaterLogic.cs +++ b/Assets/Scripts/Logic/WaterLogic.cs @@ -6,8 +6,9 @@ public class WaterLogic : MonoBehaviour { - [FormerlySerializedAs("max_oxygen")] public int maxOxygen = 45; - [FormerlySerializedAs("current_oxygen")] public int currentOxygen; + public int maxOxygen = 45; + [Range(0, 50)] + public int currentOxygen; public Rigidbody playerRigidbody; public float waterGravityScale = 0.5f; @@ -34,6 +35,7 @@ public class WaterLogic : MonoBehaviour private float _previousWaitTime; private bool _isUnderwater; private bool _isFadingIn; + public int oxygenAlertsCount; private bool _hasPlayedWarning1; private bool _hasPlayedWarning2; @@ -149,6 +151,7 @@ private IEnumerator OxygenDecrement() StartCoroutine(FadeTextAlpha(oxygenWarningText, 1f, 0f, 6f)); _audioSource.PlayOneShot(oxygenWarning3); _hasPlayedWarning3 = true; + oxygenAlertsCount++; StartCoroutine(FadeInBlackCanvas()); break; case <= 15 when !_hasPlayedWarning2: @@ -157,6 +160,7 @@ private IEnumerator OxygenDecrement() StartCoroutine(FadeTextAlpha(oxygenWarningText, 1f, 0f, 6f)); _audioSource.PlayOneShot(oxygenWarning2); _hasPlayedWarning2 = true; + oxygenAlertsCount++; break; case <= 30 when !_hasPlayedWarning1: oxygenWarningText.text = "¡Oxígeno agotándose! ¡Conseguí un poco de oxígeno!"; @@ -164,6 +168,7 @@ private IEnumerator OxygenDecrement() StartCoroutine(FadeTextAlpha(oxygenWarningText, 1f, 0f, 6f)); _audioSource.PlayOneShot(oxygenWarning1); _hasPlayedWarning1 = true; + oxygenAlertsCount++; break; } diff --git a/Assets/Scripts/UI/Endgame.cs b/Assets/Scripts/UI/Endgame.cs index f9f6434..96bdc20 100644 --- a/Assets/Scripts/UI/Endgame.cs +++ b/Assets/Scripts/UI/Endgame.cs @@ -1,11 +1,10 @@ -using System; using UnityEngine; using TMPro; +using UnityEngine.UI; public class Endgame : MonoBehaviour { - //theres a blakck screen that overlays all this on endgame please make all this z up or shit and also we need to to the same to the explanation texts of what are the values cuz i only puyyed values so far now i will put the explicative elements like 'your score' you just fade this at the beggining and show it at the end with the real values - + // Variables for UI elements public TextMeshProUGUI scoreExplanationText; public TextMeshProUGUI scoreExplanationTextOutOfTen; public TextMeshProUGUI timePlayedTextExplanation; @@ -19,93 +18,105 @@ public class Endgame : MonoBehaviour public TextMeshProUGUI timePerPipeText; // Time played divided by 7 public TextMeshProUGUI oxygenWarningsAmountText; // Number of times an oxygen warning was triggered public TextMeshProUGUI distanceCoveredText; // Distance covered as the sum of all 3 components (x, y, z) + public Image reticle; private Health _health; // Reference to player health private FixLogic _fixLogic; // Reference to the fixing logic - private Transform playerTransform; // Player's transform (captured automatically from prefab) + private WaterLogic _waterLogic; // Reference to the water logic + private Transform _playerTransform; // Player's transform (captured automatically from prefab) - private int score = 0; // Final score for winning - private float timePlayed = 0f; // Total time played - private bool gameEnded = false; // Check if the game has ended - private int oxygenWarnings = 0; // Oxygen warnings triggered + private int _score; // Final score for winning + private float _timePlayed; // Total time played + private bool _gameEnded; // Check if the game has ended + private int _oxygenAlertsCount; // Oxygen alerts triggered - private Vector3 startPosition; // Start position of the player + private Vector3 _startPosition; // Start position of the player private void Start() { // Get player transform from prefab - playerTransform = GameObject.FindWithTag("Player").transform; + _playerTransform = GameObject.FindWithTag("Player").transform; - if (playerTransform == null) + if (_playerTransform == null) { Debug.LogError("Player prefab not found!"); return; } + // Initialize references + _health = FindObjectOfType(); + _fixLogic = FindObjectOfType(); + _waterLogic = FindObjectOfType(); + // Capture player's starting position - startPosition = playerTransform.position; + _startPosition = _playerTransform.position; // Initialize the text elements to be transparent (not visible) SetTextVisibility(false); // Start time tracking - timePlayed = Time.time; - - scoreExplanationText.color = new Color(1, 1, 1, 0); - scoreExplanationTextOutOfTen.color = new Color(1, 1, 1, 0); - timePlayedTextExplanation.color = new Color(1, 1, 1, 0); - timePerPipeTextExplanation.color = new Color(1, 1, 1, 0); - oxygenWarningsAmountTextExplanation.color = new Color(1, 1, 1, 0); - distanceCoveredTextExplanation.color = new Color(1, 1, 1, 0); + _timePlayed = Time.time; + + // Initialize explanation texts to be invisible + SetExplanationTextVisibility(0); } private void Update() { - if (gameEnded) return; + if (_gameEnded) return; - // Continuously check the player's health and the number of pipes fixed - if (_health.health <= 0) - { - EndGame(false); // Loss - } - else if (_fixLogic.fixedCount >= 7) + var healthDepleted = _health.health <= 0; + var pipesFixed = _fixLogic.fixedCount >= 7; + var oxygenDepleted = _waterLogic.currentOxygen <= 1; + + if (healthDepleted || pipesFixed || oxygenDepleted) { - EndGame(true); // Victory + EndGame(pipesFixed); } } private void EndGame(bool isVictory) { - gameEnded = true; // Stop further updates + _gameEnded = true; // Stop further updates + reticle.enabled = false; // Hide the reticle // Calculate total time played - timePlayed = Time.time - timePlayed; // Time since the game started + _timePlayed = Time.time - _timePlayed; // Time since the game started + _oxygenAlertsCount = _waterLogic.oxygenAlertsCount; // Adjusted to use the correct instance // Calculate distance covered using player's current position - Vector3 endPosition = playerTransform.position; - float distanceCovered = Vector3.Distance(startPosition, endPosition); + Vector3 endPosition = _playerTransform.position; + float distanceCovered = Vector3.Distance(_startPosition, endPosition); // Calculate the score if the player wins if (isVictory) { - score = UnityEngine.Random.Range(7, 11); // Random score between 7 and 10 - endgameText.text = "Victory!"; + _score = Random.Range(7, 11); // Random score between 7 and 10 + endgameText.text = "Felicidades!"; // Victory message + endgameText.color = Color.green; // Change text color to green } else { - score = 0; // No score for losing - endgameText.text = "You Lost!"; + _score = 0; // No score for losing + endgameText.text = "Perdiste!"; // Loss message + endgameText.color = Color.red; // Change text color to red } // Update the UI elements - scoreText.text = $"Score: {score}"; - timePlayedText.text = $"Time Played: {timePlayed:F2} seconds"; - timePerPipeText.text = $"Time per Pipe: {timePlayed / 7:F2} seconds"; - oxygenWarningsAmountText.text = $"Oxygen Warnings: {oxygenWarnings}"; - distanceCoveredText.text = $"Distance Covered: {distanceCovered:F2} units"; + UpdateUI(); // Make the text visible SetTextVisibility(true); + SetExplanationTextVisibility(1f); + } + + private void UpdateUI() + { + scoreText.text = $"{_score}"; + timePlayedText.text = $"{_timePlayed:F2} s"; + timePerPipeText.text = $"{_timePlayed / 7:F2} s"; + oxygenWarningsAmountText.text = $"{_oxygenAlertsCount}"; + distanceCoveredText.text = $"{Vector3.Distance(_startPosition, _playerTransform.position):F2} m"; } private void SetTextVisibility(bool visible) @@ -119,9 +130,14 @@ private void SetTextVisibility(bool visible) distanceCoveredText.color = color; } - // Call this method whenever an oxygen warning is triggered - public void OnOxygenWarningTriggered() + private void SetExplanationTextVisibility(float alpha) { - oxygenWarnings++; + Color color = new Color(1, 1, 1, alpha); // Set alpha for explanation texts + scoreExplanationText.color = color; + scoreExplanationTextOutOfTen.color = color; + timePlayedTextExplanation.color = color; + timePerPipeTextExplanation.color = color; + oxygenWarningsAmountTextExplanation.color = color; + distanceCoveredTextExplanation.color = color; } }