Skip to content
Snippets Groups Projects
Verified Commit 1fd1dc5f authored by Adrian Paschkowski's avatar Adrian Paschkowski :thinking:
Browse files

Don't hardcode Arrow attack damage, more documentation

parent 0843c361
No related branches found
No related tags found
No related merge requests found
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
// Removes all active Arrows from the play field at round end.
public class ArrowDespawner : MonoBehaviour, IRoundCallback public class ArrowDespawner : MonoBehaviour, IRoundCallback
{ {
void Start()
{
RoundController.instance.roundCallbacks.Add(this);
}
public void OnRoundEnd(bool won) public void OnRoundEnd(bool won)
{ {
ArrowController[] arrows = FindObjectsOfType<ArrowController>(); ArrowController[] arrows = FindObjectsOfType<ArrowController>();
...@@ -15,18 +19,7 @@ public class ArrowDespawner : MonoBehaviour, IRoundCallback ...@@ -15,18 +19,7 @@ public class ArrowDespawner : MonoBehaviour, IRoundCallback
public void OnRoundStart() public void OnRoundStart()
{ {
// nop
}
// Start is called before the first frame update
void Start()
{
RoundController.instance.roundCallbacks.Add(this);
} }
// Update is called once per frame
void Update()
{
}
} }
public class Archer : Enemy public class Archer : Enemy
{ {
// Archers don't have any special abilities public int GetArrowAttackDamage()
{
return GetAttackDamage();
}
} }
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
// Controls an Arrow shot by an Archer. Moves it across the play field until it hits the AntiPlayer.
public class ArrowController : MonoBehaviour public class ArrowController : MonoBehaviour
{ {
[SerializeField] float speed; [SerializeField] float speed;
[SerializeField] Opponent opponent; [SerializeField] Opponent opponent;
public int direction; public int direction;
public Archer archer;
Rigidbody2D rb; Rigidbody2D rb;
void Awake() void Awake()
...@@ -15,7 +17,6 @@ public class ArrowController : MonoBehaviour ...@@ -15,7 +17,6 @@ public class ArrowController : MonoBehaviour
rb = GetComponentInChildren<Rigidbody2D>(); rb = GetComponentInChildren<Rigidbody2D>();
} }
// Update is called once per frame
void Update() void Update()
{ {
rb.velocity = transform.up * -1 * speed; rb.velocity = transform.up * -1 * speed;
...@@ -25,7 +26,7 @@ public class ArrowController : MonoBehaviour ...@@ -25,7 +26,7 @@ public class ArrowController : MonoBehaviour
{ {
if (other.CompareTag("AntiPlayer")) 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); Destroy(gameObject);
} }
} }
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine; 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 public class ArrowSpawner : StateMachineBehaviour
{ {
[SerializeField] GameObject arrowPrefab; [SerializeField] GameObject arrowPrefab;
GameObject arrow; GameObject arrow;
...@@ -18,17 +19,18 @@ public class ArrowSpawner : StateMachineBehaviour ...@@ -18,17 +19,18 @@ public class ArrowSpawner : StateMachineBehaviour
} }
Vector2 spawnPos = animator.gameObject.transform.position; Vector2 spawnPos = animator.gameObject.transform.position;
spawnPos += new Vector2(1 * directionArrow, 0); spawnPos += new Vector2(1 * directionArrow, 0);
arrow = Instantiate(arrowPrefab,spawnPos,Quaternion.identity); arrow = Instantiate(arrowPrefab, spawnPos, Quaternion.identity);
ChangeArrowDirection(arrow,directionArrow); ChangeArrowDirection(arrow, directionArrow);
ArrowController arrowController = arrow.GetComponentInChildren<ArrowController>(); ArrowController arrowController = arrow.GetComponentInChildren<ArrowController>();
arrowController.direction = directionArrow; arrowController.direction = directionArrow;
arrowController.archer = animator.gameObject.GetComponent<Archer>();
} }
} }
void ChangeArrowDirection(GameObject arrow, int directionArrow) void ChangeArrowDirection(GameObject arrow, int directionArrow)
{ {
arrow.transform.Rotate(0, 0, 90 * directionArrow); arrow.transform.Rotate(0, 0, 90 * directionArrow);
} }
} }
...@@ -153,11 +153,15 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback ...@@ -153,11 +153,15 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback
// If we hit an opponent, deal them damage // If we hit an opponent, deal them damage
if (roundRunning && other.CompareTag(opponentTag)) if (roundRunning && other.CompareTag(opponentTag))
{ {
var damageToDeal = Mathf.RoundToInt(baseAttackDamage * GetStats().damageMultiplier); other.GetComponent<Fighter>().DealDamage(GetAttackDamage());
other.GetComponent<Fighter>().DealDamage(damageToDeal);
} }
} }
protected int GetAttackDamage()
{
return Mathf.RoundToInt(baseAttackDamage * GetStats().damageMultiplier);
}
public virtual void OnRoundStart() public virtual void OnRoundStart()
{ {
roundRunning = true; roundRunning = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment