CS50 2D - Lecture 7 - Pokémon

CS50 (Harvard University)
CS50 (Harvard University)Apr 28, 2026

Why It Matters

Understanding stack‑based state management and modular UI design empowers developers to build robust, extensible games, accelerating prototyping and reducing code complexity.

Key Takeaways

  • Use a stack to manage overlapping game states like menus.
  • Implement turn‑based battles with separate field and combat states.
  • GUI panels built from simple rectangles with borders and text.
  • Layered tile maps differentiate grass depth for random encounters.
  • Demonstrates Lua/Love2D techniques for RPG mechanics and UI.

Summary

The final CS50 lecture walks students through building a Pokémon‑style RPG using Lua and the Love2D engine, emphasizing how classic turn‑based mechanics can be recreated with modern code. It introduces a stack‑based state system that lets the game push and pop contexts such as field exploration, battle screens, dialogue windows, and pause menus, preserving player position and enabling seamless transitions.

Key technical insights include separating the overworld (field state) from combat (battle state), layering tile maps to distinguish shallow and tall grass, and triggering random wild‑encounter events. The lecture also covers constructing GUI elements—panels, text boxes, menus, progress bars—by drawing nested rectangles with borders, mirroring web‑style CSS techniques. Health and XP bars are animated using timers and tweens, illustrating reusable UI components.

During the live demo, the instructor shows a dialogue box appearing over the field, a battle menu offering Fight or Run options, and the consequences of each choice, such as damage calculation, victory XP, or fainting and revival. Sample code for a simple Panel class demonstrates how a 50‑line module can render bordered rectangles and handle visibility toggles, reinforcing the modular design approach.

The lecture’s broader significance lies in teaching aspiring developers a scalable architecture for RPGs: state stacks for layered gameplay, composable UI widgets, and asset reuse (e.g., Zelda sprite sheets). These patterns equip students to prototype complex games quickly and translate to commercial indie projects.

Original Description

In CS50 2D’s final lecture, explore the core mechanics and programming concepts behind Pokémon-inspired RPGs, including state stacks, GUI design, and turn-based battle systems.
To take the course for a certificate, register at cs50.edx.org/2d.
***
This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
***
HOW TO SUBSCRIBE
HOW TO TAKE CS50
Harvard Extension School: https://cs50.harvard.edu/extension
Harvard Summer School: https://cs50.harvard.edu/summer
HOW TO JOIN CS50 COMMUNITIES
HOW TO FOLLOW DAVID J. MALAN
***
CS50 SHOP
***
LICENSE
CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
David J. Malan
malan@harvard.edu

Comments

Want to join the conversation?

Loading comments...