Skip to content

Lesson 05 — Construct and validate a trail ​

Where this lesson fits: walking is constrained to a path. This lesson introduces the temporary geometry that begins when the player leaves safety and ends only at a valid reconnect or loop.

Time: 3–4 hours

Prerequisites and outcomes ​

Complete lessons 02–04. By the end, you can trace the trail lifecycle and identify which movement candidates may be appended, rejected, or used to complete it.

Prepare and run ​

  1. From your learner project's solution folder, follow tutorial chapter 05 steps 1–5.
  2. Open Source\Systems\TrailSystem.cs and the named test files, run the focused commands below, then follow the tutorial's checkpoint.
  3. Stage note: slow-draw input, scoring, and TrailSlowDrawTests are wired into the staged app in tutorial chapter 08 / LP3 lesson 10. Here inspect the TrailSystem slow-draw API, not an already playable slow-draw feature.

Code anchors ​

  • last-perimeter/Source/Entities/Trail.cs
  • last-perimeter/Source/Systems/TrailSystem.cs
  • last-perimeter/Source/Rendering/TrailRenderer.cs
  • last-perimeter/Tests/Systems/TrailSystemTests.cs
  • last-perimeter/Tests/Systems/TrailLoopTests.cs

Guided operations ​

  1. Follow TryStart: identify the snapped wall anchor and first interior point.
  2. Follow CanAdvance before AppendPoint; explain why invalid movement must not alter player position or trail points.
  3. Follow completion on the playable path and loop completion at a self-intersection. Note the minimum trail-length rule.
  4. Follow cancel/reset behavior and identify which state is cleared by SetupLevel.
  5. In TrailSystem.TryStart and UpdateSlowDraw, inspect slow-draw state: it starts from the supplied flag and is permanently demoted for that trail when the input is released. The staged app does not supply that input until chapter 08.
  6. Run trail-system and loop tests; then inspect the trail renderer to confirm it draws model points rather than creating geometry rules.
powershell
dotnet test --filter FullyQualifiedName~TrailSystemTests
dotnet test --filter FullyQualifiedName~TrailLoopTests

Checkpoint ​

A trail cannot start detached from a path, cannot advance into invalid cells, and has an explicit completed or cancelled outcome. A loop uses the intersection as its endpoint.

Common mistakes ​

  • Treating every candidate movement as accepted before validation.
  • Completing from an unsnapped point and leaving a visible or logical gap.
  • Reading the slow-draw button only on the completion frame.

Questions and extension ​

What should happen to the player when a loop closes but the solver finds no partition? Trace the recovery path before proposing a change.