diff --git a/game/game.py b/game/game.py index 24c1b24..6383b1b 100644 --- a/game/game.py +++ b/game/game.py @@ -38,6 +38,7 @@ class Game: def start_game(self): self.gameState.set_stop_game(False) + falling_steps = 0 # Spawn the player at the spawn point spawn_point_position = self.map.get_first_block_type_position('spawn_point') @@ -48,11 +49,23 @@ class Game: while not self.gameState.stopGame: if self.gameState.playerVelocity == -1 and self.waitingForInputCallback: + falling_steps = 0 self.gameState.set_player_velocity(self.waitingForInputCallback()) self.gameState.add_move_count() + elif self.gameState.playerVelocity != -1: + falling_steps += 1 + if falling_steps > self.map.height: + self.gameState.set_game_won(False) + self.gameState.set_stop_game(True) + self._position_update() + continue # Try to move the player according to his velocity velocity_position = self.get_position_at_velocity() + if velocity_position is not None and not self.map.is_position_in_bounds(velocity_position): + self.gameState.set_stop_game(True) + self._position_update() + continue block_at_velocity = None if velocity_position is not None: block_at_velocity = self.map.get_block_at(velocity_position[0], velocity_position[1]) @@ -85,7 +98,7 @@ class Game: self.gameState.set_player_velocity(-1) return - if current_velocity is "up": # Going up → Going down + if current_velocity == "up": # Going up → Going down self.gameState.set_player_velocity("down") return