Skip to content
Snippets Groups Projects
Commit 952853aa authored by Max Cherris's avatar Max Cherris
Browse files

Add function to check for Range from allied to enemy unit(s)

parent 2d37a5c8
No related branches found
No related tags found
1 merge request!15Merge units into main
......@@ -70,9 +70,14 @@ MatchupTabel damageMatrix = {
void Unit::attack(Unit &enemy) {
//checks to be run:
//is unit in range?
//has unit not attacked this turn?
if(!inRange(Unit &enemy)) {
//Render enemies as not in Range
}
if (this->has_attacked) {
//display the unit as not able to attack (maybe greyscale?)
}
//Start Attack: choose the appropriate weapon:
int offDamage = damageMatrix[this->id][enemy->id] * ((this->health)/(this->max_health));
......@@ -89,4 +94,13 @@ void Unit::attack(Unit &enemy) {
}
}
void Unit::inRange(Unit &enemy) {
if (this->x == enemy.x) {
return abs(this->y - enemy.y) <= this->range;
} else if (this->y == enemy.y) {
return abs(this->x - enemy.x) <= this->range;
}
return false;
}
} // namespace advanced_wars
\ No newline at end of file
......@@ -66,6 +66,14 @@ public:
void render(Engine &engine, int scale);
/*
Check if attacker is in Range to initiate combat
TODO: This should probably tie back into rendering the units differently
If a unit is selected, it should call inRange on all other enemy units on the field
*/
bool inRange(Unit &enemy);
/*
The attacker will move towards the defender and thus initiate combat
@params Takes a reference to the defender
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment