Programming

Making Games with Python & Pygame by Al Sweigart

Making Games with Python & Pygame by Al Sweigart

This book will teach you how to make graphical computer games in the Python programming language using the Pygame library – Making Games with Python & Pygame

This book assumes you know a little bit about Python or programming in general. If you don’t know how to program, you can learn by downloading the free book “Invent Your Own Computer Games with Python” from http://inventwithpython.com. Or you can jump right into this book and mostly pick it up along the way.

Recommended: Python Notes for Professionals

This book is for the intermediate programmer who has learned what variables and loops are, but now wants to know, “What do actual game programs look like?” There was a long gap after I first learned programming but didn’t really know how to use that skill to make something cool. It’s my hope that the games in this book will give you enough ideas about how programs work to provide a foundation to implement your own games.

Table of Contents

  • Chapter 1 – Installing Python and Pygame
  • Chapter 2 – Pygame Basics
  • Chapter 3 – Memory Puzzle
  • Chapter 4 – Slide Puzzle
  • Chapter 5 – Simulate
  • Chapter 6 – Wormy
  • Chapter 7 – Tetromino
  • Chapter 8 – Squirrel Eat Squirrel
  • Chapter 9 – Star Pusher
  • Chapter 10 – Four Extra Games

WHAT OTHERS ARE READING

About the Contributors

Author

Albert Sweigart (but you can call him Al), is a software developer in San Francisco, California who enjoys bicycling, volunteering, haunting coffee shops, and making useful software. “Making Games with Python & Pygame” is his second book.His first book, “Invent Your Own Computer Games with Python” can be read online at http://inventwithpython.com. He is originally from Houston, Texas. He finally put his University of Texas at Austin computer science degree in a frame. He laughs out loud when watching park squirrels, which makes people think he’s a simpleton.

Errata

If you find any typos, please email them to al@inventwithpython.com. (Apologies in advance if I haven’t posted your errata submission yet or failed to give credit. Please email me to correct this.)

Chapter 2 – Pygame Basics

On page 23, there is the sentence, “Unfortunately, there isn’t a single function you can call that will set a single pixel to a color”. Actually, there is the set_at() and get_at() methods for Surface objects. (Thanks to Ben LeBlanc)

Chapter 3 – Memory Puzzle

Figure 3-3 has the X and Y coordinates for the box coordinates reversed. (Thanks to tile ile)

Line 224 of the memory puzzle program is for coverage in range(BOXSIZE, (-REVEALSPEED) - 1, - REVEALSPEED):, but that second argument ((-REVEALSPEED) - 1) could be simplified to just -1 and the program would work just fine. This isn’t a bug, but the code is kind of confusing.

Chapter 4 – Slide Puzzle

On page 85, there is the sentence, “Much of the code in Wormy is similar to the previous games we’ve looked at, especially the constants being set at the start of the code.” which should actually read, “Much of the code in Slide Puzzle is similar to the previous games we’ve looked at, especially the constants being set at the start of the code.” (Thanks to Ben LeBlanc)

Line 151 of slidePuzzle.py has an extra closing parentheses at the end of the line. (Thanks to Eduardo França)

On page 97, there is “Depending on if the blank space is at the edge of the board, lines 184 to 191 will remove other directional values from the lastMove list. Of the values that are left in lastMove, one of them is randomly selected with a call to random.choice() and returned.” should be “Depending on if the blank space is at the edge of the board, lines 184 to 191 will remove other directional values from the validMoves list. Of the values that are left in validMoves, one of them is randomly selected with a call to random.choice() and returned.” (Thanks to Tyler Mitchell)

On page 100, there is the sentence “Finally, we draw the buttons off to the slide of the screen” which should be “Finally, we draw the buttons off to the sideof the screen” (Thanks to Tyler Michell)

Chapter 5 – Simulate

On page 129, the sentence “We could have left line 47 out entirely” should be “We could have left line 247 out entirely”. (Thanks to C. Whitt)

Chapter 6 – Wormy

On page 131, the sentence “…a new apply randomly appears on the screen.” should be “…a new apple randomly appears on the screen.” (Thanks to C. Whitt)

Chapter 10 – Four Extra Games

On page 305, the sentence “If the player gets board of the colors…” should be “If the player gets bored of the colors…” (Thanks to David Keck)

Please comment as i would love to hear from you

Please Submit your review here