Learning C++ by Building Games, Second Edition — cover

About this book

Learning C++ by Building Games · Second Edition · by John Horton

From your first line of code to a roguelike you built yourself — modern C++20, learned by building 25 hands-on projects. The whole book is free to read here.

36chapters, rewritten start to finish
25projects, finished code on GitHub
295terms in the glossary

What it is

If you've never written a line of code, you're in the right place. If you know another language and want C++, or know some C++ and want to make games, you're in the right place too. C++ has a reputation for being hard, usually because it's taught in the abstract. This book does the opposite: every idea arrives because a game needs it, and you build every game step by step, with the code explained as you go.

What you'll build

Bouncing Ball, Square Invader and Cascade teach variables, decisions and loops; an arcade shooter ties the first act together. Whack-a-Mole and a side-scrolling runner bring in real art. You build one animated character three ways — as you learn classes, inheritance and polymorphism — then direct an AI to write Snake and Asteroids. The finale is Rogue SDL, a roguelike built across seven playable parts: dungeons in the dark, monsters that hunt you, treasure, save files, sound, scrolls, swords and fireballs.

What you'll learn

Modern C++20 from the ground up — variables, loops and functions; pointers, smart pointers and references; vectors and maps; classes, inheritance, virtual functions and interfaces; templates, lambdas and exceptions. Then the ideas real games run on: the game loop, delta time, collision, animation, state machines, components and A* pathfinding. Every chapter after the first ends with an AI exercise and a checklist for judging the answer, and 112 build checkpoints let you confirm your code works before you move on.

Who it's for

Complete beginners, and anyone who learns best by making something they can actually play. All you need is a Windows PC with Visual Studio 2026 Community — Chapter 1 sets it up, step by step, along with SDL 3. (Appendix B covers building every project on a Mac or Linux.)

Free online, in print, and on Kindle

This complete second edition is free to read online, right here — every chapter, no sign-up, no paywall. If you'd like it offline and on your shelf, the Kindle edition contains everything, and the paperback carries every chapter you need to learn C++ and build the games, with some of the longer reference material kept here on the site so the book fits in a single volume. However you read it, the code for all 25 projects is on GitHub.

About the author

I'm John Horton — I've spent four decades turning the daunting business of writing code into something a complete beginner can actually enjoy, and since 2014 I've taught it at Game Code School by building real games. If this book helps you make something you're proud of, that's the whole point.

Carry on in the series

Fundamentals →

The math every engine hides — vectors, physics, pathfinding and a software 3D renderer, built from scratch.

Using C++ to Build a Traditional Roguelike →

Rogue SDL was a taste. This is the whole meal — a complete dungeon crawler, built properly.

Building C++ Games with AI →

You bring the vision, the AI writes the C++, and you direct it all the way to finished.

Start reading free → Get the ebook & paperback See all 36 chapters