Update all 13 tutorial scripts to current enum-based API, refs #167

All tutorial parts (1-13) used the old string-based key/action
comparison API removed in 6d5e99a. Every handle_keys function now
uses mcrfpy.Key.* and mcrfpy.InputState.PRESSED enums.

Additional fixes across all parts:
- Replace manual FOV computation with ColorLayer.draw_fov() which
  handles FOV calculation and explored-state tracking in one call
- Replace old grid.add_layer("color") with ColorLayer() constructor
- Fix entity removal bug: entities.remove(index) -> remove(entity_ref)
- Remove manual exploration tracking (draw_fov handles it internally)
- Use tuple positions for compute_fov/is_in_fov: (x, y) not x, y

All 14 parts (0-13) tested and passing in headless mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-04-09 23:23:35 -04:00
commit 1805b985bd
13 changed files with 388 additions and 765 deletions

View file

@ -160,9 +160,9 @@ scene.children.append(status_display)
# Input Handling
# =============================================================================
def handle_keys(key: str, action: str) -> None:
def handle_keys(key, action) -> None:
"""Handle keyboard input with collision detection."""
if action != "start":
if action != mcrfpy.InputState.PRESSED:
return
# Get current position
@ -171,15 +171,15 @@ def handle_keys(key: str, action: str) -> None:
# Calculate intended new position
new_x, new_y = px, py
if key == "W" or key == "Up":
if key == mcrfpy.Key.W or key == mcrfpy.Key.UP:
new_y -= 1
elif key == "S" or key == "Down":
elif key == mcrfpy.Key.S or key == mcrfpy.Key.DOWN:
new_y += 1
elif key == "A" or key == "Left":
elif key == mcrfpy.Key.A or key == mcrfpy.Key.LEFT:
new_x -= 1
elif key == "D" or key == "Right":
elif key == mcrfpy.Key.D or key == mcrfpy.Key.RIGHT:
new_x += 1
elif key == "Escape":
elif key == mcrfpy.Key.ESCAPE:
mcrfpy.exit()
return
else: