2021-07-28 13:28:36 +00:00
|
|
|
#include "Clyde.hpp"
|
|
|
|
|
|
|
|
namespace pacman {
|
|
|
|
|
|
|
|
Clyde::Clyde()
|
2021-07-28 14:20:19 +00:00
|
|
|
: Ghost(Atlas::Ghost::clyde) {
|
2021-07-28 15:01:22 +00:00
|
|
|
pos = initialPosition();
|
2021-07-28 13:28:36 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 12:57:53 +00:00
|
|
|
double Clyde::speed() const {
|
2021-07-28 13:28:36 +00:00
|
|
|
if (state == State::Eyes)
|
|
|
|
return 2;
|
|
|
|
if (state == State::Frightened)
|
|
|
|
return 0.5;
|
|
|
|
return 0.75;
|
|
|
|
}
|
|
|
|
|
2021-09-23 12:57:53 +00:00
|
|
|
void Clyde::setTarget(Position pacManPos) {
|
|
|
|
if (state == State::Eyes) {
|
|
|
|
target = initialPosition();
|
|
|
|
return;
|
|
|
|
}
|
2021-07-28 13:28:36 +00:00
|
|
|
|
2021-09-23 12:57:53 +00:00
|
|
|
if (isInPen()) {
|
|
|
|
target = penDoorPosition();
|
|
|
|
return;
|
|
|
|
}
|
2021-07-28 13:28:36 +00:00
|
|
|
|
2021-07-29 09:16:08 +00:00
|
|
|
// Clyde always target its scatter target, unless pacman is further than 8 tiles away
|
2021-09-23 12:57:53 +00:00
|
|
|
target = scatterTarget();
|
|
|
|
if (state == State::Scatter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto distanceFomPacMan = std::hypot(pos.x - pacManPos.x, pos.y - pacManPos.y);
|
|
|
|
if (distanceFomPacMan > 8) {
|
|
|
|
target = pacManPos;
|
|
|
|
}
|
2021-07-28 13:28:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:20:19 +00:00
|
|
|
Position Clyde::initialPosition() const {
|
2021-07-28 14:39:27 +00:00
|
|
|
return { 15.5, 14 };
|
2021-07-28 14:20:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:39:27 +00:00
|
|
|
Position Clyde::scatterTarget() const {
|
|
|
|
return { 0, 30 };
|
|
|
|
}
|
2021-07-28 14:20:19 +00:00
|
|
|
|
2021-09-20 13:17:07 +00:00
|
|
|
} // namespace pacman
|