aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Items
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2022-04-13 18:10:31 -0500
committerNeil Kollack <nkollack@gmail.com>2022-04-13 18:10:31 -0500
commit15a62795a2f2d9e7311bea4b59430c589125ec79 (patch)
treeeee8f899364f6ca30d02feac61a384d36cf0742e /Assets/Scripts/Items
parent9a902e09f35760e5ce7af6070e1f673476ded06e (diff)
fix: player swing + whip damage/grapple
Diffstat (limited to 'Assets/Scripts/Items')
-rw-r--r--Assets/Scripts/Items/Active.cs2
-rw-r--r--Assets/Scripts/Items/Whip.cs53
2 files changed, 48 insertions, 7 deletions
diff --git a/Assets/Scripts/Items/Active.cs b/Assets/Scripts/Items/Active.cs
index 5cec317..055e7d7 100644
--- a/Assets/Scripts/Items/Active.cs
+++ b/Assets/Scripts/Items/Active.cs
@@ -4,6 +4,6 @@ namespace MontanaJohns.Items
{
public abstract class Active : Item
{
- public abstract void Use();
+ public abstract Vector2? Use();
}
} \ No newline at end of file
diff --git a/Assets/Scripts/Items/Whip.cs b/Assets/Scripts/Items/Whip.cs
index 5f086eb..134ea53 100644
--- a/Assets/Scripts/Items/Whip.cs
+++ b/Assets/Scripts/Items/Whip.cs
@@ -1,3 +1,6 @@
+using MontanaJohns.Actors;
+using MontanaJohns.Core;
+using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -6,25 +9,63 @@ namespace MontanaJohns.Items
public class Whip : Active
{
[SerializeField] protected GameObject hook;
- [SerializeField] protected float maxRopeLength = 5f;
-
+ [SerializeField] protected GameObject hookNoSwing;
+ [SerializeField] protected float maxRopeLength = 20f;
+ protected GameObject player;
protected GameObject currentHook;
+ protected LayerMask ropeLayers;
protected bool ropeExists = false;
- public override void Use()
+ private void Awake()
+ {
+ stats.damage = 1;
+ }
+
+ private void Start()
+ {
+ player = GameObject.FindGameObjectWithTag("Player");
+ ropeLayers = LayerMask.GetMask("Grapple", "Enemy");
+ }
+
+ public override Vector2? Use()
{
if (!ropeExists)
{
Vector2 clickLocation = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
-
- currentHook = Instantiate(hook, clickLocation, Quaternion.identity);
- ropeExists = true;
+ Vector2 playerPos = player.transform.position;
+ Vector2 direction = clickLocation - playerPos;
+ RaycastHit2D hit = Physics2D.Raycast(playerPos, direction, maxRopeLength, ropeLayers);
+ if(hit.collider != null)
+ {
+ GameObject collisionGameObject = hit.collider.gameObject;
+ ropeExists = true;
+ if (LayerMask.LayerToName(collisionGameObject.layer) == "Grapple")
+ {
+ currentHook = Instantiate(hook, clickLocation, Quaternion.identity);
+ return clickLocation;
+ }
+ else
+ {
+ StartCoroutine(WhipSmack(collisionGameObject, clickLocation));
+ }
+ }
+ return null;
}
else
{
Destroy(currentHook);
ropeExists = false;
+ return null;
}
}
+
+ private IEnumerator WhipSmack(GameObject collisionGameObject, Vector2 clickLocation)
+ {
+ currentHook = Instantiate(hookNoSwing, clickLocation, Quaternion.identity);
+ collisionGameObject.GetComponent<Actor>().TakeDamage(player.GetComponent<Stats>().damage);
+ yield return new WaitForSeconds(0.1f);
+ Destroy(currentHook);
+ ropeExists = false;
+ }
}
} \ No newline at end of file