67 lines
1.3 KiB
C++
67 lines
1.3 KiB
C++
#include "Pinky.hpp"
|
|
#include "GameState.hpp"
|
|
|
|
namespace pacman {
|
|
|
|
Pinky::Pinky()
|
|
: Ghost(Atlas::Ghost::pinky) {
|
|
pos = initialPosition();
|
|
}
|
|
|
|
double Pinky::speed() const {
|
|
if (state == State::Eyes)
|
|
return 2;
|
|
if (state == State::Frightened)
|
|
return 0.5;
|
|
return 0.75;
|
|
}
|
|
|
|
void Pinky::setTarget(GridPosition pacManPos, Direction pacManDir) {
|
|
if (state == State::Eyes) {
|
|
target = initialPosition();
|
|
return;
|
|
}
|
|
|
|
if (isInPen()) {
|
|
target = penDoorPosition();
|
|
return;
|
|
}
|
|
|
|
if (state == State::Scatter) {
|
|
target = scatterTarget();
|
|
return;
|
|
}
|
|
|
|
// Inky first selects a position 2 cell away from pacman in his direction.
|
|
GridPosition targetPosition = pacManPos;
|
|
switch (pacManDir) {
|
|
case Direction::LEFT:
|
|
targetPosition.x -= 4;
|
|
break;
|
|
case Direction::RIGHT:
|
|
targetPosition.x += 4;
|
|
break;
|
|
case Direction::UP:
|
|
targetPosition.y -= 4;
|
|
targetPosition.x -= 4;
|
|
break;
|
|
case Direction::DOWN:
|
|
targetPosition.y += 4;
|
|
break;
|
|
case Direction::NONE:
|
|
assert(false && "Pacman should be moving");
|
|
break;
|
|
}
|
|
|
|
target = gridPositionToPosition(targetPosition);
|
|
}
|
|
|
|
Position Pinky::initialPosition() const {
|
|
return { 11.5, 14 };
|
|
}
|
|
|
|
Position Pinky::scatterTarget() const {
|
|
return { 3, -2 };
|
|
}
|
|
|
|
} // namespace pacman
|