Skip to content

Lesson 13 — Add collectible effects ​

Where this lesson fits: levels now have configurable threats. Add pickups as a lifecycle—spawn, remain available, collect, apply, expire, and reset—not as a rendering-only object.

Time: 2–3 hours

Prerequisites and outcomes ​

Complete lesson 12. By the end, you can follow one powerup end to end and identify which effects belong to a level, a run, or an immediate player change.

Prepare and run ​

  1. From your learner project's solution folder, follow tutorial chapter 11 steps 1–5.
  2. Open Source\Systems\PowerupSystem.cs and find ApplyPowerup in Source\Game\LastPerimeterApp.cs. Run the focused command below.
  3. Run dotnet run --project Platforms\DesktopVK and use the tutorial's checkpoint to observe spawning, collection, and effects.
  4. Stage note: persisted collection statistics arrive with ProfileTracker in tutorial chapter 12. Inspect the final app separately or return to statistics in lesson 16.

Code anchors ​

  • last-perimeter/Source/Systems/PowerupSystem.cs
  • last-perimeter/Source/Entities/Powerup.cs
  • last-perimeter/Source/Data/Enums.cs
  • last-perimeter/Source/Game/LastPerimeterApp.cs (UpdateGameplay, ApplyPowerup)
  • last-perimeter/Tests/Systems/PowerupSystemTests.cs

Guided operations ​

  1. Trace the spawn timer and the maximum active count. Inspect why spawning uses the current wall path.
  2. Follow lifetime updates and collection overlap. Confirm collected or expired powerups leave the active list.
  3. Trace each effect into its owning value: shield charges, freeze duration, extra life, fuse reset, or double-points duration.
  4. Follow the collection event into audio, HUD, and level reset. Separate the effect's behavior from its visual cue; follow profile statistics after lesson 14.
  5. Run the focused powerup tests and verify one effect in play.
powershell
dotnet test --filter FullyQualifiedName~PowerupSystemTests

Checkpoint ​

A pickup cannot be collected twice, effects expire or are consumed according to their rules, and a new level clears only the effects that are level-scoped.

Common mistakes ​

  • Spawning on a stale path after a capture.
  • Removing an item visually but leaving it collectible in the model.
  • Giving every effect the same lifetime/reset behavior without checking its owner.

Questions and extension ​

How could a deterministic test validate a pickup's location without depending on random output? Inject or control the random source rather than asserting against an arbitrary seed.