pacman/lib/Clyde.cpp

48 lines
1 KiB
C++
Raw Normal View History

2021-07-28 13:28:36 +00:00
#include "Clyde.hpp"
2021-07-29 09:16:08 +00:00
#include "GameState.hpp"
2021-07-28 13:28:36 +00:00
namespace pacman {
Clyde::Clyde()
: Ghost(Atlas::Ghost::clyde) {
2021-07-28 15:01:22 +00:00
pos = initialPosition();
2021-07-28 13:28:36 +00:00
}
2021-08-02 12:29:25 +00:00
double Clyde::speed(const GameState &) 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;
}
Position Clyde::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialPosition();
2021-07-28 13:28:36 +00:00
if (isInPen())
return penDoorPosition();
2021-07-29 09:16:08 +00:00
// Clyde always target its scatter target, unless pacman is further than 8 tiles away
auto targetPosition = scatterTarget();
2021-08-02 12:24:11 +00:00
if (state == State::Scatter)
return targetPosition;
2021-07-29 09:16:08 +00:00
const auto pacManPosition = gameState.pacMan.position();
auto distanceFomPacMan = positionDistance(pos, pacManPosition);
2021-08-02 12:24:11 +00:00
if (distanceFomPacMan > 8)
targetPosition = pacManPosition;
2021-07-29 09:16:08 +00:00
return targetPosition;
2021-07-28 13:28:36 +00:00
}
Position Clyde::initialPosition() const {
return { 15.5, 14 };
}
Position Clyde::scatterTarget() const {
return { 0, 30 };
}
} // namespace pacman