5.5 Building a runner game

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

5.5 Building a runner game

You now have everything to build a runner game like Chrome Dino: a character that runs (or stays in place), obstacles that scroll from the right, and a jump or dodge to avoid them.

What we’re aiming for

Jump and simple gravity

Keep two variables: player_y or use player_rect.y, and a vertical speed (e.g. vy = 0). When the player presses jump, set vy = -15 (or another negative number). Each frame:

Only allow jump when the player is on the ground (e.g. if player_rect.bottom >= ground_y and event.key == pygame.K_SPACE: vy = -15).

Spawning obstacles

Game over and restart

When player_rect.colliderect(obstacle):

Checklist for your Chrome Dino–style game

  1. Window, game loop, quit on close.
  2. Player rect at a fixed x, moving up/down with jump and gravity.
  3. Ground line (optional: draw a line or rect for the ground).
  4. At least one obstacle (or many) moving left, respawning when off-screen.
  5. Collision → game over.
  6. (Optional) Score: increase every frame or every obstacle passed; show with text.
  7. (Optional) Restart with a key.

Ideas to extend

You’ve gone from no coding to a playable game — keep iterating and adding ideas.


Back to: Coding Club homepage