aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Actors
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Actors')
-rw-r--r--Assets/Scripts/Actors/Actor.cs30
-rw-r--r--Assets/Scripts/Actors/Player.cs13
2 files changed, 34 insertions, 9 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs
index 1c52214..bcee7a3 100644
--- a/Assets/Scripts/Actors/Actor.cs
+++ b/Assets/Scripts/Actors/Actor.cs
@@ -10,7 +10,6 @@ using UnityEngine;
namespace MontanaJohns.Actors
{
[RequireComponent(typeof(Rigidbody2D))]
- [RequireComponent(typeof(CapsuleCollider2D))]
public abstract class Actor : MonoBehaviour
{
[SerializeField] protected float gravityScale = 1.5f;
@@ -18,14 +17,15 @@ namespace MontanaJohns.Actors
[SerializeField] protected LayerMask groundLayer;
[SerializeField] protected Transform groundCheckPoint;
- protected CapsuleCollider2D _collider;
protected Rigidbody2D _rigidBody;
protected SpriteRenderer _renderer;
protected Animator _animator;
protected Transform _transform;
- protected Stats stats;
+ public Stats stats;
protected Active activeItem;
+ protected bool isGrappling;
+ protected Vector2? grapplePoint = null;
Collection<Item> items;
bool isFalling;
@@ -35,7 +35,6 @@ namespace MontanaJohns.Actors
protected virtual void Awake()
{
- _collider = GetComponent<CapsuleCollider2D>();
_rigidBody = GetComponent<Rigidbody2D>();
_transform = GetComponent<Transform>();
_renderer = GetComponent<SpriteRenderer>();
@@ -74,6 +73,11 @@ namespace MontanaJohns.Actors
else if (_rigidBody.velocity.x > 0.001)
_renderer.flipX = false;
}
+ public virtual void MoveY(float input)
+ {
+ var target = new Vector2(_rigidBody.velocity.x, input * stats.speedMultiplier * 10);
+ _rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f);
+ }
public virtual void Jump()
{
@@ -88,8 +92,18 @@ namespace MontanaJohns.Actors
public virtual void Use()
{
+ Vector2? grapplePoint;
if (activeItem != null)
- activeItem.Use();
+ {
+ grapplePoint = activeItem.Use();
+ if (grapplePoint != null)
+ isGrappling = true;
+ else
+ isGrappling = false;
+ }
+ else
+ grapplePoint = null;
+ this.grapplePoint = grapplePoint;
}
public virtual void AddItem(Item item)
@@ -103,6 +117,12 @@ namespace MontanaJohns.Actors
health -= damage;
}
+ public virtual void Grapple(float xInput, float yInput, Vector2 grapplePoint)
+ {
+ Move(xInput);
+ MoveY(yInput);
+ }
+
IEnumerator Falling()
{
_animator.SetBool("airborn", true);
diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs
index 97099eb..3192338 100644
--- a/Assets/Scripts/Actors/Player.cs
+++ b/Assets/Scripts/Actors/Player.cs
@@ -6,7 +6,6 @@ using UnityEngine.InputSystem;
namespace MontanaJohns.Actors
{
[RequireComponent(typeof(Rigidbody2D))]
- [RequireComponent(typeof(CapsuleCollider2D))]
public class Player : Actor, IFollowable
{
public Transform ActorTransform => _transform;
@@ -28,8 +27,6 @@ namespace MontanaJohns.Actors
jump.started += context => Jump();
use.started += context => Use();
- move.started += context => Debug.Log("Moving!");
- move.performed += context => Debug.Log("Stopping!");
}
protected override void Start()
@@ -37,12 +34,20 @@ namespace MontanaJohns.Actors
base.Start();
GameObject loadedItem = (GameObject)Instantiate(Resources.Load("ActiveItems/Whip"));
activeItem = loadedItem.GetComponent<Whip>();
+ stats = baseStats + activeItem.stats;
}
protected void Update()
{
((IFollowable)this).Follow();
- base.Move(move.ReadValue<Vector2>().x);
+ if(isGrappling)
+ {
+ base.Grapple(move.ReadValue<Vector2>().x, move.ReadValue<Vector2>().y, (Vector2)grapplePoint);
+ }
+ else
+ {
+ base.Move(move.ReadValue<Vector2>().x);
+ }
}
}
} \ No newline at end of file