Name changes and typos
This commit is contained in:
parent
335f15e276
commit
ab9664d07f
4 changed files with 9 additions and 8 deletions
|
@ -23,7 +23,8 @@ Position Blinky::target(const GameState & gameState) const {
|
||||||
if (isInPen())
|
if (isInPen())
|
||||||
return penDoorPosition();
|
return penDoorPosition();
|
||||||
|
|
||||||
return state == State::Chase ? gridPositionToPosition(gameState.pacMan.positionInGrid()) : scatterTarget();
|
const auto pacManPosition = gridPositionToPosition(gameState.pacMan.positionInGrid());
|
||||||
|
return state == State::Chase ? pacManPosition : scatterTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position Blinky::initialPosition() const {
|
Position Blinky::initialPosition() const {
|
||||||
|
|
|
@ -26,10 +26,10 @@ Position Clyde::target(const GameState & gameState) const {
|
||||||
// Clyde always target its scatter target, unless pacman is further than 8 tiles away
|
// Clyde always target its scatter target, unless pacman is further than 8 tiles away
|
||||||
auto targetPosition = scatterTarget();
|
auto targetPosition = scatterTarget();
|
||||||
|
|
||||||
const auto & pacmanPosition = gameState.pacMan.positionInGrid();
|
const auto pacManPosition = gameState.pacMan.positionInGrid();
|
||||||
auto distanceFomPacMan = std::hypot(pos.x - pacmanPosition.x, pos.y - pacmanPosition.y);
|
auto distanceFomPacMan = std::hypot(pos.x - pacManPosition.x, pos.y - pacManPosition.y);
|
||||||
if (state == State::Chase && distanceFomPacMan > 8)
|
if (state == State::Chase && distanceFomPacMan > 8)
|
||||||
targetPosition = gridPositionToPosition(pacmanPosition);
|
targetPosition = gridPositionToPosition(pacManPosition);
|
||||||
|
|
||||||
return targetPosition;
|
return targetPosition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,14 +199,14 @@ void Ghost::updateAnimation(std::chrono::milliseconds time_delta) {
|
||||||
* Ghosts alternate between the scatter and chase states at
|
* Ghosts alternate between the scatter and chase states at
|
||||||
* specific intervals
|
* specific intervals
|
||||||
*/
|
*/
|
||||||
Ghost::State Ghost::defaultStateAtDuration(std::chrono::seconds s) {
|
Ghost::State Ghost::defaultStateAtDuration(std::chrono::seconds seconds) {
|
||||||
// This array denotes the duration of each state, alternating between scatter and chase
|
// This array denotes the duration of each state, alternating between scatter and chase
|
||||||
std::array changes = { /*scatter*/ 7, 20, 7, 20, 5, 20, 5 };
|
std::array changes = { /*scatter*/ 7, 20, 7, 20, 5, 20, 5 };
|
||||||
// To know the current state we first compute the cumulative time using std::partial_sum
|
// To know the current state we first compute the cumulative time using std::partial_sum
|
||||||
// This gives us {7, 27, 34, 54, 59, 79, 84}
|
// This gives us {7, 27, 34, 54, 59, 79, 84}
|
||||||
std::partial_sum(std::begin(changes), std::end(changes), std::begin(changes));
|
std::partial_sum(std::begin(changes), std::end(changes), std::begin(changes));
|
||||||
// Then we look for the first value in the array greater than the time spend in chase/scatter states
|
// Then we look for the first value in the array greater than the time spent in chase/scatter states
|
||||||
auto it = std::upper_bound(std::begin(changes), std::end(changes), s.count());
|
auto it = std::upper_bound(std::begin(changes), std::end(changes), seconds.count());
|
||||||
// We get the position of that iterator in the array
|
// We get the position of that iterator in the array
|
||||||
auto count = std::distance(std::begin(changes), it);
|
auto count = std::distance(std::begin(changes), it);
|
||||||
// Because the first positition is scatter, all the even positions will be scatter
|
// Because the first positition is scatter, all the even positions will be scatter
|
||||||
|
|
|
@ -41,7 +41,7 @@ private:
|
||||||
void updateDirection(const GameState & gameState);
|
void updateDirection(const GameState & gameState);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
State defaultStateAtDuration(std::chrono::seconds s);
|
State defaultStateAtDuration(std::chrono::seconds seconds);
|
||||||
|
|
||||||
virtual double speed(const GameState & gameState) const = 0;
|
virtual double speed(const GameState & gameState) const = 0;
|
||||||
virtual Position target(const GameState & gameState) const = 0;
|
virtual Position target(const GameState & gameState) const = 0;
|
||||||
|
|
Loading…
Reference in a new issue