Support teleporting at the edges of the map
This commit is contained in:
parent
bbf3731cf4
commit
f6efcbbf79
2 changed files with 14 additions and 3 deletions
|
@ -49,7 +49,10 @@ Board::Board() {
|
|||
}
|
||||
|
||||
bool Board::isWalkable(Position point, float position_delta, Direction direction) const {
|
||||
switch (direction) {
|
||||
if(point.x <= 0 || point.x >= COLUMNS-1)
|
||||
return true;
|
||||
|
||||
switch (direction) {
|
||||
case Direction::LEFT:
|
||||
return board_state[int(point.y)][int(point.x - position_delta)] != 0;
|
||||
case Direction::RIGHT:
|
||||
|
|
|
@ -33,9 +33,17 @@ void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta) {
|
|||
}
|
||||
|
||||
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Board & board) {
|
||||
float position_delta = (time_delta.count() / 128.0);
|
||||
float position_delta = std::min(1.0, (time_delta.count() / 128.0));
|
||||
|
||||
if (board.isWalkable(pos, position_delta, desired_direction)) {
|
||||
// Handle teleport
|
||||
if(pos.x >= COLUMNS-1 && direction == Direction::RIGHT) {
|
||||
pos.x = -1;
|
||||
}
|
||||
else if(pos.x <= 0 && direction == Direction::LEFT) {
|
||||
pos.x = COLUMNS;
|
||||
}
|
||||
|
||||
else if (board.isWalkable(pos, position_delta, desired_direction)) {
|
||||
direction = desired_direction;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue