Skip to content

engine: composite moves blocked by solid tiles (olive-empire obstacles) - #92

Closed
ffex wants to merge 2 commits into
refactir-olive-empirefrom
olive-empire-blocked-moves
Closed

ffex wants to merge 2 commits into
refactir-olive-empirefrom
olive-empire-blocked-moves

Conversation

@ffex

@ffex ffex commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Summary

The olive-empire example needs obstacles: olive trees the player cannot walk through. The library could tell whether a screen pixel is on a solid tile (TileCollision::at_screen_pixel), but it had no way to cancel a move before the player steps on one, and no public way to get a background tile's ID. This PR adds blocked composite moves with a hitbox, and registers olive-empire as an example so the test suite is green again.

What changed

  • src/engine/tile_collision.rs: TileCollision::when_free(points, body) runs body only when none of the screen pixels is on a solid tile (it stops at the first solid one; no points or no solid tiles: just body). New Hitbox (a rectangle of a sprite, e.g. a character's feet). at_screen_pixel emits the same code as before.
  • src/engine/sprites.rs: SpriteManager::move_composite_{left,right,up,down}_blocked(id, distance, limit, &solid, hitbox) do what the _limit moves do, unless the hitbox would step on a solid tile. They read the lines 1 and distance pixels ahead of the hitbox, every 8 pixels along its edge and at its last pixel, so no 8x8 tile is skipped (distance in 1..=8, checked).
  • src/engine/tiles.rs: TileManager::background_tile_index(id), the tile ID of background tiles ($9000 addressing) for tilemaps and collision sets.
  • src/engine/mod.rs, src/prelude.rs: export Hitbox.
  • olive-empire registered as an example (tests/support/examples.rs, tests/report.rs, tests/snapshots.rs, scripts/assemble-examples.sh, CLAUDE.md) with its snapshot examples/olive-empire/main.asm: every_example_has_a_snapshot_test was failing on the base branch.
  • Task.md, CONTEXT.md, CHANGELOG.md: the new API and the example.

Tasks closed

  • Task.md Phase 3: "Blocked moves against solid tiles" (new item, found writing olive-empire).

How it was verified

  • cargo fmt --check: ok
  • cargo clippy --all-targets -- -D warnings: ok
  • cargo test: ok (472 lib tests, all integration tests); cargo +1.85 test: ok
  • scripts/assemble-examples.sh: all 8 examples assemble and link (RGBDS)
  • RGBDS_LINK_CHECK=1 GB_TEST_ROMS=<dir> cargo test --lib --test emulator: ok (115 tests)
  • New tests: blocked_composite_moves_stop_the_hitbox_against_solid_tiles (emulator: a 16x16 player with a feet hitbox stops touching a solid tile in all four directions, its head overlapping the tile row when walking up; it fails with an empty solid set), unit tests for the pixels read, the panics, the empty-set case, when_free's code and background_tile_index.

Generated-asm impact

  • New snapshot examples/olive-empire/main.asm (the example as it is on the base branch). No other example changes.

Risks and follow-ups

  • Additive API, no breaking change.
  • A step cut short by the screen limit is still checked for the whole distance; with distance > 1 the composite stops up to distance - 1 pixels before an obstacle (documented).
  • The checks read VRAM: they must run while it is accessible (input bindings run at the start of the main loop, in VBlank).
  • Next on the base branch: the olive trees in the olive-empire map.

Independent review

  • None: written in pair-programming mode with the maintainer, who asked for the merge.

How to review

  • src/engine/tile_collision.rs (when_free), then blocked_points in src/engine/sprites.rs, then the emulator test at the end of tests/emulator.rs.

🤖 Generated with Claude Code

ffex and others added 2 commits October 22, 2026 17:13
SpriteManager::move_composite_{left,right,up,down}_blocked move a composite
as the limited moves do unless its Hitbox would step on a solid background
tile, read with the new TileCollision::when_free. TileManager::
background_tile_index gives a background tile's ID for maps and collision
sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests require every binary in src/bin to have a snapshot test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ffex

ffex commented Oct 30, 2026

Copy link
Copy Markdown
Owner Author

Already in develop (10d97fd); closing.

@ffex ffex closed this Oct 30, 2026
@ffex
ffex deleted the olive-empire-blocked-moves branch October 30, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant