CC-licensed book on learning games programming for kids

Al Sweigart sez,
I've written a book that teaches programming to kids (and beginner adults) that I thought might interest you. The book is Invent Your Own Computer Games with Python and it is available in full for free under a Creative Commons license.

I began writing it when a friend who nannies a 10 year old boy asked me for any good programming tutorials. Most of what I found seemed to be either boring textbooks or books for software engineers. My book uses a different approach: Each chapter focuses on the source code for a small game (Tic Tac Toe, Hangman, Othello, an encryption program, etc.) and explains the concepts as they come up in the program. While sometimes concepts are introduced in an unorthodox order, they are always based on actual programs.

The first three chapters covers the basics of installing Python and using the interactive shell. The next several chapters covers games that use text and ASCII art. The last four chapters introduces the Pygame library for graphics and sound.

The print edition came out a couple months ago and has about a dozen reviews on Amazon. (I've priced it at $25 to qualify for free shipping and but still cheaper than other computer books, and it's still free online.)

Buy Invent Your Own Computer Games with Python on Amazon

Teach yourself how to program by making computer games! (download and information) (Thanks, Al!)


    1. Hi, I’m Al the author of the book. I wrote the book in a dry and plain tone (as opposed to a “4 kidz” style) so it’s a bearable read for adults too. Quite a few college students and adults have emailed me saying they found the book enjoyable. I just tried to keep the concepts simple enough for grade school kids to understand.

  1. This was the way learning to code used to be, back in the (microcomputer) day – small self-contained programs that introduced each concept and built on the last. Good stuff.

  2. Really nice book. Very gentle approach, that manages to remain interesting. I think it does what it sets out to do quite well: emulate those old “learn game programming in Basic” books of the 80s.

    But at the same time, and I think this is Python’s fault, the book does feel 30 years behind the times. Python feels like completely the wrong tool for teaching game programming.

    It’s pretty damning of Python that more than three quarters of the 20-chapter book are spent on command line games: it gets to basic line graphics and the concept of the “main game loop” at chapter 17, and only finally hits sprites at chapter 19. And (with chapter 20 reserved for a big sprite game) the book ends there.

    What the world needs(tm) is something like DarkBasic but open, which would get them up and running with a 3D game at the “Hello World” stage, and then teach them concepts like arrays and collision detection around their game, rather than teach them game programming around the concepts.

    That is much, much more appealing to a kid who wants to develop a game than 16 chapters of text games.

    No kid says “I want to learn TEXT programming!”: when they think “game”, they think “graphics”. Even the best books of the 80s knew that. Kids want to do graphics, and they want to do them NOW, not in 17 chapter’s time. And ideally, they want 3D avatars, not 2D sprites.

    Yes, you love those old retro sprite games. But don’t force your values on the kids of today.

    Worrying about animating and texturing, placing a lightbox and a procedurally generated groundplane on day 2 is much more engrossing than worrying about making an array to print out Os and Xs for a text picture of your board, and teaches more game-relevant skills.

    DarkBasic’s very far from the perfect language: it’s proprietary, there are no anonymous datastructures, arrays must be globally defined, etc. (might’ve changed, I’ve not looked at it for a while: but I wouldn’t bet on it). But as a pedagogical language for gaming to get people enthralled, it can’t be beat.

    If there were a public domain language like this, that would definitely be the one I’d get kids coding in. But there isn’t (that I know of).

    So if I were an educator, I’d probably argue for budget to be spent on DB licenses, and free tutorials, rather than on copies of this book and free Python.

    Or I’d just go straight for DarkSDK, a free C/C++ lib that does the same thing, and not spend any money: but that’s not quite so coder-friendly.

    1. There **is** a point to text based game programming especially for education. There is nothing about python that limits you to this if your students really are ready to handle more sophisticated concepts. For 2D gaming there is

      For which there plenty of good tutorials and
      lots of documentation

      Slicker (still 2D games), better performance and with more direct
      openGL access there is the python library:

      For which there are nice tutorials:


      Then again some people won’t call it game programming
      unless it is 3d. For that there is pyogre and

      So I am not sure about how retro python is compared to BASIC.

      If you want to get nostalgic for ancient languages, python provides a turtle library so you can re-live the days of logo

      Now if only somebody would finish a port of scratch

      then python game programming for education would
      be complete.

    2. Dewi Morgan – why is 3D more appealing to a kid that wants to make a game than text mode? Being in 3D doesn’t mean a game is intrinsically better or more fun. I’d take Tetris over Portal any day.

    3. Hi Dewi, I’m Al the author of the book. This is a sentiment I’ve encountered often with my book. The choice to use text games in the beginning chapters was deliberate and shouldn’t reflect poorly on the Python language for beginners.

      I wanted to use text because it took the abstraction layer down a bit (lower than Visual Basic, but not as low as C or assembly.) But I added the Pygame chapters because people do want graphics and sound.

      But I completely disagree that we need to start out with 3D graphics in order to make compelling content. When I was learning to program in BASIC, the text games I was making were far less cool than the 16-bit Super Nintendo games I had. But it was creative and fun, and led to me becoming a software developer.

      I will concede that this might make the book not the best for a general audience. But there are already plenty of other books and tutorials and “game creation kits” that target the general audience. I wanted a great book for geek kids that taught real programming in a real programming language.

      Thanks for your input!

    4. As a guy who found out he loved programming at the age of eight, hacking away on my Dad’s Commodore Vic20, I must say I disagree with you. If the enjoyment of pounding out a good algorithm is there, then the fact that it isn’t a pile of eye candy means nothing.

  3. My 8 year old and I have been playing around with programming and he’ll love this. Thanks!

  4. If you really believe in the need for a 3D book, why not write it?

    Thank you for making this book available. I am planning on sitting down with my daughter and getting her started along the path that I myself started down soo many years ago.

  5. Dewi: I can’t disagree more.

    I just finished teaching a group of six twelve year olds Python programming and focusing on text based concepts (at first) is the right thing to do. Kids these days spend their whole life in a GUI world now. Spending some time in a stripped down text environment really allowed my students to focus.

    When I resume class after the summer we will be using the Panda3D engine. It mostly does what DarkBasic but its free and Python based.

    1. Thanks for the pointer to Panda3D: this may be exactly what I was calling for, an open source 3D simplifier :) I’ll check it out.

      Good to see you teaching graphics programming early on, and even covering 3D stuff, though I still feel it’s simple enough that a five line rotating cube program can easily be the second program they write after “hello world”. 2D’s even easier.

      Like many, I was scared off from programming graphics and UIs for a very long time exactly because all the pedagogical resources treated it as something hard, to be dealt with only in advanced courses, at the end of the book, and so on.

      It’s not. Graphics coding is almost trivial, and kids need to know that. And that sounds like what you’re teaching: you showed them 2D graphics, and I’d be willing to bet that the moment they got their first sprite moving around the screen is the point when the class really came *alive*.

      Text I/O is an entirely different paradigm: it needs no fast sync loop, blocking calls are OK, and there’s no realtime input. For [i]games programming[/i], those concepts need to be there from day one.

      Even “hello world” contains a game loop, though people porting it to other languages forget the importance of “20 GOTO 10”.

      If someone was teaching a course on text programming, then it’d be deceptive of them to claim that they’re teaching “games programming” instead of just “programming”. Even with a couple of chapters of graphics tacked onto the end, they just aren’t teaching the skills that elevate someone from “programmer” to “games programmer”.

      Kind of like teaching a “real time programming” course, then only covering time constraints in the last class. That’s not RTP, that’s just programming with an RTP element added in.

      REM Animate a HelloWorld object.
      LOAD OBJECT “HelloWorld.x”, 1

      Bingo. Trivial. And so very, very empowering. A few more lines and you’ve got yourself a “shoot the HelloWorld” game.

  6. I like the hands on programming style of learning. Writing programs can be a lot of fun and who can resist building big and better programs. The book seems to cover every thing I could possibly imagine a new programmer needs to know. I think this is a great start book and plan to buy one for my nephew.

    other good places to start are:

  7. Tis freakin awesome to see this on BB! Al presented his book a couple days ago at the San Francisco PyGame meetup and at least three of us simultaneously thought of Cory and Boing Boing.

    Python is nearly the perfect first language. It looks like executable pseudocode. Hello world is one line: print “hello world” Lists and dictionaries are incredibly simple. Python has decorators, classes, and lots of other object oriented goodness. It has the 2nd largest library (with Java being the first).

    As for coding Artificial Intelligence, the simplest and easiest implementation of Eliza that I’ve ever run across is written in Python.

    That’s Python: easy to get started with no limits to expressiveness.

  8. Fantastic! I work in a 3rd-5th grade computer lab and I’ll definitely be looking into this. Last year we were going to use Scratch but we never got around to it. Based on what I was able to accomplish with it I think only my 5th graders could handle in and probably not even all of them. Thanks for the post.


  9. funny enough, 3d do not add extra programming, but it sure do add extra graphics work. Iirc, the big game companies today employ more artists then they employ programmers, and often reuse a generic engine (the unreal series of engines seems to be quite popular) in several projects.

  10. I’m definitely going to go though this book. I’ve been trying to teach myself Python, but almost every text I’ve found assumes quite a bit of previous software engineering experience.

    In addition to the other suggestions being thrown around, Unity ( is a great free 3d engine. Can’t recommend it enough if you just want to get in and start making something instead of writing tons of foundation code before anything even shows up on screen.

  11. This is great. I remember spending time with GW-BASIC-based games and its line-based editor, as well as Apple BASIC; starting with Python would definitely build better habits.

    And for the people demanding a 3D version: really, you’re going to introduce programming concepts and that much geometry all at once, at the age of, say, 10. Yeah. Wouldn’t it be better to teach ’em about 2D collision detection first? Or are you planning on handing them some crippled environment that makes building 3D games easy but teaches them almost nothing?

    1. GW-BASIC FTW! I was a 5th-grade home schooled kid that attended a community programming course at the local community college. We learned how to create a simple text-based game… in mine, you had to get a flashlight from one room before you could see in another (ah, the power of global variables… it was so not OO :).

      Then my folks got me an Apple ][e. Programming at a young age changed my life.

      Now my son has been begging me to teach him LUA, since that’s what Roblox uses. I haven’t had the time lately :(, but man have I been searching for a good book I can send his way.

  12. Dewi has a good point, though. What if a 12-year-old kid says they want to be an engineer when they grow up? I mean, they want to build real things NOW, not learn basic math and science first. They might get bored or distracted!

    I say cut ’em loose and let them design some deep water drilling rigs. What could go wrong?

  13. Wow – I am SO looking forward to reading this book and doing some good old programming! When I was a kid I was heavy, heavy, HEAVY into programming with BASIC. I LOVED it. Yes, I was a serious geek about it. Cool to see that there is something similar in modern times. And I love to see this kind of thing made for kids. If it hadn’t have been for BASIC when I was young, I don’t know that I would understand software as well as I do today (and therefore I probably wouldn’t have the awesome job I have administering a bunch of various systems). Cool beans!

  14. Hi Al! It’s Tess, we met at Noise Bridge the other day. Exciting to see your work up on here, congratulations!

  15. Thanks so much for posting this! I’m teaching my 9 yr old daughter Python and this is a great resource!

  16. I’ve been leisurely going through the book these last couple months. While it may be for kids , it certainly is accessible to someone like myself with zero programming experience.

    Its great!

  17. I remember having a wonderful BASIC programming book for kids in which dinosaurs explained how it all works. Really loved it and it probably made me the webdeveloper I am today.

  18. That’s very awesome but I agree with some of the others that python is arguably not the best choice for a variety of reasons.

    I also agree that you need pretty pictures. My friends and I learned on Apple II, Atari 800, C64 and we spent all our time making our stuff look good. That was state of the art then. Today state of the art is Modern Warfare 2 or Uncharted 2. You can’t expect **most** kids to find old school stuff fun.

    I remember these books and I loved them back when they came out but that was all brand new stuff back then. It’s not new anymore anymore, it’s old.

    Kids might not need AAA title art but they do need more than those old titles provide to keep their interest. Watch the video about The Secret Powers of Time above.

Comments are closed.