From ab5d2567ecd2c319d02ff2012d0136f6ca8a3895 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Mon, 13 Jan 2025 00:16:49 +0000 Subject: [PATCH] Adapt to simplified ChamberCourt main loop --- wincoll/wincoll_game.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/wincoll/wincoll_game.py b/wincoll/wincoll_game.py index 1f9eb5b..75c3498 100644 --- a/wincoll/wincoll_game.py +++ b/wincoll/wincoll_game.py @@ -127,14 +127,11 @@ def unlock(self) -> None: UNLOCK_SOUND.play() def can_move(self, velocity: Vector2) -> bool: + if not super().can_move(velocity): + return False 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 @@ -142,6 +139,8 @@ def can_move(self, velocity: Vector2) -> bool: return False def do_move(self) -> None: + if self.hero.velocity == Vector2(0, 0): + return newpos = self.hero.position + self.hero.velocity block = self.get(newpos) if block == Tile.DIAMOND: @@ -169,6 +168,14 @@ 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 == 1: + self.physics_frame = 0 + if self.physics_frame != 0: + return + self.do_physics() + def do_physics(self) -> None: # Put Win into the map data for collision detection. self.set(self.hero.position, Tile.HERO) @@ -212,6 +219,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 +251,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: