Sub topic 5
Designing the Level Curve
A level curve maps total experience points (XP) to levels. Its shape sets how long each level takes, how often rewards arrive, and where players quit. This chapter assumes you have read the previous chapter on XP and levels. It also assumes you can read short Python samples and work with exponents and sums.
What the curve controls
Treat the curve as a pacing tool, not a math exercise. Two quantities matter, and they are easy to confuse:
- Cost per level is the XP needed to go from level
nton + 1. The code calls thisxp_to_next. - Cumulative cost is the total XP needed to reach level
nfrom level 1. The code calls thistotal_xp.
Players feel cost per level, because that is the bar they fill. Designers usually plan with cumulative cost, because it answers "how long until the endgame?"
The real design target is time per level, which is cost divided by how fast the player earns XP. A curve that looks steep on paper can feel flat if income grows with it. Always read a curve together with the XP income at that point in the game.
Common curve shapes
| Shape | Cost per level | Feel | Typical use |
|---|---|---|---|
| Linear | `base + step * (level - 1)` | Steady, predictable | Short games, mobile games |
| Polynomial | `base * level ** p` | Gentle slowdown | Mid-length RPGs |
| Exponential | `base * growth ** (level - 1)` | Fast start, hard late game | Long-running RPGs, MMOs |
| Table-driven | Hand-written list | Whatever you tune it to | Shipped games, final tuning |
Exponential curves are common because they front-load rewards. Early levels arrive in minutes, which teaches the loop, and later levels stretch out. The cost is that cumulative XP explodes. With growth=1.15, level 20 needs roughly 8,800 total XP and level 30 needs roughly 37,700. Small changes to growth move the endgame a lot.
The exponential curve in code
This is the curve from the spine, with its cumulative helper and its inverse:
def xp_to_next(level, base=100, growth=1.15):
"""XP needed to go from `level` to `level + 1`."""
return round(base * growth ** (level - 1))
def total_xp(level, base=100, growth=1.15):
"""Cumulative XP needed to reach `level` from level 1."""
return sum(xp_to_next(l, base, growth) for l in range(1, level))
def level_from_xp(xp, base=100, growth=1.15):
level = 1
while xp >= xp_to_next(level, base, growth):
xp -= xp_to_next(level, base, growth)
level += 1
return level
print(xp_to_next(1), xp_to_next(10), total_xp(10), level_from_xp(500))This prints 100 352 1678 5. Level 10 costs 3.5 times as much as level 1, and 500 XP is just enough to reach level 5, since levels 1 to 4 cost 499 together.
base and growth do different jobs:
basescales the whole curve. Doubling it doubles every level's cost and leaves the shape unchanged.growthchanges the shape. It controls how much harder each level is than the last.
Tune base to set how the first minutes feel. Tune growth to set how the late game feels.
Designing from a target, not from a formula
Picking growth=1.15 because it looks reasonable is a common mistake. Work backward from what you want instead.
- Decide the level cap and the total playtime to reach it.
- Decide how long the first level should take. A first level-up in the first two to five minutes is a common goal.
- Decide roughly how long the last level should take.
- Fit the parameters to those numbers.
For an exponential curve, fitting is a single formula. If the last level's cost should be last_cost and the cap is max_level, then growth = (last_cost / base) ** (1 / (max_level - 2)). The max_level - 2 comes from the cost formula. The cost of going from level max_level - 1 to max_level is base * growth ** (max_level - 2).
def xp_to_next(level, base=100, growth=1.15):
return round(base * growth ** (level - 1))
def fit_growth(base, last_cost, max_level):
"""Growth rate so the final level-up costs `last_cost` XP."""
return (last_cost / base) ** (1 / (max_level - 2))
def level_from_xp(xp, max_level=30, base=100, growth=1.15):
"""Return (level, leftover_xp), stopping at the cap."""
level = 1
while level < max_level:
cost = xp_to_next(level, base, growth)
if xp < cost:
break
xp -= cost
level += 1
return level, xp
print(round(fit_growth(100, 5000, 30), 3))
print(level_from_xp(10**9))A 5,000 XP final level over a 100 XP first level, capped at level 30, gives a growth of about 1.15. That is why the spine's default is a sensible one for a 30-level game.
The second function adds a cap. Without one, level_from_xp loops forever on a huge XP value, because costs keep growing but the loop never stops at a maximum. It also returns leftover XP, so you can decide what happens to it at the cap.
Reading the curve as time per level
Divide cost by income to see what the player feels. Suppose a player earns 8 + 2 * level XP per minute, so quests pay a bit more as you progress.
def xp_to_next(level, base=100, growth=1.15):
return round(base * growth ** (level - 1))
def minutes_per_level(level):
xp_per_minute = 8 + 2 * level
return xp_to_next(level) / xp_per_minute
for level in (1, 10, 20, 29):
print(level, round(minutes_per_level(level), 1))Level 1 takes about 10 minutes and level 29 takes about 76. Income grew from 10 to 66 XP per minute, but cost grew about 50 times, so the late game is slow. If 76 minutes per level is too long, you have three levers:
- lower
growth - raise income per activity
- add faster sources of XP late in the game
Edge cases and design decisions
Rounding. round() makes early costs jump in odd steps, such as 132 then 152. That is harmless. Rounding to a friendlier number, such as the nearest 5 or 10, makes costs easier to read and communicate. Do it once, in the cost function, so cumulative sums stay consistent.
Multiple level-ups from one reward. A large XP award can cross several levels. Use a loop, as level_from_xp does, instead of an if. Granting level-up rewards once per level crossed, not once per XP event, avoids skipped rewards.
Level caps and leftover XP. At the cap you can discard XP, bank it toward a separate "paragon" track, or convert it to currency. Discarding XP feels bad, because the player's action has no visible effect. A second track keeps the feedback loop alive.
Soft caps and plateaus. Some games keep the formula smooth but flatten the reward. For example, the player gains levels but fewer stat points per level. This keeps long-term growth without raising cumulative cost further.
Grind walls. A sharp rise in cost per level where income does not rise teaches players that further play is wasted. If you want a hard gate, such as a boss, make that gate explicit through unlocks instead of hiding it in the curve.
Catch-up mechanics. In multiplayer games, bonus XP for low-level players or for returning players keeps newcomers from falling behind a steep curve. This also makes it safe to use a steeper curve at the top.
Changing the curve after launch. If you change the formula in a live game, recompute levels from stored total XP, not from stored levels. Store total XP as the source of truth and derive the level from it. That makes balance patches one code change instead of a data migration.
Choosing between a formula and a table
A formula is compact, easy to reason about, and easy to rescale. A table lets you hand-tune individual levels, for example making level 10 quick because it unlocks a major feature. A practical workflow is to start with a formula for the first draft, then export it to a table and edit the levels that playtests flag. The table becomes the shipped data, which fits the data-driven approach covered later in the tutorial.
Exercise
Using base=100 and growth=1.15, how much XP does it cost to go from level 5 to level 6? Then, for a 40-level game with base 100 and a final level-up cost of 8,000 XP, what growth value does fit_growth return, to three decimals?
Show answer
xptonext(5) = round(100 1.15 4) = round(174.9) = 175 XP. For the fit, growth = (8000 / 100) (1 / 38) = 80 (1 / 38). Since ln(80) is about 4.382, the exponent is about 0.1153, and e * 0.1153 is about 1.122. So growth is about 1.122.
Exercise
A player earns 30 XP per minute at level 15. With base=100 and growth=1.15, about how many minutes does level 15 take, and which of the three levers (lower growth, raise income, add faster XP sources) would you change if the target is 30 minutes?
Show answer
The cost is round(100 1.15 * 14) = round(713.8) = 714 XP, so the level takes about 714 / 30, or roughly 24 minutes. That is already under 30. If the target were a ceiling of 30 minutes, no change is needed at this level. If you wanted it to take about 30 minutes, you could slightly raise growth or lower income. Any of the three levers works, as long as you check the effect on the levels before and after.