diff options
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Actors/Actor.cs | 20 | ||||
-rw-r--r-- | Assets/Scripts/Actors/Enemy.cs | 9 | ||||
-rw-r--r-- | Assets/Scripts/Actors/Player.cs | 5 | ||||
-rw-r--r-- | Assets/Scripts/Items/Whip.cs | 5 |
4 files changed, 27 insertions, 12 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() diff --git a/Assets/Scripts/Items/Whip.cs b/Assets/Scripts/Items/Whip.cs index 134ea53..cfc7aa9 100644 --- a/Assets/Scripts/Items/Whip.cs +++ b/Assets/Scripts/Items/Whip.cs @@ -46,7 +46,8 @@ namespace MontanaJohns.Items } else { - StartCoroutine(WhipSmack(collisionGameObject, clickLocation)); + // TODO uncomment this later when Projectiles are reworked into an Active Item (commented out for demonstration purposes) + // StartCoroutine(WhipSmack(collisionGameObject, clickLocation)); } } return null; @@ -62,7 +63,7 @@ namespace MontanaJohns.Items private IEnumerator WhipSmack(GameObject collisionGameObject, Vector2 clickLocation) { currentHook = Instantiate(hookNoSwing, clickLocation, Quaternion.identity); - collisionGameObject.GetComponent<Actor>().TakeDamage(player.GetComponent<Stats>().damage); + collisionGameObject.GetComponent<Actor>().TakeDamage(player.GetComponent<Player>().stats.damage); yield return new WaitForSeconds(0.1f); Destroy(currentHook); ropeExists = false; |