Debug view improvements, warp animation

* Add a visible frame one tile beyond the normal screen in debug mode.

* Fix the display of motion paths for mounted traps in debug mode.

* Add an animation for the warp trap.
This commit is contained in:
James Campbell
2026-07-22 11:56:21 -04:00
parent d84e4627c3
commit 59e4bcce1c
8 changed files with 249 additions and 41 deletions

View File

@@ -35,8 +35,10 @@ class Game:
# Size the window ONCE to fit the largest level, then never resize it —
# calling set_mode again mid-session recreates the window (it flickers /
# looks like it closes). Smaller levels are centred within it.
dims = [(lv.width, lv.height) for lv in map(Level, self.level_paths)]
# looks like it closes). Smaller levels are centred within it. The debug
# view reveals a margin of overscan around a level, so budget for it here
# (for any level that will be shown in debug) or it'd be clipped.
dims = [self._draw_size(lv) for lv in map(Level, self.level_paths)]
self.win_w = max(max(w for w, _ in dims), MIN_W)
self.win_h = max(h for _, h in dims) + HUD_H
self.screen = pygame.display.set_mode((self.win_w, self.win_h))
@@ -44,16 +46,34 @@ class Game:
self._load_current()
# --- level management ----------------------------------------------------
def _debug_margin(self, level):
"""Pixels of overscan drawn around a level in the debug view (0 if it
won't be shown in debug)."""
if not (self.force_debug or level.debug):
return 0
return S.DEBUG_VIEW_MARGIN * level.tile
def _draw_size(self, level):
"""The pixel size the level's play surface occupies, including any debug
overscan margin on both sides."""
m = self._debug_margin(level)
return level.width + 2 * m, level.height + 2 * m
def _load_current(self):
self.level = Level(self.level_paths[self.index])
if self.force_debug:
self.level.debug = True # CLI flag overrides the per-level setting
self.player = Player(self.level)
self.battery = self.level.battery
self.world = pygame.Surface((self.level.width, self.level.height))
# In debug, grow the play surface by a margin and shift all drawing into
# it (render_offset) so geometry just off the map is visible.
m = self._debug_margin(self.level)
self.level.render_offset = (m, m)
world_w, world_h = self._draw_size(self.level)
self.world = pygame.Surface((world_w, world_h))
# Centre the play area in the fixed window, below the HUD.
ox = (self.win_w - self.level.width) // 2
oy = HUD_H + (self.win_h - HUD_H - self.level.height) // 2
ox = (self.win_w - world_w) // 2
oy = HUD_H + (self.win_h - HUD_H - world_h) // 2
self.world_pos = (ox, oy)
self.state = "playing"
self.death_timer = 0.0
@@ -238,7 +258,7 @@ class Game:
# The traps stay drawn in their moment-of-death state; the player is
# replaced by a corpse sprite where they fell.
sprite = self.assets.get("player_dead", self.death_rect.w, self.death_rect.h)
self.world.blit(sprite, self.death_rect)
self.world.blit(sprite, self.death_rect.move(self.level.render_offset))
else:
self.player.draw(self.world, self.assets)