Move teleport to Board
This commit is contained in:
parent
370a57f454
commit
890d061a92
3 changed files with 23 additions and 7 deletions
|
@ -9,9 +9,11 @@ enum class Cell {
|
||||||
wall = 0,
|
wall = 0,
|
||||||
pellet = 1,
|
pellet = 1,
|
||||||
nothing = 2,
|
nothing = 2,
|
||||||
door = 3,
|
// missing 3
|
||||||
power_pellet = 4,
|
power_pellet = 4,
|
||||||
pen = 5,
|
pen = 5,
|
||||||
|
left_portal = 6,
|
||||||
|
right_portal = 7
|
||||||
};
|
};
|
||||||
|
|
||||||
// Legend
|
// Legend
|
||||||
|
@ -39,7 +41,7 @@ constexpr std::array<std::array<int, COLUMNS>, ROWS> board = {{
|
||||||
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 11
|
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 11
|
||||||
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 5, 5, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 12
|
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 5, 5, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 12
|
||||||
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 5, 5, 5, 5, 5, 5, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 13
|
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 5, 5, 5, 5, 5, 5, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 13
|
||||||
{ 3, 2, 2, 2, 2, 2, 1, 2, 2, 2, 0, 5, 5, 5, 5, 5, 5, 0, 2, 2, 2, 1, 2, 2, 2, 2, 2, 3 }, // 14
|
{ 6, 2, 2, 2, 2, 2, 1, 2, 2, 2, 0, 5, 5, 5, 5, 5, 5, 0, 2, 2, 2, 1, 2, 2, 2, 2, 2, 7 }, // 14
|
||||||
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 5, 5, 5, 5, 5, 5, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 15
|
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 5, 5, 5, 5, 5, 5, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 15
|
||||||
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 16
|
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 16
|
||||||
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 17
|
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 17
|
||||||
|
@ -80,8 +82,19 @@ bool isInPen(GridPosition point) {
|
||||||
return cellAtPosition(point) == Cell::pen;
|
return cellAtPosition(point) == Cell::pen;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPortal(GridPosition point) {
|
bool isPortal(GridPosition point, Direction direction) {
|
||||||
return cellAtPosition(point) == Cell::door;
|
return (cellAtPosition(point) == Cell::left_portal && direction == Direction::LEFT) ||
|
||||||
|
(cellAtPosition(point) == Cell::right_portal && direction == Direction::RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
GridPosition teleport(GridPosition point) {
|
||||||
|
size_t right = COLUMNS - 1;
|
||||||
|
size_t left = 0;
|
||||||
|
if (point.x == left)
|
||||||
|
point.x = right;
|
||||||
|
else if (point.x == right)
|
||||||
|
point.x = left;
|
||||||
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<GridPosition> initialPelletPositions() {
|
std::vector<GridPosition> initialPelletPositions() {
|
||||||
|
|
|
@ -54,8 +54,9 @@ void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta, bool
|
||||||
|
|
||||||
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta) {
|
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta) {
|
||||||
|
|
||||||
if(isPortal(positionInGrid())) {
|
if (isPortal(positionInGrid(), direction)) {
|
||||||
// TODO: patricia
|
pos = gridPositionToPosition(teleport(positionInGrid()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double position_delta = 0.004 * time_delta.count();
|
const double position_delta = 0.004 * time_delta.count();
|
||||||
|
|
|
@ -13,6 +13,8 @@ namespace pacman {
|
||||||
[[nodiscard]] bool isWalkableForPacMan(GridPosition point);
|
[[nodiscard]] bool isWalkableForPacMan(GridPosition point);
|
||||||
[[nodiscard]] bool isWalkableForGhost(GridPosition point, GridPosition origin, bool isEyes);
|
[[nodiscard]] bool isWalkableForGhost(GridPosition point, GridPosition origin, bool isEyes);
|
||||||
[[nodiscard]] bool isInPen(GridPosition point);
|
[[nodiscard]] bool isInPen(GridPosition point);
|
||||||
|
[[nodiscard]] bool isPortal(GridPosition point, Direction direction);
|
||||||
|
[[nodiscard]] GridPosition teleport(GridPosition point);
|
||||||
|
|
||||||
[[nodiscard]] std::vector<GridPosition> initialPelletPositions();
|
[[nodiscard]] std::vector<GridPosition> initialPelletPositions();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue