pacman/lib/Pinky.cpp
2021-07-29 11:16:08 +02:00

60 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 GameState & gameState) const {
if (state == State::Eyes)
return 2;
if (state == State::Frightened)
return 0.5;
return 0.75;
}
Position Pinky::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialPosition();
if (isInPen())
return penDoorPosition();
if (state == State::Scatter)
return scatterTarget();
// Inky first selects a position 2 cell away from pacman in his direction.
GridPosition targetPosition = gameState.pacMan.positionInGrid();
switch (gameState.pacMan.currentDirection()) {
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("Pacman should be moving!");
break;
}
return gridPositionToPosition(targetPosition);
}
Position Pinky::initialPosition() const {
return { 11.5, 14 };
}
Position Pinky::scatterTarget() const {
return { 3, -2 };
}
}