diff --git a/lib/Ghost.cpp b/lib/Ghost.cpp index f7a5971..ea47fbe 100644 --- a/lib/Ghost.cpp +++ b/lib/Ghost.cpp @@ -184,7 +184,7 @@ void Ghost::updateDirection(const GameState & gameState) { return a.distance_to_target < b.distance_to_target; }); - auto move = *optimal_move; + const auto& move = *optimal_move; direction = move.direction; last_grid_position = current_grid_position; } diff --git a/lib/PacMan.cpp b/lib/PacMan.cpp index b08bdf9..f3739f4 100644 --- a/lib/PacMan.cpp +++ b/lib/PacMan.cpp @@ -18,6 +18,7 @@ GridPosition PacMan::positionInGrid() const { void PacMan::die() { if (dead) return; + dead = true; } @@ -33,8 +34,10 @@ void PacMan::update(std::chrono::milliseconds time_delta, Direction input_direct updateAnimationPosition(time_delta, false); return; } + if (input_direction != Direction::NONE) desired_direction = input_direction; + const auto old = pos; updateMazePosition(time_delta); const bool paused = pos == old; @@ -50,7 +53,6 @@ void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta, bool } void PacMan::updateMazePosition(std::chrono::milliseconds time_delta) { - if (isPortal(positionInGrid(), direction)) { pos = gridPositionToPosition(teleport(positionInGrid())); return;