#include "Board.h" // Legend // 0 - wall // 1 - pellet // 2 - nothing // 3 - door // 4 - superpower // 16 pixels per square // Maze in pixels - width: 448 - height - 496 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,1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,0}, // 8 {0,0,0,0,0,0,1,0,0,0,0,0,2,0,0,2,0,0,0,0,0,1,0,0,0,0,0,0}, // 9 {0,0,0,0,0,0,1,0,0,0,0,0,2,0,0,2,0,0,0,0,0,1,0,0,0,0,0,0}, // 10 {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,3,3,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,0,0,0,0,0,2,0,0,1,0,0,0,0,0,0}, //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0,0,0,0,0,0,0,0,0,0,0,0,0,0}, // 30 }; Board::Board() { resetBoardState(); } void Board::resetBoardState() { 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; } } SDL_Rect Board::pelletSprite() { return pellet; } SDL_Rect Board::superPelletSprite() { return super_pellet; } std::vector Board::pelletPositions() { std::vector 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 Board::superPelletPositions() { // Hard coded is probably better than this std::vector 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; }