pacman/lib/Pinky.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

2021-07-28 13:28:36 +00:00
#include "Pinky.hpp"
2021-07-29 09:16:08 +00:00
#include "GameState.hpp"
2021-07-28 13:28:36 +00:00
namespace pacman {
Pinky::Pinky()
: Ghost(Atlas::Ghost::pinky) {
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 Pinky::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 Pinky::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialPosition();
2021-07-28 13:28:36 +00:00
if (isInPen())
2021-07-28 13:41:32 +00:00
return penDoorPosition();
2021-07-28 13:28:36 +00:00
2021-07-29 09:16:08 +00:00
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);
2021-07-28 13:28:36 +00:00
}
Position Pinky::initialPosition() const {
return { 11.5, 14 };
}
Position Pinky::scatterTarget() const {
return { 3, -2 };
}
}