diff --git a/wincoll/wincoll_game.py b/wincoll/wincoll_game.py index 1f9eb5b..88959e9 100644 --- a/wincoll/wincoll_game.py +++ b/wincoll/wincoll_game.py @@ -129,12 +129,7 @@ def unlock(self) -> None: def can_move(self, velocity: Vector2) -> bool: newpos = self.hero.position + velocity block = self.get(newpos) - if block in ( - Tile.EMPTY, - Tile.EARTH, - Tile.DIAMOND, - Tile.KEY, - ): + if block in (Tile.EMPTY, Tile.EARTH, Tile.DIAMOND, Tile.KEY): return True if block == Tile.ROCK: new_rockpos = self.hero.position + velocity * 2 @@ -169,6 +164,13 @@ def reset_falling(self) -> None: self.falling = False SLIDE_SOUND.stop() + def do_play(self) -> None: + self.physics_frame = (self.physics_frame + 1) % self.subframes + if self.move_frame == 0: + self.physics_frame = 0 + if self.physics_frame == 0: + self.do_physics() + def do_physics(self) -> None: # Put Win into the map data for collision detection. self.set(self.hero.position, Tile.HERO) @@ -178,6 +180,7 @@ def fall(oldpos: Vector2, newpos: Vector2) -> None: block_below = self.get(newpos + Vector2(0, 1)) if block_below == Tile.HERO: self.dead = True + self.hero.velocity = Vector2(0, 0) self.set(oldpos, Tile.EMPTY) self.set(newpos, Tile.ROCK) nonlocal new_fall @@ -212,6 +215,8 @@ def fall(oldpos: Vector2, newpos: Vector2) -> None: self.set(self.hero.position, Tile.EMPTY) + self.do_move() + def die(self) -> None: self.die_sound.play() self.game_surface.blit( @@ -242,6 +247,9 @@ def show_status(self) -> None: def finished(self) -> bool: return self.diamonds == 0 or self.dead + def start_play(self) -> None: + self.physics_frame = 0 + def stop_play(self) -> None: self.reset_falling() if self.dead: