José Moreira

Writing Pygame games for a two-year-old

The most demanding QA team I have ever worked with. No failure states, lots of bright colours.

My son loves pressing buttons. So I wrote a couple of tiny games for the Batocera box: a lightgun one where everything you hit turns into confetti, and a side-scroller where you cannot lose.

Design rules for a toddler

  • No game over, ever.
  • Every input does something visible.
  • Family photos as characters, cel-shaded.
  • Sessions end when he says so.
import pygame
import random

# Every click spawns confetti; there is no way to miss.
def spawn_confetti(pos, n=40):
    return [
        {"x": pos[0], "y": pos[1],
         "vx": random.uniform(-4, 4), "vy": random.uniform(-8, -2),
         "color": random.choice(PALETTE)}
        for _ in range(n)
    ]

particles = []
while running:
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN:
            particles += spawn_confetti(event.pos)
    for p in particles:
        p["x"] += p["vx"]; p["y"] += p["vy"]; p["vy"] += 0.3  # gravity
    particles = [p for p in particles if p["y"] < HEIGHT]

Placeholder post for layout testing.