diff --git a/src/Tank.cpp b/src/Tank.cpp index 392ef6b..f59fc11 100644 --- a/src/Tank.cpp +++ b/src/Tank.cpp @@ -13,7 +13,7 @@ Tank::Tank(TankType tankType, Point point) : Drawable(point), initialX_(point.x_), initialY_(point.y_) { setType(tankType); - direction_ = (isPlayerControlled() ? Direction::UP : Direction::DOWN); + resetDirection(); } void Tank::draw(const Display& display) const @@ -188,7 +188,7 @@ void Tank::respawn() setY(initialY_); if (isPlayerControlled()) setType(TankType::PLAYER_TIER_1); - direction_ = (isPlayerControlled() ? Direction::UP : Direction::DOWN); + resetDirection(); } void Tank::adjustEnemySpeed(float& speed) const @@ -205,3 +205,11 @@ int Tank::getCalculatedSpeed(float speedFactor) const adjustEnemySpeed(speed); return std::max(1, static_cast(speed)); } + +void Tank::resetDirection() +{ + if (isPlayerControlled()) + direction_ = Direction::UP; + else + direction_ = Direction::DOWN; +} diff --git a/src/Tank.h b/src/Tank.h index 99449ce..aadc039 100644 --- a/src/Tank.h +++ b/src/Tank.h @@ -58,6 +58,8 @@ class Tank : public Drawable bool destroy(); + void resetDirection(); + static const int BASIC_ATTACK{1}; static const int BASIC_HEALTH{1}; static const int BASIC_SPEED{2};