Fix flying bug
This commit is contained in:
+14
-1
@@ -38,6 +38,7 @@ class Game:
|
|||||||
|
|
||||||
def start_game(self):
|
def start_game(self):
|
||||||
self.gameState.set_stop_game(False)
|
self.gameState.set_stop_game(False)
|
||||||
|
falling_steps = 0
|
||||||
|
|
||||||
# Spawn the player at the spawn point
|
# Spawn the player at the spawn point
|
||||||
spawn_point_position = self.map.get_first_block_type_position('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:
|
while not self.gameState.stopGame:
|
||||||
if self.gameState.playerVelocity == -1 and self.waitingForInputCallback:
|
if self.gameState.playerVelocity == -1 and self.waitingForInputCallback:
|
||||||
|
falling_steps = 0
|
||||||
self.gameState.set_player_velocity(self.waitingForInputCallback())
|
self.gameState.set_player_velocity(self.waitingForInputCallback())
|
||||||
self.gameState.add_move_count()
|
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
|
# Try to move the player according to his velocity
|
||||||
velocity_position = self.get_position_at_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
|
block_at_velocity = None
|
||||||
if velocity_position is not None:
|
if velocity_position is not None:
|
||||||
block_at_velocity = self.map.get_block_at(velocity_position[0], velocity_position[1])
|
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)
|
self.gameState.set_player_velocity(-1)
|
||||||
return
|
return
|
||||||
|
|
||||||
if current_velocity is "up": # Going up → Going down
|
if current_velocity == "up": # Going up → Going down
|
||||||
self.gameState.set_player_velocity("down")
|
self.gameState.set_player_velocity("down")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user