Skip to content

Commit

Permalink
Adapt to simplified ChamberCourt main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Jan 16, 2025
1 parent 79ca527 commit ba0510c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions wincoll/wincoll_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,6 +166,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)
Expand All @@ -178,6 +183,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
Expand Down Expand Up @@ -212,6 +218,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(
Expand Down Expand Up @@ -242,6 +250,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:
Expand Down

0 comments on commit ba0510c

Please sign in to comment.