diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index ac1d1f0..f4075f6 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -3,13 +3,9 @@ using UnityEngine.Events; public class Entity : MonoBehaviour { - public float maxHealth { get; private set; } - public float currentHealth { get; private set; } - public float attackDamage { get; private set; } - - public UnityEvent OnDeath; - public UnityEvent OnTakeDamage; - + private int maxHealth; + private int currentHealth; + private int attackDamage; [SerializeField] private EntityData data; @@ -20,30 +16,28 @@ public class Entity : MonoBehaviour attackDamage = data.attackDamage; } - public virtual void TakeDamage(float damage) + public virtual void TakeDamage(int playerAttackDamage) { - currentHealth -= damage; - OnTakeDamage?.Invoke(damage); + currentHealth -= playerAttackDamage; if (currentHealth <= 0) { currentHealth = 0; - Die(); + Destroy(gameObject); } } - - protected virtual void Die() - { - Destroy(gameObject); - OnDeath?.Invoke(); - } - public void Heal(float heal) + + void Update() { - if (heal < 0) return; - currentHealth += heal; - if(currentHealth > maxHealth) - { - currentHealth = maxHealth; - } + RunAI(); } + + protected void RunAI() { } + + + public int getAttackDamage() + { + return attackDamage; + } + } diff --git a/Assets/Scripts/EntityData.cs b/Assets/Scripts/EntityData.cs index ae220d8..5a56571 100644 --- a/Assets/Scripts/EntityData.cs +++ b/Assets/Scripts/EntityData.cs @@ -3,7 +3,7 @@ using UnityEngine; [CreateAssetMenu(fileName = "EntityData", menuName = "Scriptable Objects/EntityData")] public class EntityData : ScriptableObject { - public string entityName; - public float maxHealth; - public float attackDamage; + public string name; + public int maxHealth; + public int attackDamage; } diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs new file mode 100644 index 0000000..880c7eb --- /dev/null +++ b/Assets/Scripts/Player/Player.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.InputSystem; + +public class Player : MonoBehaviour +{ + private int currentHealth; + private int maxHealth; + + private int maxJumpCount = 2; + private int currentJumpCount = 2; + + [SerializeField] private float moveSpeed = 9f; + [SerializeField] private float jumpSpeed = 18.2f; + [SerializeField] private float jumpCutMultiplier = 0.3f; + + private Rigidbody2D _rigidbody; + + + private void Start() + { + _rigidbody = gameObject.GetComponent(); + } + + public void Jump() + { + if (currentJumpCount > 0) + { + currentJumpCount--; + _rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0); + _rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse); + } + + } + + public void Heal(int heal) + { + if (heal < 0) { return; } + + currentHealth += heal; + if (currentHealth > maxHealth) + { + currentHealth = maxHealth; + } + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Player/Player.cs.meta b/Assets/Scripts/Player/Player.cs.meta new file mode 100644 index 0000000..de4bf61 --- /dev/null +++ b/Assets/Scripts/Player/Player.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b68250b34a148164d9a00b31f0af63d8 \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 8bec599..a71e7df 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -6,6 +6,12 @@ using UnityEngine.InputSystem; public class PlayerController : MonoBehaviour { + + private Player player; + + private int currentHealth; + private int maxHealth; + private Rigidbody2D _rigidbody; private Camera _camera; @@ -34,6 +40,7 @@ public class PlayerController : MonoBehaviour private void Start() { + player = GetComponent(); _rigidbody = gameObject.GetComponent(); _camera = Camera.main; } @@ -70,31 +77,7 @@ public class PlayerController : MonoBehaviour private void OnJump(InputValue value) { - if (value.isPressed) - { - if (currentJumpCount > 0) - { - currentJumpCount--; - jumpStartTime = Time.time; - if (jumpCutRoutine != null) StopCoroutine(jumpCutRoutine); - _rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0); - _rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse); - } - } - else - { - float timeElapsed = Time.time - jumpStartTime; - - if (timeElapsed >= minJumpDuration) - { - CutJumpVelocity(); - } - else - { - float delay = minJumpDuration - timeElapsed; - jumpCutRoutine = StartCoroutine(DelayedJumpCut(delay)); - } - } + player.Jump(); } private void NormalAttack() @@ -216,4 +199,6 @@ public class PlayerController : MonoBehaviour } } + + } \ No newline at end of file