aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Actors
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2022-04-14 21:14:44 -0500
committerNeil Kollack <nkollack@gmail.com>2022-04-14 21:14:44 -0500
commit80c478b00f090a64ccd63d3252ac02ffa1f7f5a2 (patch)
treeec0aefd7727a8ae29be0ebac1f2e005283fe1782 /Assets/Scripts/Actors
parent15a62795a2f2d9e7311bea4b59430c589125ec79 (diff)
feat: level complete
Diffstat (limited to 'Assets/Scripts/Actors')
-rw-r--r--Assets/Scripts/Actors/Actor.cs10
-rw-r--r--Assets/Scripts/Actors/Player.cs26
2 files changed, 27 insertions, 9 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs
index bcee7a3..2e98974 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;
@@ -26,8 +25,8 @@ namespace MontanaJohns.Actors
protected Active activeItem;
protected bool isGrappling;
protected Vector2? grapplePoint = null;
+ protected LayerMask groundLayers;
Collection<Item> items;
- bool isFalling;
public int health;
protected int jumpCount;
@@ -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;
@@ -127,7 +127,7 @@ namespace MontanaJohns.Actors
{
_animator.SetBool("airborn", true);
- while (_rigidBody.velocity.y > 0 || !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayer))
+ while (_rigidBody.velocity.y > 0 || !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers))
{
yield return new WaitForFixedUpdate();
}
diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs
index 3192338..3537aa7 100644
--- a/Assets/Scripts/Actors/Player.cs
+++ b/Assets/Scripts/Actors/Player.cs
@@ -10,10 +10,11 @@ namespace MontanaJohns.Actors
{
public Transform ActorTransform => _transform;
public Camera MainCamera => _camera;
+ 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()
{
@@ -34,7 +35,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()
@@ -48,6 +50,22 @@ namespace MontanaJohns.Actors
{
base.Move(move.ReadValue<Vector2>().x);
}
+ DeathCheck();
+ }
+
+ protected void DeathCheck()
+ {
+ if(health <= 0)
+ {
+ ResetStats();
+ health = stats.maxHealth;
+ transform.position = spawnPoint;
+ }
+ }
+
+ protected void ResetStats()
+ {
+ stats = baseStats + activeItem.stats;
}
}
} \ No newline at end of file