Skip to main content
Skip to article

Research Note

Game Development with pygame

Zhenyu He · Jobs Stroustrup 3 min read

Proficiency

Proficient

Description

pygame framework (full stack)

  • pygame.sprite.Sprite base class + inheritance tree (9 Enemy subclasses; 4 Bar subclasses)
  • pygame.sprite.Group organized by type (enemies full set + ord_enemies / heal_enemies / split_enemies subset for per-type batch collision/update)
  • pygame.Surface / pygame.image.load / convert_alpha + double-buffered drawing
  • pygame.mixer: music.load + play(-1) for looping BGM + mixer.Sound for triggered SFX
  • pygame.font with custom font (Futura.ttc) + text rendering
  • pygame.time.Clock FPS control (60 FPS, 60s per match)
  • pygame.event event loop: KEYDOWN/KEYUP + QUIT + multi-branch

Scene + state management

  • Multi-mode state machine (main menu / battle / story / pause / end / tutorial — 6 scenes)
  • Assets pre-loaded into Surface caches to avoid runtime disk I/O
  • Pause/end overlays + per-menu option state

Custom DSL (Domain-Specific Language) design

  • Token-stream data structure (double-ended deque) supporting both L_ prepend and R_ append
  • Key-to-token mapping (KEYDICT lookup)
  • Real-time evaluation (calc(x) applies tokens in order)
  • Symbolic simplification rule engine (inverse pair cancellation: a·s, l·e, d·d, -·-, /·*) — lite computer-algebra normalize
  • Expression pretty-print (token stream → readable string like sin(e(x/2)))
  • Custom exceptions as gameplay mechanic (out_of_domain on log(neg)/arcsin(|x|>1)/1/0 triggers “function invalid” feedback)

Game balance & incentive design

  • Non-linear cost function: cost = f(linear, A, d, e, l) with exponential composition pow(2+linear, 1.5+A) penalizing nested operations — making elegant expressions the dominant strategy
  • Converting mathematical rigor (exceptions) into gameplay feedback — getting it wrong is how you learn

Coordinate abstraction

  • Four bidirectional mapping functions (lof / tof / xof / yof) decouple physics and screen coords
  • pygame.sprite.Sprite.rect.center and custom (x, y) coord systems kept in sync

Gamified educational design

  • 11-level tutorial with increasing math difficulty: single ln → single exp → single sin → 2sin → sin×2 → sin÷2 → …
  • Each level has fixed target points (e.g. [(0,-4), (1,0), (3,1), (7,2)] for ln) — player must construct a function through them — an inverse problem-to-answer practice
  • Knowledge sequencing: single ops first, then composition, then deep nesting — core curriculum-design principle
  • Directly relevant to the Exam-centric AI Coaching idea in

Engine reverse-engineering (cross-project)

  • In , to build the rollout simulator, Zhenyu fully reverse-engineered Prof. Chen’s kernel.py (eject physics / multi-body absorb / collision grouping) — white-box modeling of external game engines

Relationships to Other Skills

Used In

  • — Math Kills Monsters Alpha 4.0 (~1300 lines pygame + 9 enemies + 11 tutorial levels + full UI + audio/visual assets)
  • — white-box understanding of the kernel.py / world.py / cell.py game engine internals
  • Potential future use: interactive components for educational/visualization products