From 1fd1dc5fc19c6ee646307eef1efe487e657c48d4 Mon Sep 17 00:00:00 2001 From: Adrian Paschkowski <git@wasdennnoch.me> Date: Sun, 18 Apr 2021 19:33:22 +0200 Subject: [PATCH] Don't hardcode Arrow attack damage, more documentation --- Assets/Scripts/ArrowDespawner.cs | 21 +++++++-------------- Assets/Scripts/Fighters/Archer.cs | 5 ++++- Assets/Scripts/Fighters/ArrowController.cs | 9 +++++---- Assets/Scripts/Fighters/ArrowSpawner.cs | 14 ++++++++------ Assets/Scripts/Fighters/Fighter.cs | 8 ++++++-- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Assets/Scripts/ArrowDespawner.cs b/Assets/Scripts/ArrowDespawner.cs index 7d492c0..654512f 100644 --- a/Assets/Scripts/ArrowDespawner.cs +++ b/Assets/Scripts/ArrowDespawner.cs @@ -1,9 +1,13 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; +// Removes all active Arrows from the play field at round end. public class ArrowDespawner : MonoBehaviour, IRoundCallback { + void Start() + { + RoundController.instance.roundCallbacks.Add(this); + } + public void OnRoundEnd(bool won) { ArrowController[] arrows = FindObjectsOfType<ArrowController>(); @@ -15,18 +19,7 @@ public class ArrowDespawner : MonoBehaviour, IRoundCallback public void OnRoundStart() { - - } - - // Start is called before the first frame update - void Start() - { - RoundController.instance.roundCallbacks.Add(this); + // nop } - // Update is called once per frame - void Update() - { - - } } diff --git a/Assets/Scripts/Fighters/Archer.cs b/Assets/Scripts/Fighters/Archer.cs index 665f919..33801f1 100644 --- a/Assets/Scripts/Fighters/Archer.cs +++ b/Assets/Scripts/Fighters/Archer.cs @@ -1,6 +1,9 @@ public class Archer : Enemy { - // Archers don't have any special abilities + public int GetArrowAttackDamage() + { + return GetAttackDamage(); + } } diff --git a/Assets/Scripts/Fighters/ArrowController.cs b/Assets/Scripts/Fighters/ArrowController.cs index 51cabf7..a876a64 100644 --- a/Assets/Scripts/Fighters/ArrowController.cs +++ b/Assets/Scripts/Fighters/ArrowController.cs @@ -1,13 +1,15 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; +// Controls an Arrow shot by an Archer. Moves it across the play field until it hits the AntiPlayer. public class ArrowController : MonoBehaviour { [SerializeField] float speed; [SerializeField] Opponent opponent; + public int direction; + public Archer archer; + Rigidbody2D rb; void Awake() @@ -15,7 +17,6 @@ public class ArrowController : MonoBehaviour rb = GetComponentInChildren<Rigidbody2D>(); } - // Update is called once per frame void Update() { rb.velocity = transform.up * -1 * speed; @@ -25,7 +26,7 @@ public class ArrowController : MonoBehaviour { if (other.CompareTag("AntiPlayer")) { - other.GetComponent<Fighter>().DealDamage(Mathf.RoundToInt(10 * StatsManager.instance.fighterStats[FighterTypes.ENEMY].damageMultiplier)); + other.GetComponent<Fighter>().DealDamage(archer.GetArrowAttackDamage()); Destroy(gameObject); } } diff --git a/Assets/Scripts/Fighters/ArrowSpawner.cs b/Assets/Scripts/Fighters/ArrowSpawner.cs index 4cf29d3..77bfad6 100644 --- a/Assets/Scripts/Fighters/ArrowSpawner.cs +++ b/Assets/Scripts/Fighters/ArrowSpawner.cs @@ -1,9 +1,10 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; +// Used by the Animator for the Archer animation in the Shoot state. Fires an +// Arrow once the accoring state is entered/animation is played. public class ArrowSpawner : StateMachineBehaviour { + [SerializeField] GameObject arrowPrefab; GameObject arrow; @@ -18,17 +19,18 @@ public class ArrowSpawner : StateMachineBehaviour } Vector2 spawnPos = animator.gameObject.transform.position; spawnPos += new Vector2(1 * directionArrow, 0); - - arrow = Instantiate(arrowPrefab,spawnPos,Quaternion.identity); - ChangeArrowDirection(arrow,directionArrow); + + arrow = Instantiate(arrowPrefab, spawnPos, Quaternion.identity); + ChangeArrowDirection(arrow, directionArrow); ArrowController arrowController = arrow.GetComponentInChildren<ArrowController>(); arrowController.direction = directionArrow; + arrowController.archer = animator.gameObject.GetComponent<Archer>(); } } void ChangeArrowDirection(GameObject arrow, int directionArrow) { arrow.transform.Rotate(0, 0, 90 * directionArrow); - + } } diff --git a/Assets/Scripts/Fighters/Fighter.cs b/Assets/Scripts/Fighters/Fighter.cs index bdff094..197eba6 100644 --- a/Assets/Scripts/Fighters/Fighter.cs +++ b/Assets/Scripts/Fighters/Fighter.cs @@ -153,11 +153,15 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback // If we hit an opponent, deal them damage if (roundRunning && other.CompareTag(opponentTag)) { - var damageToDeal = Mathf.RoundToInt(baseAttackDamage * GetStats().damageMultiplier); - other.GetComponent<Fighter>().DealDamage(damageToDeal); + other.GetComponent<Fighter>().DealDamage(GetAttackDamage()); } } + protected int GetAttackDamage() + { + return Mathf.RoundToInt(baseAttackDamage * GetStats().damageMultiplier); + } + public virtual void OnRoundStart() { roundRunning = true; -- GitLab