aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Actors
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2022-04-15 13:48:43 -0500
committerNeil Kollack <nkollack@gmail.com>2022-04-15 13:48:43 -0500
commitb2ea5e80bc770fc65d0ed297fb400d694765c497 (patch)
tree1a911a02e4f22c7e1716d6db1e203c3154d7095e /Assets/Scripts/Actors
parentce047b021d4d7d66ec57973d8e3b27a0f223c35e (diff)
fix: various issues with player and Enemy
Diffstat (limited to 'Assets/Scripts/Actors')
-rw-r--r--Assets/Scripts/Actors/Actor.cs20
-rw-r--r--Assets/Scripts/Actors/Enemy.cs9
-rw-r--r--Assets/Scripts/Actors/Player.cs5
3 files changed, 24 insertions, 10 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs
index f23f3c6..9a4b338 100644
--- a/Assets/Scripts/Actors/Actor.cs
+++ b/Assets/Scripts/Actors/Actor.cs
@@ -21,7 +21,6 @@ namespace MontanaJohns.Actors
protected Animator _animator;
protected Transform _transform;
- protected Stats stats;
protected Active activeItem;
protected bool isGrappling;
protected Vector2? grapplePoint = null;
@@ -30,6 +29,7 @@ namespace MontanaJohns.Actors
protected int jumpCount;
protected Vector2 acceleration;
+ public Stats stats;
public int health;
protected virtual void Awake()
@@ -68,7 +68,7 @@ namespace MontanaJohns.Actors
_rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f);
_animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 1);
- if (_rigidBody.velocity.x < -0.001) {
+ if (_rigidBody.velocity.x < -0.1) {
_renderer.flipX = true;
for (int i = 0; i < transform.childCount; i++) {
var rot = transform.GetChild(i).rotation;
@@ -76,7 +76,7 @@ namespace MontanaJohns.Actors
transform.GetChild(i).rotation = rot;
}
}
- else if (_rigidBody.velocity.x > 0.001) {
+ else if (_rigidBody.velocity.x > 0.1) {
_renderer.flipX = false;
for (int i = 0; i < transform.childCount; i++) {
var rot = transform.GetChild(i).rotation;
@@ -129,15 +129,23 @@ namespace MontanaJohns.Actors
stats = baseStats + items.Select(i => i.stats).Sum();
}
+ public virtual void Grapple(float xInput, float yInput, Vector2 grapplePoint)
+ {
+ Move(xInput);
+ MoveY(yInput);
+ }
+
public virtual void TakeDamage(int damage)
{
health -= damage;
+ StartCoroutine(DamageAnimation());
}
- public virtual void Grapple(float xInput, float yInput, Vector2 grapplePoint)
+ IEnumerator DamageAnimation()
{
- Move(xInput);
- MoveY(yInput);
+ _renderer.color = Color.red;
+ yield return new WaitForSeconds(0.5f);
+ _renderer.color = Color.white;
}
IEnumerator Falling()
diff --git a/Assets/Scripts/Actors/Enemy.cs b/Assets/Scripts/Actors/Enemy.cs
index 9160e44..5abf7ce 100644
--- a/Assets/Scripts/Actors/Enemy.cs
+++ b/Assets/Scripts/Actors/Enemy.cs
@@ -24,6 +24,11 @@ namespace MontanaJohns.Actors
CheckHealth();
}
+ protected override void FixedUpdate()
+ {
+ // Temp override while missing falling logic/animations
+ }
+
void MoveTowardsPlayer()
{
if (player.transform.position.x < transform.position.x) Move(-stats.speedMultiplier * 0.5f);
@@ -37,7 +42,7 @@ namespace MontanaJohns.Actors
void Attack()
{
- if (Mathf.Abs(player.transform.position.x - transform.position.x) <= 5 && Time.time >= nextAttackTime) {
+ if (Mathf.Abs(player.transform.position.x - transform.position.x) <= 5 && Mathf.Abs(player.transform.position.y - transform.position.y) <= 2 && Time.time >= nextAttackTime) {
_animator.SetTrigger("attack");
player.GetComponent<Actor>().TakeDamage(1);
nextAttackTime = Time.time + 1f / attackRate;
@@ -48,7 +53,7 @@ namespace MontanaJohns.Actors
{
if (other.gameObject.tag == "Projectile")
{
- Debug.Log("Enemy: Hit by projectile");
+ // TODO update once projectile is made an Active Item
TakeDamage(1);
Destroy(other.gameObject);
}
diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs
index 95ec2ca..8ba1daf 100644
--- a/Assets/Scripts/Actors/Player.cs
+++ b/Assets/Scripts/Actors/Player.cs
@@ -16,7 +16,7 @@ namespace MontanaJohns.Actors
private Camera _camera;
private PlayerInput playerInput;
- private InputAction use, move, jump;
+ private InputAction use, move, jump, attack;
protected override void Awake()
{
@@ -25,12 +25,13 @@ namespace MontanaJohns.Actors
playerInput = GetComponent<PlayerInput>();
move = playerInput.currentActionMap.FindAction("Move");
jump = playerInput.currentActionMap.FindAction("Jump");
+ attack = playerInput.currentActionMap.FindAction("Attack");
use = playerInput.currentActionMap.FindAction("Use");
jump.started += context => Jump();
use.started += context => Use();
- use.started += context => Fire();
+ attack.started += context => Fire();
}
protected override void Start()