Skip to content

Lesson 12 — Create levels from data ​

Where this lesson fits: the core loop has been tested. Replace one fixed setup with a level definition that supplies a coherent set of parameters to the runtime.

Time: 2–3 hours

Prerequisites and outcomes ​

Complete the core pass. By the end, you can explain the level-definition boundary and distinguish per-level reset from run state.

Prepare and run ​

  1. From your learner project's solution folder, follow tutorial chapter 10 steps 1–9.
  2. Open Source\Systems\LevelProgressionSystem.cs and the staged app's SetupLevel. Run the focused command below.
  3. Run dotnet run --project Platforms\DesktopVK and perform the level-transition observations in the tutorial's checkpoint.

Code anchors ​

  • last-perimeter/Source/Data/LevelDefinition.cs
  • last-perimeter/Source/Systems/LevelProgressionSystem.cs
  • last-perimeter/Source/Game/LastPerimeterApp.cs (SetupLevel, CreateEnemies)
  • last-perimeter/Tests/Systems/LevelProgressionSystemTests.cs

Guided operations ​

  1. Follow CreateLevel for a level number and difficulty preset. Record the values it returns: goal percentage, speed multiplier, enemy roster, and arena variation.
  2. Trace Initialize and the level-complete update into SetupLevel. Identify which objects are rebuilt and which session values survive. StartRun is introduced in tutorial chapter 12.
  3. Follow active configuration derivation from the base config. Explain why each level should start from base values instead of multiplying the previous level's result; run modifiers arrive in lesson 15.
  4. Trace creation of arena, wall path, enemies, and initial player position.
  5. Run the progression tests and compare two level definitions; verify only intended parameters change.
powershell
dotnet test --filter FullyQualifiedName~LevelProgressionSystemTests

Checkpoint ​

Level generation is reproducible from its inputs, setup resets level-scoped state, and the player's score and remaining lives carry forward. Profile persistence arrives in lesson 14.

Common mistakes ​

  • Incrementally mutating the previous level's configuration and compounding difficulty.
  • Forgetting to clear temporary powerups, fuse state, or pending upgrade choices.
  • Putting permanent statistics on the per-level arena.

Questions and extension ​

How should a new arena shape affect initial player placement and enemy placement? Write the invariants before implementing a new shape.