Skip to main content
main-content
Top

About this book

Beginning Python Games Development, Second Edition teaches you how to create compelling games using Python and the PyGame games development library. It will teach you how to create visuals, do event handling, create 3D games, add media elements, and integrate OpenGL into your Python game.

In this update to the first ever book to cover the popular open source PyGame games development library, you'll stand to gain valuable technical insights and follow along with the creation of a real-world, freely downloadable video game. Written by industry veterans and Python experts Will McGugan and Harrison Kinsley, this is a comprehensive, practical introduction to games development in Python. You can also capitalize upon numerous tips and tricks the authors have accumulated over their careers creating games for some of the world's largest game developers.

Table of Contents

Chapter 1. Introducing Python

Abstract
The programming language that we are going to use to create games is Python, which gets its name because the original author of the language was a fan of the UK television series Monty Python. While we will be using Python to create games, the language is a general-purpose programming language that is used for things like data analysis, robotics, creating websites, and much more. Companies and agencies such as Google, NASA, and Instagram rely heavily on Python.
Harrison Kinsley, Will McGugan

Chapter 2. Exploring Python

Abstract
In the previous chapter we entered our Python code a line at a time, but now we are going to put the interactive interpreter to the side and start creating Python files. In this chapter we will cover more of the building blocks of Python code, and show you how to use classes to help with creating games. We will also explain how to use the code libraries that come with all installations of Python.
Harrison Kinsley, Will McGugan

Chapter 3. Introducing Pygame

Abstract
Have you ever opened up your computer and had a look inside the case? No need to do it now, but you will find that it is built from a number of parts necessary to deliver your computing experience. The video card generates an image and sends a signal to your monitor. The sound card mixes sound together and sends audio to your speakers. Then there are the input devices, such as the keyboard, mouse, and joystick(s), and a variety of other electronic gizmos—all of which are essential in making a game.
Harrison Kinsley, Will McGugan

Chapter 4. Creating Visuals

Abstract
Computer games are very visual in nature, and game developers spend a lot of time working on manipulating graphics and refining the visuals to create the most entertaining experience for the player. This chapter gives you a strong foundation in generating visuals for computer games.
Harrison Kinsley, Will McGugan

Chapter 5. Making Things Move

Abstract
In the real world, objects move in a variety of different ways, depending on what they are doing, and a game must approximate those motions to create a convincing virtual representation. A few games can get away with unrealistic motion—Pac-Man, for example, moves in a straight line with a constant speed and can change direction in an instant, but if you applied that kind of motion to a car in a driving game it would destroy the illusion. After all, in a driving game you would expect the car to take some time to reach full speed and it definitely shouldn’t be able to turn 180 degrees in an instant!
Harrison Kinsley, Will McGugan

Chapter 6. Accepting User Input

Abstract
There are a variety of ways that the player can interact with a game, and this chapter covers the various input devices in detail. In addition to retrieving information from the devices, we will also explore how to translate what the player does into meaningful events in the game. This is extremely important for any game—regardless of how good a game looks and sounds, it must also be easy to interact with.
Harrison Kinsley, Will McGugan

Chapter 7. Take Me to Your Leader

Abstract
Placing a player character in a convincing world is only part of creating a game. To make a game fun, you need to present the player with a number of challenges. These may come in the form of traps and obstacles, but to really entertain your players you need to have them interact with non-player characters (NPCs)—characters that appear to act with a degree of intelligence or awareness in the game. The process of creating these NPCs is called artificial intelligence (AI). In this chapter, we will explore some simple techniques that you can use to give your game characters a life of their own.
Harrison Kinsley, Will McGugan

Chapter 8. Moving into the Third Dimension

Abstract
Games generally try to mimic the real world, or create a world that is not so far from reality that the player will still in some way be able to identify with it. In the past this required a real leap of faith on behalf of the player because technology wasn’t yet capable of creating visuals that looked much like reality. But as the technology advanced, game designers began to push the hardware to create more convincing graphics.
Harrison Kinsley, Will McGugan

Chapter 9. Exploring the Third Dimension

Abstract
You’ve seen how to take a point in three-dimensional space and project it onto the screen so that it can be rendered. Projection is only part of the process of rendering a 3D scene; you also need to manipulate the points in the game to update the scene from frame to frame. This chapter introduces the matrix, which is a kind of mathematical shortcut used to manipulate the position and orientation of objects in a game.
Harrison Kinsley, Will McGugan

Chapter 10. Making Things Go Boom

Abstract
Sound is an essential component of any game as it gives instant feedback from the virtual world. If you were to play a game with the audio turned down, you would likely find it a very passive experience because we expect events to be accompanied by sound.
Harrison Kinsley, Will McGugan

Chapter 11. Lights, Camera, Action!

Abstract
In Chapters 8 and 9, you learned how to manipulate 3D information and use OpenGL to display simple models. In this chapter we will cover how to work with images to create more visually appealing scenes. We will also discuss how to read a 3D model from a file, which is an important step in creating a polished game.
Harrison Kinsley, Will McGugan

Chapter 12. Setting the Scene with OpenGL

Abstract
You’ve come quite far with OpenGL, having learned how to render and manipulate objects in a 3D scene. In this chapter, we will cover lighting in more detail and introduce you to other OpenGL features that will help you to add polish to your game.
Harrison Kinsley, Will McGugan

Appendix A. Game Object Reference

Abstract
This appendix documents some of the most fundamental classes in the Game Objects library that provide a toolbox for creating 2D and 3D games. For up-to-date information regarding Game Objects, see https://github.com/PythonProgramming/Beginning-Game-Development-with-Python-and-Pygame .
Harrison Kinsley, Will McGugan

Appendix B. Packaging Your Game

Abstract
If you have gone to the effort of writing a game with Pygame, you will likely want to share your masterpiece with others. The simplest way to distribute your game is to bundle your Python code and data as a compressed archive file, such as ZIP, TAR, or GZIP, and upload it to your website or send it via e-mail. The problem with this approach is that Python and any external modules you use must be installed before your game can be played, which makes code distributions suitable only for other Python programmers. To distribute your game to a wider, nontechnical audience, you will need to package your game in a familiar way for your chosen platform(s).
Harrison Kinsley, Will McGugan
Additional information