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;
// 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()
{
}
}
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;
// 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);
}
}
......
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);
}
}
......@@ -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;
......
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