164db664ef
* Remove non-pacman exercises. * Use vcpkg instead of conan ( make vcpkg a submodule) * Merge the readmem these will need to be improve later
87 lines
4.5 KiB
C++
87 lines
4.5 KiB
C++
#include "Board.hpp"
|
|
|
|
// Legend
|
|
// 0 - wall
|
|
// 1 - pellet
|
|
// 2 - nothing
|
|
// 3 - door
|
|
// 4 - superpower
|
|
|
|
static const uint8_t board[ROWS][COLUMNS] = {
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 0
|
|
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, // 1
|
|
{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0}, // 2
|
|
{0, 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 4, 0}, // 3
|
|
{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0}, // 4
|
|
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, // 5
|
|
{0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0}, // 6
|
|
{0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0}, // 7
|
|
{0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 30
|
|
};
|
|
|
|
Board::Board() {
|
|
for (uint8_t row = 0; row < ROWS; row++)
|
|
for (uint8_t column = 0; column < COLUMNS; column++)
|
|
board_state[row][column] = board[row][column];
|
|
}
|
|
|
|
bool Board::isWalkable(Position point, float_t position_delta, Direction direction) const {
|
|
switch (direction) {
|
|
case Direction::LEFT:
|
|
return board_state[int(point.y)][int(point.x - position_delta)] != 0;
|
|
case Direction::RIGHT:
|
|
return board_state[int(point.y)][int(point.x) + 1] != 0;
|
|
case Direction::UP:
|
|
return board_state[int(point.y - position_delta)][int(point.x)] != 0;
|
|
case Direction::DOWN:
|
|
return board_state[int(point.y) + 1][int(point.x)] != 0;
|
|
case Direction::NONE:
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
std::vector<SDL_Point> Board::initialPelletPositions() const {
|
|
std::vector<SDL_Point> positions;
|
|
for (uint8_t row = 0; row < ROWS; row++) {
|
|
for (uint8_t column = 0; column < COLUMNS; column++) {
|
|
if (board_state[row][column] == 1)
|
|
positions.push_back({column, row});
|
|
}
|
|
}
|
|
return positions;
|
|
}
|
|
|
|
std::vector<SDL_Point> Board::initialSuperPelletPositions() const {
|
|
std::vector<SDL_Point> positions;
|
|
for (uint8_t row = 0; row < ROWS; row++) {
|
|
for (uint8_t column = 0; column < COLUMNS; column++) {
|
|
if (board_state[row][column] == 4)
|
|
positions.push_back({column, row});
|
|
}
|
|
}
|
|
return positions;
|
|
}
|