Appearance
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]
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:
- express a level as immutable data (
LevelDefinition) instead of hard-coded special cases, - implement a deterministic difficulty curve that scales enemy count, speed, and claim goal from a level number, and read the curve off a chart,
- apply a difficulty preset (
Chill/Classic/Hardcore) as a final adjustment layer over the base curve, - vary arena geometry safely with pre-claimed insets while keeping one authoritative claim-state model,
- trace
SetupLeveland say which state it resets and which it preserves, - schedule variant introductions through level data instead of code branches,
- 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,
- 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:LEVELandGOALreadouts)Source/Game/LastPerimeterApp.cs(chapter 10 staged version:SetupLevel,CreateEnemies,UpdateEnemies,ApplyArenaInsetClaim)Source/Systems/EnemySystem.cs(TrySpawnSplitterCloneandSplitterFirstSplitDelaySeconds, 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.
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:
| Level | Enemies | Roster | Speed | Goal | Inset tiles |
|---|---|---|---|---|---|
| 1-3 | 1 | Wanderer | 1.0x, 1.1x, 1.2x | 75%, 76%, 77% | 0 |
| 4-5 | 2 | Wanderer, Hunter | 1.3x, 1.4x | 78%, 79% | 0 |
| 6 | 2 | Wanderer, Hunter | 1.5x | 80% | 1 |
| 7 | 3 | Wanderer, Hunter, Splitter | 1.6x | 81% | 1 |
| 8-9 | 3 | Wanderer, Hunter, Splitter | 1.7x, 1.8x | 82%, 83% | 2 |
| 10-12 | 4 | Wanderer, Hunter, Splitter, Hunter | 1.9x, 2.0x, 2.1x | 84%, 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
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 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.csSource/Systems/LevelProgressionSystem.csTests/Systems/LevelProgressionSystemTests.cs
Replaced files:
Source/Data/GameSession.csSource/Game/LastPerimeterApp.csSource/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/DesktopVKdotnet 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 testThe 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 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.
- In your
LastPerimeterfolder, rundotnet 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. - Without running the game, predict from
CreateLevelwhat level 7 on Classic looks like (enemy count, roster, claim goal, speed multiplier, inset tiles). Then check the table above andCreateLevel_ScalesEnemyRosterAndGoal. - 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 readsLEVEL:2andGOAL:76%, and your score and lives carry over. - The pre-claimed border first appears at level 6. To see it without clearing five levels, open
Source/Game/LastPerimeterApp.cs, findInitialize, and changeSetupLevel(1);toSetupLevel(6);. Run the game. The HUD readsLEVEL:6andGOAL: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 toSetupLevel(1);. - Now see the variants. Open
Source/Game/LastPerimeterApp.cs, findInitialize, and changeSetupLevel(1);toSetupLevel(7);. This is a temporary edit. Run the game withdotnet run --project Platforms/DesktopVK. The status line readsLEVEL 7: WANDERER / HUNTER / SPLITTER, as in the screenshot above. - 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.
- 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.
- Press Escape to close the game. Open
Source/Systems/EnemySystem.csand changeHunterPursuitWeightfrom0.7fto0.9f. Run the game again, draw, and explain why it stops feeling fair. - Press Escape to close the game and undo both edits:
HunterPursuitWeightback to0.7f, andSetupLevel(7);back toSetupLevel(1);. Rundotnet testand confirm 50 tests pass. - Open
Source/Systems/LevelProgressionSystem.cs, findCreateLevel, and change theinsetTilesline toint 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 rundotnet testto 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.CalculateLevelBonusandCalculateThresholdBonus), - 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
ClaimedAreaRendererwith a newArenaSystem(its render target belongs to the old arena), - special-casing level numbers in gameplay code instead of in the level factory,
- adding to
_gameSession.Enemieswhile iterating it (collect the clones, then add them after the loop).
Extensions
Compare these approaches:
- handcrafted level sequences,
- parameter-driven level generation (the approach
LevelProgressionSystemtakes), - hybrid campaigns where authored milestone levels are mixed with generated in-between levels.
Then try to:
- 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,
- author and playtest a difficulty curve of your own for at least ten levels,
- add new arena presets beyond the opening rectangle (start from
ApplyArenaInsetClaim).

