Skip to content

Build Last Perimeter with MonoGame ​

Welcome to Last Perimeter, a type-along course. You build a complete 2D arcade game from an empty project, one service and one operation at a time, and you prove every rule with a test.

Last Perimeter is a territory-capture game. You steer a marker along the edge of a field, leave the edge to draw a risky line, and reconnect to claim the space you enclosed. Enemies roam the open field, and a fuse chases you whenever you stop. Claim enough of the field and the level is won.

By the end of the course, you have a finished game with levels, powerups, menus, saved profiles, upgrades between levels, a daily challenge, colour themes and accessibility options. You also have a test suite that proves its rules without opening a window.

Last Perimeter is an independent game inspired by Qix (Taito, 1981). It is not affiliated with or endorsed by the owner of Qix.

Who this course is for ​

This course is for developers who write C# with confidence and have never used MonoGame or built a game. You should be comfortable with classes, properties, records, collections and basic generics. You do not need any maths beyond school geometry.

If you are newer to C#, read the optional C# primer first. It explains each language feature the course uses, with a short example and the chapter where you first meet it.

You do not need to know anything about game loops, sprites or tile grids. The course explains each one before you use it.

What you will learn ​

  • How a MonoGame project starts, updates and draws, and why the host class stays thin.
  • How to split a game into services that each own one kind of truth.
  • How to write a contract for an operation, then a test, then the code.
  • How to draw everything from one white pixel, with no art assets.
  • How to solve real problems: rebuilding a wall path, ruling a trail, steering enemies and choosing which region a closed line captures.
  • How to prove game rules headlessly, with scenario tests that need no window.
  • How to build the product around the game: menus, profiles, saving, seeded runs, themes and shipping.

Prerequisites ​

You need four things. Complete each step before you start Chapter 01: The Project and the Host.

  1. A code editor. Visual Studio Code with the C# Dev Kit extension is a good choice. Visual Studio and JetBrains Rider also work.

  2. The .NET 10 SDK, from the .NET download page. Open a terminal and run dotnet --version. The output should start with 10..

  3. The MonoGame project templates. In a terminal, run the following command, then check the result.

    dotnet new install MonoGame.Templates.CSharp
    dotnet new list monogame

    The second command should list the MonoGame templates.

  4. A clone of the course repository. The repository holds the course text and a finished project for every chapter.

    In PowerShell, run:

    powershell
    cd $HOME
    git clone [TODO Simon: public repository address] last-perimeter-course
    cd last-perimeter-course
    pwd

    In bash, run:

    bash
    cd ~
    git clone [TODO Simon: public repository address] last-perimeter-course
    cd last-perimeter-course
    pwd

    The last command prints the path of the clone. This course calls that path <course-repo>. If you prefer not to use Git, download the repository as a ZIP file from its web page and extract it, then note the path of the extracted folder.

NOTE

You build your own game in a new folder named LastPerimeter, created in Chapter 01. The course repository is a reference. Open it when you want to compare your work, not to copy from it.

How each chapter works ​

Every chapter from 01 onward is type-along. Chapter 00 is reading only.

Chapters from 03 onward build services. Every operation of every service follows the same five steps:

  1. Read the contract card: what the operation takes, gives, promises and refuses.
  2. Add the signature, with a body that throws NotImplementedException.
  3. Add the tests, one per promise and one per refusal, and watch them fail.
  4. Write the body, and watch the tests pass.
  5. Read the explanation, headed "The key things to note are:".

The tests come first because a test that has never failed has never proved anything. The stub keeps the project compiling, so each failure is a clean one.

Every chapter has the same sections, in the same order:

  1. A navigation line, an introduction and the end-state figure, with a time estimate.
  2. The requirements the chapter builds.
  3. Concept sections that explain the ideas before any code.
  4. One section per service, with one subsection per operation.
  5. Wiring the service into the game.
  6. Running the tests, with the exact count to expect.
  7. Running the game, with the keys to press and what you should see.
  8. Common mistakes, a conclusion, Test Your Knowledge and extensions.

Chapter 00: Overview explains this shape in more detail and shows the service map of the finished game.

The through-line ​

Every chapter asks the same six questions:

  1. What is the player feeling here?
  2. Which requirement makes that feeling possible?
  3. Which service owns that truth?
  4. Which operation changes it, and what does that operation promise?
  5. What maths or algorithm supports it?
  6. Which test proves it?

Chapter map ​

The course has 22 chapters in three parts. Each part ends with something you can play.

Part 1: Foundations ​

You finish with a thin host, a scene manager, the arena service, input, and a headless simulation that moves a dot.

ChapterTitleWhat you build
00Overview: the game, its requirements and its servicesNothing. This is a paper chapter.
01The project and the hostLastPerimeterApp, GameLaunchOptions
02Drawing from one pixelPrimitiveDrawing, PlayerRenderer
03The service pattern and the arenaGameConfig, ArenaSystem
04Input and frame timeInputManager, InputState, MovementSystem
05Scenes and the gameplay simulationScene, SceneManager, GameServices, GameplaySimulation

Part 2: One complete level ​

You finish with the whole core loop: wall path, trail, fuse, capture, enemies, lives, score, HUD and sound, with scenario tests that drive the simulation without a window. Chapters 06 and 09 are the hardest, so allow the most time for them.

ChapterTitleWhat you build
06The wall path serviceWallSystemV2, PlayableWallPath
07The trail serviceTrailSystem, Trail
08The fuse serviceFuseSystem
09The capture serviceAreaClaimingSystem, ClaimedAreaRenderer
10Enemies and collisionEnemySystem, CollisionSystem
11Lives, shields and respawnLivesSystem
12Events, score and feedbackGameEvent, ScoringSystem, AudioCuePlayer, HudRenderer
13Proving the levelScriptedInput, scenario tests, the smoke run (LASTPERIMETER_SMOKE_TEST_SECONDS)

Part 3: The full game ​

You finish with levels, powerups, profiles, menus, runs and upgrades, seeded daily runs, themes, accessibility and a shipped build.

ChapterTitleWhat you build
14Levels and difficultyLevelProgressionSystem, LevelServices
15PowerupsPowerupSystem, PowerupEffects
16Profiles, settings and savingProfileStorage, ProfileTracker
17Menus and the front endMenuList, OptionsModel, the menu scenes
18Runs and upgradesRunModifiers, RunUpgradeDraft
19Seeds, the clock and the daily challengeDailySeed, RunRandom, PlayerStatistics
20Themes and accessibilityThemePalette, the options rows
21ShippingPublishing, continuous integration and the requirements sign-off

Reference ​

These pages are not numbered chapters. Use them whenever you need them.

PageWhat it gives you
C# primerAn optional guide to the C# features the course uses, with the chapter where each first appears.
Requirements of the finished gameEvery requirement, its acceptance check, its proof and the chapter that builds it.

[TODO Simon: decide whether the course ships an appendix, "Where to take the game next", and where it links from this page]

Suggested pace ​

The chapters group into six blocks. Each block is a sensible stopping point.

BlockChaptersNotes
100 to 02MonoGame from zero.
203 to 05The patterns every later chapter repeats.
306 to 09The two hardest chapters are 06 and 09.
410 to 13Ends with a complete, tested single level.
514 to 17Content and the front end.
618 to 21Product features and shipping.

[TODO Simon: total course time and a time estimate for each block]

Where the snapshots live ​

Each chapter from 01 onward has a snapshot: a complete project folder that matches the end of that chapter. The snapshots are in the course repository, in DOCUMENTATION/learning_plan_2/snapshots/, one folder per chapter. Chapter 00 has none, because it has no code.

If your project fails to build or a test count differs from the chapter, compare your files with the snapshot for that chapter. To build a snapshot, open a terminal in its folder and run dotnet build. To test it, run dotnet test.

IMPORTANT

Use a snapshot to find a difference, not to skip the typing. You learn the rhythm of the course by writing each test and each body yourself.

Start the course ​

When the four prerequisites are in place, begin with Chapter 00: Overview. It takes no typing, and it explains the words the rest of the course uses.