From f7a361d451fb87434a1f2981496c098b1d4ab905 Mon Sep 17 00:00:00 2001 From: pyoneerC Date: Thu, 26 Sep 2024 19:15:37 -0300 Subject: [PATCH] feat: chelicerate movement --- Assets/Scenes/Reparation.unity | 26 ++--- Assets/Scripts/Creatures/Chelicerate.cs | 126 ------------------------ Assets/Scripts/UI/Endgame.cs | 15 ++- 3 files changed, 27 insertions(+), 140 deletions(-) delete mode 100644 Assets/Scripts/Creatures/Chelicerate.cs diff --git a/Assets/Scenes/Reparation.unity b/Assets/Scenes/Reparation.unity index c336675..659b0f2 100644 --- a/Assets/Scenes/Reparation.unity +++ b/Assets/Scenes/Reparation.unity @@ -25639,7 +25639,7 @@ PrefabInstance: addedObject: {fileID: 1153932945} - targetCorrespondingSourceObject: {fileID: -5609321221556402741, guid: d9ff58e3d94324345b590825be096953, type: 3} insertIndex: -1 - addedObject: {fileID: 1153932946} + addedObject: {fileID: 1153932948} m_SourcePrefab: {fileID: 9199261849990390558, guid: d9ff58e3d94324345b590825be096953, type: 3} --- !u!1 &1153932944 stripped GameObject: @@ -25667,7 +25667,12 @@ SphereCollider: serializedVersion: 3 m_Radius: 0.25 m_Center: {x: 0, y: 0, z: 0} ---- !u!114 &1153932946 +--- !u!4 &1153932947 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 5146681718063874739, guid: d9ff58e3d94324345b590825be096953, type: 3} + m_PrefabInstance: {fileID: 1153932943} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1153932948 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -25676,19 +25681,14 @@ MonoBehaviour: m_GameObject: {fileID: 1153932944} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6cd190f2ed0638945954a157b7b78d1a, type: 3} + m_Script: {fileID: 11500000, guid: 77df7a834c991ce4c966b3383d967636, type: 3} m_Name: m_EditorClassIdentifier: - swimSpeed: 3 - swimRadius: 100 - damage: 10 - changeDirectionInterval: 10 - rotationSpeed: 50 ---- !u!4 &1153932947 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 5146681718063874739, guid: d9ff58e3d94324345b590825be096953, type: 3} - m_PrefabInstance: {fileID: 1153932943} - m_PrefabAsset: {fileID: 0} + splineObject: {fileID: 557190188} + swimSpeed: 1 + rotationSpeed: 5 + loop: 1 + rotationOffset: {x: -90, y: 0, z: 0} --- !u!1001 &1155032072 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Creatures/Chelicerate.cs b/Assets/Scripts/Creatures/Chelicerate.cs deleted file mode 100644 index 94f1881..0000000 --- a/Assets/Scripts/Creatures/Chelicerate.cs +++ /dev/null @@ -1,126 +0,0 @@ -using UnityEngine; - -/// -/// Represents a Chelicerate that swims in a circular path and interacts with the player. -/// -public class Chelicerate : MonoBehaviour -{ - /// - /// The speed at which the Chelicerate swims. - /// - [Tooltip("The speed at which the Chelicerate swims.")] - public float swimSpeed = 2f; - - /// - /// The maximum distance from the center within which the Chelicerate swims. - /// - [Tooltip("The maximum swimming radius.")] - public float swimRadius = 5f; - - /// - /// The damage dealt to the player on overlap. - /// - [Tooltip("The damage dealt to the player.")] - public float damage = 10f; - - /// - /// The interval at which the Chelicerate changes its swimming direction. - /// - [Tooltip("The time interval for changing direction.")] - public float changeDirectionInterval = 2f; - - /// - /// The speed at which the Chelicerate rotates to face its movement direction. - /// - [Tooltip("The speed of rotation towards the movement direction.")] - public float rotationSpeed = 5f; - - private Vector2 _direction; - private float _timer; - - private void Start() - { - ChangeDirection(); - _timer = changeDirectionInterval; - } - - private void Update() - { - Move(); - CheckDirectionChange(); - KeepWithinBounds(); - RotateTowardsDirection(); - } - - /// - /// Moves the Chelicerate in its current direction. - /// - private void Move() - { - transform.Translate(_direction * (swimSpeed * Time.deltaTime)); - } - - /// - /// Checks if it's time to change direction and calls ChangeDirection if needed. - /// - private void CheckDirectionChange() - { - _timer -= Time.deltaTime; - if (_timer <= 0f) - { - ChangeDirection(); - _timer = changeDirectionInterval; - } - } - - /// - /// Keeps the Chelicerate within the defined swim radius. - /// - private void KeepWithinBounds() - { - if (Vector2.Distance(transform.position, Vector2.zero) > swimRadius) - { - _direction = -_direction; - } - } - - /// - /// Rotates the Chelicerate towards its movement direction. - /// - private void RotateTowardsDirection() - { - if (_direction == Vector2.zero) return; - - var angle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg; - var targetRotation = Quaternion.Euler(new Vector3(0, 0, angle)); - transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); - } - - /// - /// Changes the direction of the Chelicerate to a random angle. - /// - private void ChangeDirection() - { - // Set a random horizontal direction with a random angle - var angle = Random.Range(0f, 360f); - _direction = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)).normalized; // Include y-component for 2D movement - } - - /// - /// Handles collision with the player. - /// - /// The collider of the object this Chelicerate collided with. - private void OnTriggerEnter2D(Collider2D other) - { - if (other.CompareTag("Player")) - { - Debug.Log("Overlap with Player"); - // Here you can implement damage to the player if necessary - // PlayerHealth playerHealth = other.GetComponent(); - // if (playerHealth != null) - // { - // playerHealth.TakeDamage(damage); - // } - } - } -} diff --git a/Assets/Scripts/UI/Endgame.cs b/Assets/Scripts/UI/Endgame.cs index 44e3f28..480f0ab 100644 --- a/Assets/Scripts/UI/Endgame.cs +++ b/Assets/Scripts/UI/Endgame.cs @@ -106,6 +106,8 @@ private void EndGame(bool isVictory) UpdateUI(); + DisablePlayerInput(); + SetTextVisibility(true); SetExplanationTextVisibility(1f); @@ -125,6 +127,17 @@ private void EndGame(bool isVictory) healthCountExplanation.gameObject.SetActive(false); } + private void DisablePlayerInput() + { + var player = GameObject.FindWithTag("Player"); + + if (player == null) return; + + var playerMovement = player.GetComponent(); + playerMovement.enabled = false; + } + + private void UpdateUI() { scoreText.text = $"{_score}"; @@ -138,7 +151,7 @@ private void UpdateUI() restartButton.interactable = true; quitButton.interactable = true; - + restartButton.onClick.AddListener(() => { UnityEngine.SceneManagement.SceneManager.LoadScene(0); }); quitButton.onClick.AddListener(Application.Quit); }