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