Skip to content

Chapter 10 - Level Progression, Difficulty Curves, and New Arenas ​

Where this chapter fits: the first chapter of the advanced track. One solid level becomes a campaign. Levels are data, the difficulty curve is four small formulas, and one method sets up every level and decides what resets and what carries over. The level data also brings the enemy variants from chapter 07 into play, with a Hunter from level 4 and a Splitter from level 7.

Time: [TODO Simon: time estimate for chapter 10]

Chapter 10: the HUD now shows LEVEL:1 and GOAL:75%, and the status line names the level

The chapter 10 build at the start of level 1. The staged HUD gained the LEVEL readout, and GOAL now comes from the level definition rather than the config.

Prerequisites ​

Chapters 01-09, which give the complete single-level game: arena, wall path, trails, capture, enemies, scoring, HUD and tests.

Learning objectives ​

By the end of this chapter you should be able to:

  1. express a level as immutable data (LevelDefinition) instead of hard-coded special cases,
  2. implement a deterministic difficulty curve that scales enemy count, speed, and claim goal from a level number, and read the curve off a chart,
  3. apply a difficulty preset (Chill / Classic / Hardcore) as a final adjustment layer over the base curve,
  4. vary arena geometry safely with pre-claimed insets while keeping one authoritative claim-state model,
  5. trace SetupLevel and say which state it resets and which it preserves,
  6. schedule variant introductions through level data instead of code branches,
  7. manage Splitter clones in the app loop (remove the expired, collect the new, add them after the loop) without changing the list while iterating it,
  8. verify progression rules with unit tests rather than playtesting alone, and pass the chapter's 50 tests.

Code anchors ​

  • Source/Systems/LevelProgressionSystem.cs (the difficulty curve, CreateLevel)
  • Source/Data/LevelDefinition.cs (the per-level data record)
  • Source/Data/GameSession.cs (staged: Level, CurrentLevelDefinition, Difficulty)
  • Source/Data/GameConfig.cs (the base config that each level rewrites: EnemySpeed, WinClaimPercentage)
  • Source/Rendering/HudRenderer.cs (staged: LEVEL and GOAL readouts)
  • Source/Game/LastPerimeterApp.cs (chapter 10 staged version: SetupLevel, CreateEnemies, UpdateEnemies, ApplyArenaInsetClaim)
  • Source/Systems/EnemySystem.cs (TrySpawnSplitterClone and SplitterFirstSplitDelaySeconds, explained in chapter 07 and first called here)
  • Tests/Systems/LevelProgressionSystemTests.cs

The key lesson ​

Do not add "more levels" as hard-coded special cases, but treat levels as data plus rules. Decide what changes, when it changes, how that change stays fair, and how the player reads the escalation.

What a level should own ​

A level definition should describe arena shape, claim target, enemy roster, and speed modifiers. In this codebase that is the LevelDefinition record:

csharp
public sealed record LevelDefinition(
    int Number,
    string Name,
    float RequiredClaimPercentage,
    float EnemySpeedMultiplier,
    IReadOnlyList<EnemyVariant> EnemyVariants,
    int PreclaimedInsetTiles = 0);

Because it is an immutable record, a level cannot drift while it is being played. Everything mutable lives in GameSession instead. That separation keeps progression understandable and easy to author.

Difficulty curve as system design ​

Change only a few variables at once. Add one new threat, strengthen one known threat, change one pacing rule, and reward the player for adapting. That is easier to learn and fairer than spiking every variable together.

Four charts over levels 1 to 12: enemy count steps up every three levels, speed rises 10% per level, the claim goal rises 1% per level, and pre-claimed inset tiles first appear at level 6

How this codebase does it ​

LevelProgressionSystem.CreateLevel derives every dial from the level number with small, readable formulas, then layers the difficulty preset on top:

csharp
public LevelDefinition CreateLevel(int levelNumber, DifficultyPreset difficulty)
{
    int enemyCount = Math.Min(1 + ((levelNumber - 1) / 3), 4);
    float speedMultiplier = 1f + ((levelNumber - 1) * 0.1f);
    float requiredClaim = Math.Min(75f + (levelNumber - 1), 90f);
    int insetTiles = levelNumber >= 5 ? Math.Min((levelNumber - 4) / 2, 3) : 0;

    List<EnemyVariant> variants = new();
    for (int index = 0; index < enemyCount; index++)
    {
        variants.Add(index switch
        {
            1 when levelNumber >= 4 => EnemyVariant.Hunter,
            2 when levelNumber >= 7 => EnemyVariant.Splitter,
            3 when levelNumber >= 10 => EnemyVariant.Hunter,
            _ => EnemyVariant.Wanderer,
        });
    }

    (requiredClaim, speedMultiplier) = difficulty switch
    {
        DifficultyPreset.Chill => (Math.Max(70f, requiredClaim - 5f), speedMultiplier * 0.9f),
        DifficultyPreset.Hardcore => (Math.Min(90f, requiredClaim + 5f), speedMultiplier * 1.15f),
        _ => (requiredClaim, speedMultiplier),
    };

    return new LevelDefinition(levelNumber, $"LEVEL {levelNumber}", requiredClaim, speedMultiplier, variants, insetTiles);
}

Read the curve aloud. A new enemy arrives every three levels, capped at four. Enemy speed rises 10% per level. The claim goal rises 1% per level, capped at 90%. An inset ring switches on at level 5 in the formula, but it only becomes non-zero at level 6, because of integer division: (5 - 4) / 2 = 0. Each formula is one lever, clamped and testable.

NOTE

The speed multiplier is additive: every level adds 0.1 to it. The base enemy speed is 90 px/s and you move at 150 px/s. On Classic, level 8 (1.7x, 153 px/s) is therefore the first level where a Wanderer is faster than you, and level 12 reaches 2.1x, which is 189 px/s.

On Classic the first twelve levels look like this:

LevelEnemiesRosterSpeedGoalInset tiles
1-31Wanderer1.0x, 1.1x, 1.2x75%, 76%, 77%0
4-52Wanderer, Hunter1.3x, 1.4x78%, 79%0
62Wanderer, Hunter1.5x80%1
73Wanderer, Hunter, Splitter1.6x81%1
8-93Wanderer, Hunter, Splitter1.7x, 1.8x82%, 83%2
10-124Wanderer, Hunter, Splitter, Hunter1.9x, 2.0x, 2.1x84%, 85%, 86%3

Presets adjust the result afterwards. Chill takes 5 off the goal with a floor of 70 and multiplies speed by 0.9. Hardcore adds 5 to the goal with a ceiling of 90 and multiplies speed by 1.15. Lives are a per-run resource, not a per-level one. The chapter 10 app sets 3 lives once in Initialize. LevelProgressionSystem.GetStartingLives already returns 4, 3 or 2 by preset in this chapter, and it has a test, but the first call to it is in StartRun in chapter 12.

Arena variety without breaking the core ​

A ring of pre-claimed tiles around the arena; the wall path now runs along the inner edge of the ring

LevelDefinition.PreclaimedInsetTiles shrinks the open play area without touching the capture solver. The app pre-claims a border of tiles, then rebuilds the wall path so the player walks the new, smaller outline:

csharp
PlayableWallPath initialPath = _wallSystem.RebuildPlayablePath(_arenaSystem);
if (levelDefinition.PreclaimedInsetTiles > 0)
{
    ApplyArenaInsetClaim(levelDefinition.PreclaimedInsetTiles);
    initialPath = _wallSystem.RebuildPlayablePath(_arenaSystem);
}

ApplyArenaInsetClaim builds a captured Region for the border tiles and pushes it through the normal ArenaSystem.ApplyClaimResult pipeline. Player captures use the same single source of truth:

csharp
private void ApplyArenaInsetClaim(int insetTiles)
{
    Region captured = new();
    Region remaining = new();
    for (int x = 0; x < _arenaSystem.GridWidth; x++)
    {
        for (int y = 0; y < _arenaSystem.GridHeight; y++)
        {
            Point tile = new(x, y);
            if (x < insetTiles || y < insetTiles || x >= _arenaSystem.GridWidth - insetTiles || y >= _arenaSystem.GridHeight - insetTiles)
            {
                captured.Tiles.Add(tile);
            }
            else
            {
                remaining.Tiles.Add(tile);
            }
        }
    }

    _arenaSystem.ApplyClaimResult(new ClaimResult(captured, remaining, []));
}

The lesson is that the capture system keeps one authoritative grid, used for both the playable space and claim solving, even when levels reshape the arena. A one-tile ring is only 4 px wide, so it reads as a thin claimed border rather than a new shape. Widening TileSize or the ring is the obvious variation to try.

NOTE

The ring makes the arena tighter, but it also gives you a head start. It goes through ApplyClaimResult, and GetClaimedPercentage divides the claimed tiles by ALL 31,878 tiles, so the ring counts toward the goal. A one-tile ring is 734 tiles (2.3%), a two-tile ring is 1,460 (4.6%) and a three-tile ring is 2,178 (6.8%). Level 6 therefore starts at 2.3% claimed, level 8 at 4.6% and level 10 at 6.8%, which roughly cancels the 1% per level rise in the goal.

Level 6: a thin pre-claimed border runs around the arena, the HUD reads LEVEL:6 and GOAL:80%, and two enemies roam

Level 6 with its one-tile inset ring and the Wanderer-plus-Hunter roster. This frame was captured through the chapter 12 build's level select, because the chapter 10 build always starts at level 1; the level itself is identical.

Transition design ​

A level transition should do more than increment a number. SetupLevel is the single method that turns a level number into a running level:

What is not reset is the point. Score, HighScore and Player.Lives live on GameSession and survive the call. The line between "reset" and "preserve" is the boundary between in-level state and run state, which chapter 13 formalises. In the chapter 10 staged app _activeConfig is derived from the base config with a with expression. Every level therefore starts from the same defaults plus its own multipliers:

csharp
_activeConfig = _config with
{
    EnemySpeed = _config.EnemySpeed * levelDefinition.EnemySpeedMultiplier,
    WinClaimPercentage = levelDefinition.RequiredClaimPercentage,
};

Enemies are spread across the arena width and alternate above and below the centre line, so a four-enemy level never starts with a pile:

csharp
private IEnumerable<Enemy> CreateEnemies(LevelDefinition levelDefinition)
{
    int count = levelDefinition.EnemyVariants.Count;
    for (int index = 0; index < count; index++)
    {
        float horizontalFactor = (index + 1f) / (count + 1f);
        Vector2 position = new(
            _arenaSystem.Bounds.Left + (_arenaSystem.Bounds.Width * horizontalFactor),
            _arenaSystem.Bounds.Center.Y + ((index % 2 == 0 ? -1 : 1) * 40f));
        Vector2 velocity = Vector2.Normalize(new Vector2(index % 2 == 0 ? 1f : -1f, 0.7f + (index * 0.15f))) * _activeConfig.EnemySpeed;

        yield return new Enemy
        {
            Position = position,
            Velocity = velocity,
            Variant = levelDefinition.EnemyVariants[index],
            VariantTimer = levelDefinition.EnemyVariants[index] == EnemyVariant.Splitter ? EnemySystem.SplitterFirstSplitDelaySeconds : 0f,
        };
    }
}

Each enemy takes its variant from the level definition. The last property gives a Splitter its first split timer, 6 s (EnemySystem.SplitterFirstSplitDelaySeconds), and leaves the timer at zero for the other variants. Chapter 07 explains the variants and the Splitter's rules.

Build it step by step ​

This chapter is copy-along. Step 1 copies the chapter's files from the snapshot, and the steps after it walk through what changed and why.

Step 1 - Copy the chapter files ​

From your LastPerimeter folder, copy the Source and Tests folders from this chapter's snapshot over your own. The command creates any folders you do not have yet and overwrites the files that changed. Replace <course-repo> with the path to your copy of the course repository (the course index explains how to get it).

In PowerShell:

powershell
Copy-Item -Recurse -Force "<course-repo>/DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas/Source", "<course-repo>/DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas/Tests" .

In bash:

bash
cp -R "<course-repo>/DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas/Source" "<course-repo>/DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas/Tests" .

That copy brings in these files. The listings in this chapter show the parts worth studying, not every line.

New files:

  • Source/Data/LevelDefinition.cs
  • Source/Systems/LevelProgressionSystem.cs
  • Tests/Systems/LevelProgressionSystemTests.cs

Replaced files:

  • Source/Data/GameSession.cs
  • Source/Game/LastPerimeterApp.cs
  • Source/Rendering/HudRenderer.cs

The staged GameSession adds CurrentLevelDefinition, Difficulty and Level. The staged HudRenderer adds LEVEL: and reads GOAL: from CurrentLevelDefinition.

NOTE

Every step after this one describes code that is already in the files you just copied. Open the file each step names and read along. You type nothing unless a step says so.

Step 2 - Initialize hands over to SetupLevel ​

Open Source/Game/LastPerimeterApp.cs. The app gains the _activeConfig field and a LevelProgressionSystem. Initialize no longer builds the arena itself. It creates the session with Lives = 3 and an empty path, then calls SetupLevel(1).

Step 3 - Per-level construction: SetupLevel ​

Open Source/Game/LastPerimeterApp.cs and read the SetupLevel method from top to bottom. All per-level construction now lives there, in the order of the flowchart in "Transition design" above. CreateEnemies and ApplyArenaInsetClaim sit beside it in the same file.

Step 4 - The roster in the status line: SetupLevel ​

Open Source/Game/LastPerimeterApp.cs and find SetupLevel. It names the roster in the status message, so the player can read the encounter before it starts. Level 7 reads LEVEL 7: WANDERER / HUNTER / SPLITTER:

csharp
_gameSession.StatusMessage = $"{levelDefinition.Name}: {string.Join(" / ", levelDefinition.EnemyVariants).ToUpperInvariant()}";

Step 5 - The Splitter's first timer: CreateEnemies ​

Open Source/Game/LastPerimeterApp.cs and find CreateEnemies (the listing in "Transition design" above). It gives each enemy its variant from the level definition, and gives Splitters their first timer: VariantTimer = levelDefinition.EnemyVariants[index] == EnemyVariant.Splitter ? EnemySystem.SplitterFirstSplitDelaySeconds : 0f.

Step 6 - The clone loop: UpdateEnemies ​

Open Source/Game/LastPerimeterApp.cs and find UpdateEnemies. It is the enemy loop from the chapter 07 Update, moved into its own method and called from Update. It walks the list backwards, so it can remove expired clones while iterating. It asks EnemySystem.TrySpawnSplitterClone for a clone (chapter 07 explains that method) and collects new clones to add after the loop:

csharp
private void UpdateEnemies(float deltaTime)
{
    // ... returns early if a system is not ready
    Vector2? pressureTarget = _trailSystem.HasActiveTrail ? _gameSession.Player.Position : null;
    List<Enemy> spawnedClones = [];
    for (int index = _gameSession.Enemies.Count - 1; index >= 0; index--)
    {
        Enemy enemy = _gameSession.Enemies[index];
        bool alive = _enemySystem.Update(enemy, _arenaSystem, deltaTime, _activeConfig.EnemyRetargetIntervalSeconds, pressureTarget);
        if (!alive)
        {
            _gameSession.Enemies.RemoveAt(index);
            continue;
        }

        Enemy? clone = _enemySystem.TrySpawnSplitterClone(enemy, deltaTime);
        if (clone is not null)
        {
            spawnedClones.Add(clone);
        }
    }

    _gameSession.Enemies.AddRange(spawnedClones);
}

Step 7 - Advance on level complete ​

Open Source/Game/LastPerimeterApp.cs and find Update. It freezes on GameOver. On LevelComplete it waits for confirm (Enter or Space) and then advances:

csharp
if (_gameSession.Status == GameStatus.LevelComplete)
{
    if (input.IsConfirmPressed)
    {
        SetupLevel(_gameSession.Level + 1);
    }

    base.Update(gameTime);
    return;
}

Step 8 - Read tuning from _activeConfig ​

Open Source/Game/LastPerimeterApp.cs. Everywhere the old code read _config.WinClaimPercentage, _config.EnemySpeed or _config.RespawnGraceSeconds, it now reads _activeConfig. The level bonus becomes CalculateLevelBonus(_gameSession.Level). The threshold bonus becomes CalculateThresholdBonus(_gameSession.ClaimedAreaPercentage, _activeConfig.WinClaimPercentage), so overshooting a harder goal pays the same per-percent rate.

Step 9 - Build, test, run ​

Run these commands from your LastPerimeter folder:

bash
dotnet build
dotnet test
dotnet run --project Platforms/DesktopVK

dotnet test reports 50 passing tests, including the new LevelProgressionSystemTests.

The last command opens the game window. Press Escape to close it.

Chapter snapshot ​

The buildable project for this chapter lives at DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas (regenerable via scripts/chapter-manifest.json). Compared with chapter 09 (which shares the chapter 08 build), this snapshot adds LevelProgressionSystem.cs, LevelDefinition.cs and LevelProgressionSystemTests.cs. It also has a staged app that gains the SetupLevel multi-level flow, variant rosters taken from the level data, the Splitter clone loop in UpdateEnemies and the roster in the status line. The staged HUD gains LEVEL: and GOAL: readouts. In the staged app, Draw still calls _claimedAreaRenderer.Prepare() before GraphicsDevice.Clear, as in chapter 08.

bash
cd "<course-repo>/DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas"
dotnet build
dotnet test

The new test file is Tests/Systems/LevelProgressionSystemTests.cs. It holds CreateLevel_ScalesEnemyRosterAndGoal, CreateLevel_AppliesDifficultyPresetAdjustments and GetStartingLives_DependsOnDifficulty, which runs three cases. The suite passes 50 tests at this point in the course.

Checkpoint ​

Level 7 in play: a Wanderer, a Hunter, a Splitter, and one of the Splitter's short-lived clones share the arena

Level 7 with all three variants on screen plus a clone. Hunters are tinted toward red and Splitters toward violet by EnemyRenderer. This frame was captured through the chapter 12 build's level select; the level itself is identical.

  1. In your LastPerimeter folder, run dotnet test. 50 tests pass. If your count differs, run the same command in <course-repo>/DOCUMENTATION/LastPerimeter-Source/10-Level-Progression-Difficulty-Curves-And-New-Arenas/ and compare.
  2. Without running the game, predict from CreateLevel what level 7 on Classic looks like (enemy count, roster, claim goal, speed multiplier, inset tiles). Then check the table above and CreateLevel_ScalesEnemyRosterAndGoal.
  3. Run the game with dotnet run --project Platforms/DesktopVK. Clear level 1 by claiming 75% of the arena with the arrow keys (the Controls table in chapter 03 lists every input), then press Enter. The HUD reads LEVEL:2 and GOAL:76%, and your score and lives carry over.
  4. The pre-claimed border first appears at level 6. To see it without clearing five levels, open Source/Game/LastPerimeterApp.cs, find Initialize, and change SetupLevel(1); to SetupLevel(6);. Run the game. The HUD reads LEVEL:6 and GOAL:80%, a thin claimed border runs around the arena and two enemies roam, as in the image captioned "Level 6 with its one-tile inset ring" earlier in this chapter. Then change the line back to SetupLevel(1);.
  5. Now see the variants. Open Source/Game/LastPerimeterApp.cs, find Initialize, and change SetupLevel(1); to SetupLevel(7);. This is a temporary edit. Run the game with dotnet run --project Platforms/DesktopVK. The status line reads LEVEL 7: WANDERER / HUNTER / SPLITTER, as in the screenshot above.
  6. Stay on the wall and watch. The arrow keys move you along it (the Controls table in chapter 03 lists every input). About 6 s after the level starts, the Splitter (violet-tinted, shorter arms) emits a smaller clone. The clone vanishes about 5 s later, a new one appears every 8 s, and the enemy count never grows without bound.
  7. Press the arrow key that points into the arena to start drawing. The Hunter (red-tinted) visibly cuts toward you, but only while you are drawing. Return to the wall and it goes back to wandering.
  8. Press Escape to close the game. Open Source/Systems/EnemySystem.cs and change HunterPursuitWeight from 0.7f to 0.9f. Run the game again, draw, and explain why it stops feeling fair.
  9. Press Escape to close the game and undo both edits: HunterPursuitWeight back to 0.7f, and SetupLevel(7); back to SetupLevel(1);. Run dotnet test and confirm 50 tests pass.
  10. Open Source/Systems/LevelProgressionSystem.cs, find CreateLevel, and change the insetTiles line to int insetTiles = levelNumber >= 2 ? 2 : 0;. Run the game, clear level 1, press Enter, and watch the wall path start on the inner outline of level 2. Then restore the original line, int insetTiles = levelNumber >= 5 ? Math.Min((levelNumber - 4) / 2, 3) : 0;, and run dotnet test to confirm 50 tests pass.

What you should have now ​

You now have:

  • a reusable level-definition format (LevelDefinition),
  • a level-start pipeline (SetupLevel),
  • level-complete bonus calculation (ScoringSystem.CalculateLevelBonus and CalculateThresholdBonus),
  • a formula-driven difficulty curve with three presets (LevelProgressionSystem.CreateLevel),
  • a pre-claimed inset ring from level 6 (ApplyArenaInsetClaim),
  • variant rosters scheduled by level data (a Hunter from level 4, a Splitter from level 7), with the roster named in the status line,
  • Splitter clones in play, spawned and removed by UpdateEnemies.

Common mistakes ​

  • resetting lives or score inside SetupLevel,
  • reading tuning from the base config after the level rewrote it in _activeConfig,
  • reusing the old ClaimedAreaRenderer with a new ArenaSystem (its render target belongs to the old arena),
  • special-casing level numbers in gameplay code instead of in the level factory,
  • adding to _gameSession.Enemies while iterating it (collect the clones, then add them after the loop).

Extensions ​

Compare these approaches:

  1. handcrafted level sequences,
  2. parameter-driven level generation (the approach LevelProgressionSystem takes),
  3. hybrid campaigns where authored milestone levels are mixed with generated in-between levels.

Then try to:

  1. measure the claim goal over the tiles that were open at level start, so the pre-claimed ring is pure pressure and no longer a head start,
  2. author and playtest a difficulty curve of your own for at least ten levels,
  3. add new arena presets beyond the opening rectangle (start from ApplyArenaInsetClaim).