Fix some warnings and clang tidy
This commit is contained in:
parent
dac3b12dc4
commit
e9fb5dac77
11 changed files with 30 additions and 37 deletions
|
@ -51,7 +51,7 @@ bool Board::isWalkableForPacMan(GridPosition point) {
|
|||
return cellAtPosition(point) != Cell::wall;
|
||||
}
|
||||
|
||||
bool Board::isWalkableForGost(GridPosition point, GridPosition origin, bool isEyes) {
|
||||
bool Board::isWalkableForGhost(GridPosition point, GridPosition origin, bool isEyes) {
|
||||
Cell cell = cellAtPosition(point);
|
||||
if (cell == Cell::wall)
|
||||
return false;
|
||||
|
|
|
@ -77,7 +77,7 @@ void Ghost::update(std::chrono::milliseconds time_delta, const Board & board) {
|
|||
}
|
||||
|
||||
bool Ghost::isInPen(const Board & board) const {
|
||||
return board.isInPen(positionInGrid());
|
||||
return pacman::Board::isInPen(positionInGrid());
|
||||
}
|
||||
|
||||
void Ghost::updatePosition(std::chrono::milliseconds time_delta, const Board & board) {
|
||||
|
@ -128,7 +128,7 @@ double Ghost::speed() const {
|
|||
* from that cell is considered infinite (due to the shape of the maze, there is always one direction
|
||||
* a ghost can take).
|
||||
*
|
||||
* In the scatter state, each ghost tries to reach an unreacheable position outside of the map.
|
||||
* In the scatter state, each ghost tries to reach an unreachable position outside of the map.
|
||||
* This makes ghosts run in circle around the island at each of the 4 map corner.
|
||||
*/
|
||||
void Ghost::updateDirection(const Board & board) {
|
||||
|
@ -161,7 +161,7 @@ void Ghost::updateDirection(const Board & board) {
|
|||
continue;
|
||||
|
||||
const GridPosition grid_position = {size_t(move.position.x), size_t(move.position.y)};
|
||||
const bool can_walk = board.isWalkableForGost(grid_position, current_grid_position, isEyes());
|
||||
const bool can_walk = pacman::Board::isWalkableForGhost(grid_position, current_grid_position, isEyes());
|
||||
if (!can_walk)
|
||||
continue;
|
||||
|
||||
|
@ -181,8 +181,8 @@ Position Ghost::target(const Board & board) const {
|
|||
if (state == State::Eyes)
|
||||
return startingPosition;
|
||||
|
||||
if (board.isInPen(positionInGrid()))
|
||||
return board.penDoorPosition();
|
||||
if (pacman::Board::isInPen(positionInGrid()))
|
||||
return pacman::Board::penDoorPosition();
|
||||
|
||||
return scatterTarget;
|
||||
}
|
||||
|
@ -196,19 +196,19 @@ void Ghost::updateAnimation(std::chrono::milliseconds time_delta) {
|
|||
}
|
||||
|
||||
Blinky::Blinky(const Board & board)
|
||||
: Ghost(Atlas::Ghost::blinky, board.initialBlinkyPosition(), board.blinkyScatterTarget()) {
|
||||
: Ghost(Atlas::Ghost::blinky, pacman::Board::initialBlinkyPosition(), pacman::Board::blinkyScatterTarget()) {
|
||||
}
|
||||
|
||||
Speedy::Speedy(const Board & board)
|
||||
: Ghost(Atlas::Ghost::speedy, board.initialSpeedyPosition(), board.speedyScatterTarget()) {
|
||||
: Ghost(Atlas::Ghost::speedy, pacman::Board::initialSpeedyPosition(), pacman::Board::speedyScatterTarget()) {
|
||||
}
|
||||
|
||||
Inky::Inky(const Board & board)
|
||||
: Ghost(Atlas::Ghost::inky, board.initialInkyPosition(), board.inkyScatterTarget()) {
|
||||
: Ghost(Atlas::Ghost::inky, pacman::Board::initialInkyPosition(), pacman::Board::inkyScatterTarget()) {
|
||||
}
|
||||
|
||||
Clyde::Clyde(const Board & board)
|
||||
: Ghost(Atlas::Ghost::clyde, board.initialClydePosition(), board.clydeScatterTarget()) {
|
||||
: Ghost(Atlas::Ghost::clyde, pacman::Board::initialClydePosition(), pacman::Board::clydeScatterTarget()) {
|
||||
}
|
||||
|
||||
} // namespace pacman
|
||||
|
|
|
@ -7,7 +7,7 @@ PacMan::PacMan(const Board & board)
|
|||
: pos(Board::initialPacManPosition()) {}
|
||||
|
||||
GridPosition PacMan::currentSprite() const {
|
||||
return eaten ? pacManAnimation.deathAnimationFrame(direction) : pacManAnimation.animationFrame(direction);
|
||||
return eaten ? pacManAnimation.deathAnimationFrame() : pacManAnimation.animationFrame(direction);
|
||||
}
|
||||
|
||||
Position PacMan::position() const {
|
||||
|
@ -28,7 +28,7 @@ void PacMan::eat() {
|
|||
void PacMan::reset(const Board & b) {
|
||||
eaten = false;
|
||||
direction = Direction::NONE;
|
||||
pos = b.initialPacManPosition();
|
||||
pos = pacman::Board::initialPacManPosition();
|
||||
}
|
||||
|
||||
void PacMan::update(std::chrono::milliseconds time_delta, InputState state, const Board & board) {
|
||||
|
|
|
@ -18,7 +18,7 @@ GridPosition PacManAnimation::animationFrame(Direction direction) const {
|
|||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] GridPosition PacManAnimation::deathAnimationFrame(Direction direction) const {
|
||||
[[nodiscard]] GridPosition PacManAnimation::deathAnimationFrame() const {
|
||||
return GridPosition{ animation_position, 1 };
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
namespace pacman {
|
||||
|
||||
Pellets::Pellets(const Board & board)
|
||||
: positions(board.initialPelletPositions()) {}
|
||||
: positions(pacman::Board::initialPelletPositions()) {}
|
||||
|
||||
bool Pellets::eatPelletAtPosition(GridPosition p) {
|
||||
auto it = std::find(positions.begin(), positions.end(), p);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
namespace pacman {
|
||||
|
||||
SuperPellets::SuperPellets(const Board & board)
|
||||
: positions(board.initialSuperPelletPositions()) {}
|
||||
: positions(pacman::Board::initialSuperPelletPositions()) {}
|
||||
|
||||
bool SuperPellets::eatPelletAtPosition(GridPosition p) {
|
||||
auto it = std::find(positions.begin(), positions.end(), p);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "Direction.hpp"
|
||||
#include "Position.hpp"
|
||||
#include "assert.h"
|
||||
#include <cassert>
|
||||
|
||||
#include <array>
|
||||
|
||||
|
@ -31,30 +31,23 @@ constexpr GridPosition ghost_white_frightened = { 2, 7 };
|
|||
constexpr GridPosition ghost_white_frightened2 = { 3, 7 };
|
||||
|
||||
constexpr GridPosition eyeSprite(Direction direction) {
|
||||
size_t x = 0;
|
||||
switch (direction) {
|
||||
case Direction::RIGHT:
|
||||
x = 0;
|
||||
break;
|
||||
return { 0, 6 };
|
||||
case Direction::DOWN:
|
||||
x = 2;
|
||||
break;
|
||||
return { 2, 6 };
|
||||
case Direction::LEFT:
|
||||
x = 4;
|
||||
break;
|
||||
return { 4, 6 };
|
||||
case Direction::UP:
|
||||
x = 6;
|
||||
break;
|
||||
return { 6, 6 };
|
||||
default:
|
||||
x = 0;
|
||||
break;
|
||||
return { 0, 6 };
|
||||
}
|
||||
return { x, 6 };
|
||||
}
|
||||
|
||||
constexpr GridPosition ghostSprite(Ghost ghost, Direction direction, bool alternative) {
|
||||
assert(ghost >= Ghost::blinky && ghost <= Ghost::clyde && "Invalid Ghost");
|
||||
size_t y = static_cast<size_t>(ghost);
|
||||
auto y = static_cast<size_t>(ghost);
|
||||
size_t x = 0;
|
||||
switch (direction) {
|
||||
case Direction::RIGHT:
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
};
|
||||
|
||||
[[nodiscard]] static bool isWalkableForPacMan(GridPosition point);
|
||||
[[nodiscard]] static bool isWalkableForGost(GridPosition point, GridPosition origin, bool isEyes);
|
||||
[[nodiscard]] static bool isWalkableForGhost(GridPosition point, GridPosition origin, bool isEyes);
|
||||
[[nodiscard]] static bool isInPen(GridPosition point);
|
||||
|
||||
[[nodiscard]] static std::vector<GridPosition> initialPelletPositions();
|
||||
|
|
|
@ -28,16 +28,16 @@ public:
|
|||
void update(std::chrono::milliseconds time_delta, const Board & board);
|
||||
void frighten();
|
||||
void eat();
|
||||
bool isFrightened() const;
|
||||
bool isEyes() const;
|
||||
[[nodiscard]] bool isFrightened() const;
|
||||
[[nodiscard]] bool isEyes() const;
|
||||
void reset();
|
||||
|
||||
private:
|
||||
double speed() const;
|
||||
[[nodiscard]] double speed() const;
|
||||
void updateAnimation(std::chrono::milliseconds time_delta);
|
||||
void updatePosition(std::chrono::milliseconds time_delta, const Board & board);
|
||||
void updateDirection(const Board & board);
|
||||
Position target(const Board & board) const;
|
||||
[[nodiscard]] Position target(const Board & board) const;
|
||||
|
||||
protected:
|
||||
Atlas::Ghost spritesSet;
|
||||
|
@ -51,7 +51,7 @@ protected:
|
|||
Position startingPosition;
|
||||
Position scatterTarget;
|
||||
GridPosition last_grid_position = { 0, 0 };
|
||||
bool isInPen(const Board & board) const;
|
||||
[[nodiscard]] bool isInPen(const Board & board) const;
|
||||
};
|
||||
|
||||
class Blinky : public Ghost {
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
void eat();
|
||||
void reset(const Board & b);
|
||||
bool onTheMove() const {
|
||||
[[nodiscard]] bool onTheMove() const {
|
||||
return direction != Direction::NONE;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace pacman {
|
|||
class PacManAnimation {
|
||||
public:
|
||||
[[nodiscard]] GridPosition animationFrame(Direction direction) const;
|
||||
[[nodiscard]] GridPosition deathAnimationFrame(Direction direction) const;
|
||||
[[nodiscard]] GridPosition deathAnimationFrame() const;
|
||||
|
||||
void updateAnimationPosition(std::chrono::milliseconds time_delta, bool dead);
|
||||
void pause();
|
||||
|
|
Loading…
Reference in a new issue