diff options
author | cross28 <icross028@gmail.com> | 2022-04-15 01:53:41 -0500 |
---|---|---|
committer | cross28 <icross028@gmail.com> | 2022-04-15 01:53:41 -0500 |
commit | 9e00737362f197f18db363b83b9ce4d9708bf4d9 (patch) | |
tree | f7ccbac8b46a67dbe5cb2447353542e8f66609df /Assets/Scripts/Actors | |
parent | 584b852c81c3504a823eee6eba83aa2eae53b023 (diff) | |
parent | ee708901a74b9d442e2e8397b699a568928a8dc7 (diff) |
chore: merge develop
Diffstat (limited to 'Assets/Scripts/Actors')
-rw-r--r-- | Assets/Scripts/Actors/Actor.cs | 28 | ||||
-rw-r--r-- | Assets/Scripts/Actors/Player.cs | 27 |
2 files changed, 39 insertions, 16 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs index bcee7a3..63854d9 100644 --- a/Assets/Scripts/Actors/Actor.cs +++ b/Assets/Scripts/Actors/Actor.cs @@ -14,7 +14,6 @@ namespace MontanaJohns.Actors { [SerializeField] protected float gravityScale = 1.5f; [SerializeField] protected Stats baseStats = Stats.DefaultBaseStats(); - [SerializeField] protected LayerMask groundLayer; [SerializeField] protected Transform groundCheckPoint; protected Rigidbody2D _rigidBody; @@ -22,16 +21,16 @@ namespace MontanaJohns.Actors protected Animator _animator; protected Transform _transform; - public Stats stats; + protected Stats stats; protected Active activeItem; protected bool isGrappling; protected Vector2? grapplePoint = null; - Collection<Item> items; - bool isFalling; - - public int health; + protected LayerMask groundLayers; + protected Collection<Item> items; protected int jumpCount; protected Vector2 acceleration; + + public int health; protected virtual void Awake() { @@ -39,6 +38,7 @@ namespace MontanaJohns.Actors _transform = GetComponent<Transform>(); _renderer = GetComponent<SpriteRenderer>(); _animator = GetComponent<Animator>(); + groundLayers = LayerMask.GetMask("Grapple", "Ground"); } protected virtual void Start() @@ -55,7 +55,7 @@ namespace MontanaJohns.Actors protected virtual void FixedUpdate() { - if (!_animator.GetBool("airborn") && !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayer)) + if (!_animator.GetBool("airborn") && !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) { _animator.SetTrigger("fall"); StartCoroutine(Falling()); @@ -66,7 +66,7 @@ namespace MontanaJohns.Actors { var target = new Vector2(input * stats.speedMultiplier * 10, _rigidBody.velocity.y); _rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f); - _animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 0.001); + _animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 1); if (_rigidBody.velocity.x < -0.001) _renderer.flipX = true; @@ -81,8 +81,13 @@ namespace MontanaJohns.Actors public virtual void Jump() { - if (jumpCount++ <= stats.maxJumps) + if(Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) + { + jumpCount = stats.maxJumps; + } + if (jumpCount > 0) { + jumpCount--; _rigidBody.AddForce(Vector2.up * stats.jumpForce); _animator.SetTrigger("jump"); _animator.SetBool("airborn", true); @@ -127,12 +132,11 @@ namespace MontanaJohns.Actors { _animator.SetBool("airborn", true); - while (_rigidBody.velocity.y > 0 || !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayer)) + while (!Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) { - yield return new WaitForFixedUpdate(); + yield return new WaitForEndOfFrame(); } - jumpCount = 0; _animator.SetBool("airborn", false); yield break; diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs index 012c09a..95ec2ca 100644 --- a/Assets/Scripts/Actors/Player.cs +++ b/Assets/Scripts/Actors/Player.cs @@ -12,10 +12,11 @@ namespace MontanaJohns.Actors public Camera MainCamera => _camera; public GameObject projectilePrefab; public Transform firePoint; + public Vector3 spawnPoint; - Camera _camera; - PlayerInput playerInput; - InputAction use, move, jump; + private Camera _camera; + private PlayerInput playerInput; + private InputAction use, move, jump; protected override void Awake() { @@ -37,7 +38,8 @@ namespace MontanaJohns.Actors base.Start(); GameObject loadedItem = (GameObject)Instantiate(Resources.Load("ActiveItems/Whip")); activeItem = loadedItem.GetComponent<Whip>(); - stats = baseStats + activeItem.stats; + ResetStats(); + spawnPoint = transform.position; } protected void Update() @@ -51,6 +53,23 @@ namespace MontanaJohns.Actors { base.Move(move.ReadValue<Vector2>().x); } + DeathCheck(); + } + + protected void DeathCheck() + { + if(health <= 0) + { + MainCamera.GetComponent<LevelController>().ResetLevel(); + ResetStats(); + health = stats.maxHealth; + transform.position = spawnPoint; + } + } + + protected void ResetStats() + { + stats = baseStats + activeItem.stats; } protected void Fire() |