← Back to the gamebug or idea?Terrapin Trail//Code BibleIIhow the game works, archive to van
Reel 09 · 6 min read

Winning, losing, and the score

How the game decides you've won or lost, and turns a whole run into a single number.

Every run ends somehow — you reach the last show and win, or you run out of morale, crew, or van and lose. Either way the game turns your whole trip into a single score. This chapter is about how a program decides "you won" or "you lost," and how it boils a long, messy playthrough down to one number.

Winning and losing

The game constantly watches for the losing conditions: morale hitting zero, losing your whole crew, or the van dying with no money to fix it. Winning is simpler — reach and attend (or record) the final show.

Concept: a "condition". A condition is a yes/no test the program checks, like "is morale at zero?" Games are full of them: win conditions, lose conditions, "can you afford this?" The game bundles the lose-checks into one function it runs at key moments.

The one big moment: the Peak

Once per run, your character gets a special scripted high point that boosts one of their stats:

●assets/game/game.js : 1640–1647trace ↗
1640  function showPeak() {
1641    var p = PEAKS[S.role] || DEFAULT_PEAK;
1642    var target = p.to + (S.flags.nightOwl ? 4 : 0);
1643    S[p.stat] = clamp(target, 0, statCap(p.stat));
1644    S.peaked = true;
1645    S.peakData = p;
1646    addLog(S, "You PEAKED -- " + p.title.toLowerCase() + ".", "good");
1647    Sound.peak();
The Peak: look up this character's special moment, boost the right stat (a little extra if you took the Night Owl perk), but never above its cap, and mark that it happened.

Notice it respects the cap from the last chapter ("never above its cap") — a nice example of different parts of a program agreeing to the same rules.

Turning a whole run into one number

When the game ends, it computes your score with a single formula:

●assets/game/game.js : 2035–2037trace ↗
2035  function computeScore() {
2036    return Math.round(S.tapes * 8 + S.showsAttended * 15 + S.legendaryTapes * DNA.legend + S.vibes + S.cred + S.cash / 5 + S.miles / 40);
2037  }
The score: tapes, shows, and legendary tapes are each worth points (how much a legendary tape is worth is one of the rules you can change), plus your leftover morale, reputation, some of your cash, and some of your mileage.

Read what the formula rewards and you understand what the game values: legendary tapes are worth the most by far (60 points each), then attending shows and collecting ordinary tapes, and finally ending with high spirits, good reputation, spare cash, and lots of miles behind you.

Concept: a "formula" as a design tool. That one line is the game's definition of success. Change the numbers and you change what players chase. This is a quiet but powerful truth: a lot of "game design" is really just choosing what each thing is worth in a formula like this.

Finally, one function wraps up the ending: it records your run to the leaderboard, checks which achievement badges you earned, clears your save, and shows the win or game-over screen.

The ideas to keep
  • A condition is a yes/no test; the game watches lose-conditions and a simple win-condition.
  • The Peak is a once-per-run boost that still obeys the same caps as everything else.
  • One formula turns the whole run into a score — and choosing the numbers in it is choosing what the game rewards.