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 15, 2025
1 parent 4e9328e commit ab5d256
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions wincoll/wincoll_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,20 @@ 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
return velocity.y == 0 and self.get(new_rockpos) == Tile.EMPTY
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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ab5d256

Please sign in to comment.