Learning LibraryGame Development LibraryKids

Score and lives: the numbers that make it a game

What turns 'moving shapes' into a game? Numbers to chase. Points that climb when you do well, and lives that drop when you slip.

The big idea

Score and lives are numbers the game tracks — points go up, lives go down — and shows on the screen.

See it in code

1Start simple

Underneath, score and lives are just numbers. Score starts at 0 and goes up; lives start at 3 and go down:

python
score = 0
lives = 3

score = score + 100
lives = lives - 1

print("Score:", score, "Lives:", lives)
Run it — one number climbs, the other drops:
Score: 100 Lives: 2

Add to the score, take from the lives. That up-and-down is the heart of every scoreboard.

2A step further

The HUD holds those numbers and shows them. We add_score(100), then draw it at the top of the screen:

python
from game import Stage, HUD

screen = Stage.create()
Stage.clear(screen)

hud = HUD()
hud.add_score(100)

print("Score:", hud.score)
hud.draw(screen)
Run it — the HUD puts the score on screen:
Score: 100
A dark play area with a heads-up display reading SCORE 100 and LIVES 3.

The HUD started with 3 lives and now shows a score of 100. It keeps the numbers for you and paints them on screen.

3In our world

Now let a whole turn play out. The player scores twice with add_score, loses one life with lose_life, and the HUD shows the new totals:

python
from game import Stage, HUD

screen = Stage.create()
Stage.clear(screen)

hud = HUD()
hud.add_score(100)
hud.add_score(50)
hud.lose_life()

print("Score:", hud.score, "Lives:", hud.lives)
hud.draw(screen)
Run it — the HUD shows the running score and lives:
Score: 150 Lives: 2
A dark play area with a heads-up display reading SCORE 150 and LIVES 2.

Two scores of 100 and 50 make 150, and one lost life leaves 2. The HUD shows both at a glance — that's how a player knows how they're doing.

The same idea, everywhere

Almost every game keeps score of something: points, coins, time, health, laps. The pattern is the same — a number goes up for good moves and down for bad ones, and the screen shows it so the player can chase it.

Try it yourself

Add another add_score(200) and check the new total. Then take away all three lives with three lose_life() calls — what should the game do when lives reach 0?

The common mistake

Changing the numbers but never drawing them. add_score(50) updates the score inside the HUD, but the player won't see it until hud.draw(screen) puts it on screen each frame.

What it unlocks

Scoring builds on variables and collision detection, and pairs with game state to end the game.