Appearance
Chapter 11 - Powerups, Score Modifiers, and Risk-Reward Systems
Where this chapter fits: pickups appear on the wall, expire under time pressure, and bend one axis of play each. Five effect shapes hide behind one switch, and a score multiplier shows how to shape behaviour without forcing it.
Time: [TODO Simon: time estimate for chapter 11]
The chapter 11 build about seven seconds in: the first pickup has spawned on a wall node (here the bottom-left corner). Pickups live eight seconds and spawn on nodes of the playable path, so the wall keeps them mostly safe to collect.
Prerequisites
Chapter 10 (multi-level flow and enemy variants in play), plus the chapter 08 scoring and HUD foundations.
Learning objectives
By the end of this chapter you should be able to:
- implement timed pickup spawning with randomised cooldowns (
PowerupSystem), - place pickups meaningfully by spawning on
PlayableWallPathnodes and expiring them under time pressure, - apply five distinct effect shapes (charge, timed aura, instant resource, timer reset, and score multiplier) through one switch,
- communicate active effects through HUD readouts so players can act on them,
- distinguish temporary in-level effects from run-scoped upgrades (set up for chapter 13), and pass the chapter's 55 tests.
Code anchors
Source/Systems/PowerupSystem.cs(spawn timing,Spawn,UpdatePowerups,TryCollect)Source/Entities/Powerup.cs(Type,Position,Radius,RemainingLifetimeSeconds)Source/Data/Enums.cs(PowerupType:Shield,Freeze,ExtraLife,FuseReset,DoublePoints)Source/Game/LastPerimeterApp.cs(chapter 11 staged version:ApplyPowerupeffect switch,ConsumeShield,DrawPowerup)Source/Data/GameSession.cs(staged:Powerups,ShieldCharges,FreezeEnemiesRemaining,DoublePointsRemaining)Source/Rendering/HudRenderer.cs(the full version:SHIELD:andDOUBLE PTSreadouts)Tests/Systems/PowerupSystemTests.cs
The key lesson
A powerup should create an interesting decision before it creates a reward.
The implemented pickup set
The five PowerupType values each change a different axis of play:
| Pickup | Effect (in ApplyPowerup) | Axis | Drawn as |
|---|---|---|---|
Shield | ShieldCharges++: the next fatal hit cancels the trail instead of costing a life | survivability | palette Accent (lime green in the default theme) |
Freeze | FreezeEnemiesRemaining = PowerupSystem.FreezeDurationSeconds (2 s): enemies stop moving | tempo | light blue |
ExtraLife | Player.Lives++ | survivability | lime green |
FuseReset | _fuseSystem.Reset(): buys drawing time right now | risk | palette Warning (orange-red) |
DoublePoints | DoublePointsRemaining = PowerupSystem.DoublePointsDurationSeconds (10 s): 2x on claims | scoring | gold |
WARNING
In the default theme Shield (palette Accent) and ExtraLife (Color.LimeGreen) are the same green, so you cannot tell them apart on the wall. The course leaves this in on purpose, because it shows how easily two pickups end up sharing a colour when one comes from the palette and the other is hard-coded.
The colours are chosen in DrawPowerup in Source/Game/LastPerimeterApp.cs. A fix that works is to leave Shield on the palette Accent, so it follows the theme, and change ExtraLife to Color.White, which no theme uses for a pickup. Pink looks like the obvious choice for a life, but the colourblind palette's Accent is already a pink-purple, so the two would clash again in that mode. Whatever you pick, check it against all five pickups (Accent, Color.LightBlue, the palette Warning and Color.Gold are taken) and in the colourblind palette. A different shape, such as a ring for Shield, is stronger still, because it does not rely on colour at all. The Extensions list at the end of the chapter asks you to make the change.
Also compare the wider design space (speed boosts, slow-motion fields, claim-bonus pickups) and ask which axis each one bends.
The pickup lifecycle
Placement and spawn rules
Powerups are more interesting when their placement has meaning. In PowerupSystem, pickups spawn on the playable wall outline, so collecting one is usually safe. The wall keeps shrinking as you claim, though, and the pickup expires in 8 seconds:
csharp
public const int MaxActivePowerups = 2;
public const float FreezeDurationSeconds = 2f;
public const float DoublePointsDurationSeconds = 10f;
private const float FirstSpawnDelaySeconds = 6f;
private const float MinimumSpawnIntervalSeconds = 7f;
private const float SpawnIntervalVarianceSeconds = 4f;
private readonly Random _random;
private float _spawnTimerSeconds = FirstSpawnDelaySeconds;
// Pass a seeded Random to make spawns repeatable (tests, seeded runs).
public PowerupSystem(Random? random = null)
{
_random = random ?? new Random();
}
public void UpdateSpawnTimer(float deltaTime)
{
_spawnTimerSeconds = Math.Max(0f, _spawnTimerSeconds - deltaTime);
}
public bool CanSpawn => _spawnTimerSeconds <= 0f;
// Call at the start of every level so its first powerup waits the full delay.
public void ResetForLevel()
{
_spawnTimerSeconds = FirstSpawnDelaySeconds;
}
public void ResetSpawnTimer(float minimum = MinimumSpawnIntervalSeconds, float variance = SpawnIntervalVarianceSeconds)
{
_spawnTimerSeconds = minimum + (_random.NextSingle() * variance);
}
public Powerup Spawn(PlayableWallPath wallPath)
{
IReadOnlyList<Vector2> candidates = wallPath.Nodes;
Vector2 position = candidates[_random.Next(candidates.Count)];
PowerupType type = (PowerupType)_random.Next(Enum.GetValues<PowerupType>().Length);
ResetSpawnTimer();
return new Powerup
{
Type = type,
Position = position,
};
}ResetSpawnTimer() randomises the next spawn 7-11 seconds out (MinimumSpawnIntervalSeconds + up to SpawnIntervalVarianceSeconds). UpdatePowerups decrements each pickup's RemainingLifetimeSeconds (initialised from Powerup.DefaultLifetimeSeconds, 8 seconds) and removes expired ones. The app caps the number on screen at PowerupSystem.MaxActivePowerups, which is two. Urgency is built into the data model, not bolted on.
The constructor takes an optional Random. Tests pass a seeded one so a spawn is repeatable, and the game passes nothing. ResetForLevel() puts the spawn timer back to the first-spawn delay, so each level starts with a full wait for its first pickup. A pickup spawns on a node. At level start the only nodes are the four corners. After captures the path has many more nodes, and pickups appear along the new inner edges.
Collection is a plain distance check, easily unit-tested because it touches no MonoGame services:
csharp
public Powerup? TryCollect(List<Powerup> powerups, Vector2 playerPosition, float pickupRadius)
{
for (int index = 0; index < powerups.Count; index++)
{
Powerup powerup = powerups[index];
float radius = powerup.Radius + pickupRadius;
if (Vector2.DistanceSquared(powerup.Position, playerPosition) > radius * radius)
{
continue;
}
powerups.RemoveAt(index);
return powerup;
}
return null;
}Applying effects: one switch, five shapes
The app layer owns what a pickup does, in ApplyPowerup:
csharp
switch (type)
{
case PowerupType.Shield:
_gameSession.ShieldCharges++;
_gameSession.StatusMessage = "SHIELD READY";
break;
case PowerupType.Freeze:
_gameSession.FreezeEnemiesRemaining = PowerupSystem.FreezeDurationSeconds;
_gameSession.StatusMessage = "ENEMIES FROZEN";
break;
case PowerupType.ExtraLife:
_gameSession.Player.Lives++;
_gameSession.StatusMessage = "EXTRA LIFE";
break;
case PowerupType.FuseReset:
_fuseSystem.Reset();
_warningAudioPlayed = false;
_gameSession.StatusMessage = "FUSE RESET";
break;
case PowerupType.DoublePoints:
_gameSession.DoublePointsRemaining = PowerupSystem.DoublePointsDurationSeconds;
_gameSession.StatusMessage = "DOUBLE POINTS";
break;
}Timed effects tick down in Update, where FreezeEnemiesRemaining and DoublePointsRemaining are clamped to zero each frame. The freeze flag flows into EnemySystem.Update through its frozen parameter. The speedMultiplier parameter is an extra factor from the caller, which Update multiplies with the variant speed from chapter 11 (the app passes 1f). Both are in the EnemySystem.cs you copied in chapter 07:
csharp
public bool Update(Enemy enemy, ArenaSystem arenaSystem, float deltaTime, float retargetIntervalSeconds, Vector2? pressureTarget = null, float speedMultiplier = 1f, bool frozen = false)ConsumeShield spends a charge to cancel a fatal hit instead of taking a death:
csharp
private bool ConsumeShield()
{
if (_gameSession.ShieldCharges <= 0)
{
return false;
}
_gameSession.ShieldCharges--;
_trailSystem.Cancel();
_fuseSystem.Reset();
_warningAudioPlayed = false;
_gameSession.Player.CurrentTrail = null;
_gameSession.Player.Position = _gameSession.PlayableWallPath.Snap(_gameSession.Player.Position);
_gameSession.RespawnGraceRemaining = _activeConfig.RespawnGraceSeconds;
_gameSession.StatusMessage = "SHIELD BLOCK";
return true;
}Both death paths (fuse and collision) become if (!ConsumeShield()) HandlePlayerDeath();. Every effect announces itself via StatusMessage, and the full HudRenderer shows persistent SHIELD:n and DOUBLE PTS readouts.
Score multipliers as behaviour design
Double points multiplies the claim when it lands. In the chapter 11 app the multiplier is the double-points window alone; chapter 13 multiplies in the run-scoped bonus too:
csharp
float totalScoreMultiplier = _gameSession.DoublePointsRemaining > 0f ? 2f : 1f;
_gameSession.Score += _scoringSystem.ScoreClaim(claimResult.CapturedRegion.TileCount + claimResult.TrailTiles.Count, completedTrail.IsSlowDraw, totalScoreMultiplier);Together with the chapter 08 slow-draw bonus, this is the lesson in miniature.
NOTE
Scoring systems can shape player behaviour without forcing it.
A 10-second double-points window invites a big, risky claim but never demands one.
Temporary effects vs persistent effects
Keep the difference clear:
- temporary effects change the next few seconds (everything in this chapter),
- run-limited upgrades change the next few levels (
RunModifiers, chapter 13; notePowerupSystem.CreateUpgradeChoicesalready lives inPowerupSystem.cs), - persistent upgrades change the metagame outside a run (
PlayerProfile, chapter 12).
Mixing those categories too early leads to muddy rules and poor tuning.
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. The listings show the parts worth studying, not every line.
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/11-Powerups-Score-Modifiers-And-Risk-Reward-Systems/Source", "<course-repo>/DOCUMENTATION/LastPerimeter-Source/11-Powerups-Score-Modifiers-And-Risk-Reward-Systems/Tests" .In bash:
bash
cp -R "<course-repo>/DOCUMENTATION/LastPerimeter-Source/11-Powerups-Score-Modifiers-And-Risk-Reward-Systems/Source" "<course-repo>/DOCUMENTATION/LastPerimeter-Source/11-Powerups-Score-Modifiers-And-Risk-Reward-Systems/Tests" .That copy brings in these files:
New files:
Source/Data/RunUpgradeChoice.csSource/Entities/Powerup.csSource/Systems/PowerupSystem.csTests/Systems/PowerupSystemTests.cs
Replaced files (you already have these, so overwrite them):
Source/Data/GameSession.csSource/Game/LastPerimeterApp.csSource/Rendering/HudRenderer.cs
RunUpgradeChoice.cs is used by CreateUpgradeChoices and exercised in chapter 13. HudRenderer.cs is now the full version. The staged GameSession adds Powerups, RunMode, FreezeEnemiesRemaining, DoublePointsRemaining and ShieldCharges.
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 - Spawn and collect: the gameplay update
Open Source/Game/LastPerimeterApp.cs. Initialize constructs a PowerupSystem. At the top of the gameplay update, the app ticks the timers, spawns, and collects:
csharp
_gameSession.FreezeEnemiesRemaining = Math.Max(0f, _gameSession.FreezeEnemiesRemaining - deltaTime);
_gameSession.DoublePointsRemaining = Math.Max(0f, _gameSession.DoublePointsRemaining - deltaTime);
_powerupSystem.UpdateSpawnTimer(deltaTime);
_powerupSystem.UpdatePowerups(_gameSession.Powerups, deltaTime);
if (_powerupSystem.CanSpawn && _gameSession.Powerups.Count < PowerupSystem.MaxActivePowerups)
{
_gameSession.Powerups.Add(_powerupSystem.Spawn(_gameSession.PlayableWallPath));
}
Powerup? collectedPowerup = _powerupSystem.TryCollect(_gameSession.Powerups, _gameSession.Player.Position, _gameSession.Player.Radius);
if (collectedPowerup is not null)
{
ApplyPowerup(collectedPowerup.Type);
_audioCuePlayer.PlayPowerup();
}Step 3 - Freeze and the shield
Open Source/Game/LastPerimeterApp.cs. The app passes frozen: _gameSession.FreezeEnemiesRemaining > 0f into both EnemySystem.Update and TrySpawnSplitterClone (a frozen Splitter must not split either). ApplyPowerup and ConsumeShield are new, and both death paths now go through the shield.
Step 4 - Level reset, drawing, and scoring
Open Source/Game/LastPerimeterApp.cs. SetupLevel clears Powerups and both timers. After _gameSession.Powerups.Clear();, it calls _powerupSystem?.ResetForLevel(); so each level's first powerup waits the full delay. Each pickup is drawn as a filled circle in its colour between the trail and the fuse spark, and the claim score is multiplied by the double-points factor.
Step 5 - Build, test, run
Run these commands from your LastPerimeter folder:
bash
dotnet build
dotnet test
dotnet run --project Platforms/DesktopVKdotnet test reports 55 passing tests. On Windows you can also run dotnet run --project Platforms/WindowsDX12.
Chapter snapshot
The buildable project lives at DOCUMENTATION/LastPerimeter-Source/11-Powerups-Score-Modifiers-And-Risk-Reward-Systems. Versus chapter 10 it adds PowerupSystem.cs, Powerup.cs, RunUpgradeChoice.cs, the full HudRenderer.cs (replacing the staged chapter 08/10 version with shield and double-points readouts), and PowerupSystemTests.cs. The staged app integrates spawning, collection, shield, freeze, and double points into gameplay.
bash
cd DOCUMENTATION/LastPerimeter-Source/11-Powerups-Score-Modifiers-And-Risk-Reward-Systems
dotnet build
dotnet testThe new test file is Tests/Systems/PowerupSystemTests.cs. It holds TryCollect_RemovesPowerupWhenPlayerIsInRange, CreateUpgradeChoices_ReturnsThreeDistinctOptions, Spawn_UsesWallNodesForPlacement, Spawn_WithSameSeed_PicksSameTypeAndNode and ResetForLevel_RestoresTheFirstSpawnDelay. This raises the suite from 50 to 55 tests.
Checkpoint
an ExtraLife collected on a corner: four pips | a DoublePoints window running: DOUBLE PTS shows for ten seconds |
- In your
LastPerimeterfolder, rundotnet test. It reports 55 passing tests. If it does not, compare yourSourceandTestsfolders with the chapter 11 snapshot. - Run
dotnet test --filter PowerupSystemTests. It reports 5 passing tests. - Run
dotnet run --project Platforms/DesktopVKand wait on the wall. A pickup appears on a wall node within about 6 seconds, and it disappears 8 seconds later if you ignore it. - Use the arrow keys to walk along the wall onto a pickup (the Controls table in chapter 03 lists every key). The status line names what you collected, for example
EXTRA LIFE. The two frames above were captured that way. - Keep collecting until the status line reads
SHIELD READY. The HUD showsSHIELD:1. Draw into the arena and let an enemy touch your trail. The trail is cancelled, the status line readsSHIELD BLOCK, and you keep your life. - Keep collecting until the status line reads
DOUBLE POINTS. The HUD showsDOUBLE PTSfor ten seconds, and a claim you complete in that window scores double. - Press Escape to close the game.
What you should have now
You now have:
- five pickups (
Shield,Freeze,ExtraLife,FuseReset,DoublePoints) that spawn on wall nodes, at most two at a time, and expire after 8 seconds, - one
ApplyPowerupswitch that applies the five effect shapes, with the timed effects counting down onGameSession, - a shield that cancels a fatal hit instead of costing a life,
- HUD readouts for the shield and the double-points window, and a status line for every pickup,
- a claim score that doubles during the double-points window,
PowerupSystemTests, which takes the suite to 55 tests.
Common mistakes
- spawning inside the interior where collecting means drawing,
- forgetting to clear pickups and timers at level start,
- applying timed effects as flags that never expire,
- letting a shield absorb a death without cancelling the trail (the enemy would hit it again next frame).
Extensions
Try to explore:
- mutually exclusive pickups,
- cursed powerups with upside and downside,
- pickups that alter enemy targeting,
- pickups that change capture thresholds for one level,
- re-snapping or expiring pickups when a capture rebuilds the wall path and leaves a node unreachable,
- an unmistakable shape or colour for each pickup. The shipped build reuses one green for
ShieldandExtraLife. Start inDrawPowerupinSource/Game/LastPerimeterApp.csby changingExtraLifetoColor.White, then try drawingShieldas a ring.

