Appearance
Lesson 09 — Add threats and recovery
Where this lesson fits: claiming works, but there is no moving threat. Add enemy movement and make collision consequences fair, explicit, and recoverable.
Time: 4–6 hours
Prerequisites and outcomes
Complete lessons 05–08. By the end, you can distinguish enemy occupancy, player collision, trail collision, shield consumption, death, respawn, and grace.
Prepare and run
- From your learner project's solution folder, follow tutorial chapter 07 steps 1–9.
- Open
Source\Systems\EnemySystem.cs,CollisionSystem.cs, and the corresponding tests. Run the focused commands below. - Run
dotnet run --project Platforms\DesktopVKand follow the tutorial's checkpoint for wall safety, trail contact, death, and respawn. - Stage note: shields and powerups arrive in tutorial chapter 11 / LP3 lesson 13; enemy variants first appear in play in tutorial chapter 10. Inspect their code now but verify them when those stages are reached.
Code anchors
last-perimeter/Source/Systems/EnemySystem.cslast-perimeter/Source/Systems/CollisionSystem.cslast-perimeter/Source/Entities/Enemy.cslast-perimeter/Source/Game/LastPerimeterApp.cs(UpdateEnemies,HandlePlayerDeath)last-perimeter/Tests/Systems/EnemySystemTests.cslast-perimeter/Tests/Systems/CollisionSystemTests.cs
Guided operations
- Trace enemy retargeting and movement. Find the pressure target and confirm it is supplied only while a trail is active.
- Follow the occupancy probes and axis reflection. Verify enemies stay in unclaimed space.
- Test player-enemy and enemy-trail predicates separately. Notice that the player is safe on the wall under the current collision rules.
- Trace a death event to life loss, then to the selected safe wall-path node and respawn grace timer. Revisit shield consumption in lesson 13.
- Inspect enemy variants and temporary splitter clones as parameterized behavior/lifetime, not unrelated duplicated update loops.
- Run the enemy and collision suites. For an orchestration change, add an app-level test or a reproducible manual scenario.
powershell
dotnet test --filter FullyQualifiedName~EnemySystemTests
dotnet test --filter FullyQualifiedName~CollisionSystemTestsCheckpoint
An enemy can threaten an exposed trail, but does not escape into claimed ground. A hit follows the life/respawn path and the player cannot immediately lose the newly respawned life during grace. Check shields in lesson 13.
Common mistakes
- Treating wall contact and trail contact as the same collision.
- Removing an enemy before its index in a claim result is safely applied.
- Allowing an enemy that is frozen to continue timers or split behavior unintentionally.
Questions and extension
Which fairness rules are enforced by geometry, which by timing, and which by feedback? Sparx are not part of the current acceptance scope; treat them as a separate extension.

