Book Image

Python Game Programming By Example

Book Image

Python Game Programming By Example

Overview of this book

Table of Contents (14 chapters)
Python Game Programming By Example
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Welcome to Python Game Programming By Example. As hobbyist programmers or professional developers, we may build a wide variety of applications, from large enterprise systems to web applications made with state-of-the-art frameworks. However, game development has always been an appealing topic, maybe simply for creating casual games and not just for high-budget AAA titles.

If you want to explore the different ways of developing games in Python, a language with clear and simple syntax, then this is the book for you. In each chapter, we will build a new game from scratch, using several popular libraries and utilities. By the end of this book, you will be able to quickly create your own 2D and 3D games, and have a handful of Python libraries in your tool belt to choose from.

What this book covers

Chapter 1, Hello, Pong!, details the required software, its installation, and the basic syntax of Python: data structures, control flow statements, object orientation, and so on. It also includes the first game of the book, the classic "Hello, world" game.

Chapter 2, Cocos Invaders, introduces the cocos2d game engine and explains how to build a game similar to Space Invaders to put this knowledge into practice. Here, you learn the basics of collisions, input handling, and scene setup.

Chapter 3, Building a Tower Defense Game, is where you learn to develop a full-fledged game with cocos2d. This game includes some interesting components, such as a HUD and a main menu.

Chapter 4, Steering Behaviors, covers seemingly intelligent movements for autonomous characters. You will be adding these strategies gradually, in different levels of a basic game built with particle systems.

Chapter 5, Pygame and 3D, presents the foundations of 3D and guides you through the basic structure of an OpenGL program.

Chapter 6, PyPlatformer, is where you develop a 3D platformer game with all the techniques learned in the previous chapter.

Chapter 7, Augmenting a Board Game with Computer Vision, introduces the topic of computer vision, which allows software to learn about the real world via a camera. In this chapter, you build a system to analyze a game of checkers (draughts) in real time as players move pieces on a physical board.

What you need for this book

The projects covered in this book assume that you have installed Python 3.4 on a computer with Windows, Mac OS X, or Linux. We also assume that you have included pip during the installation process, since it will be the package manager used to install the required third-party packages.

Who this book is for

If you have ever wanted to create casual games in Python and you wish to explore the various GUI technologies that this language offers, then this is the book for you. This title is intended for beginners in Python with little or no knowledge of game development, and it covers step by step how to build seven different games, from the well-known Space Invaders to a classical 3D platformer.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "For instance, on Ubuntu, you need to install the python3-tk package."

A block of code is set as follows:

new_list = []
for elem in collection:
    if elem is not None:
        new_list.append(elem)

Any command-line input or output is written as follows:

$ python –-version
Python 3.4.3

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Make sure that you check the Tcl/Tk option to include the library."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Additionally, up-to-date example code for Chapter 7, Augmenting a Board Game with Computer Vision, is posted at http://nummist.com/opencv.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/B04505_Graphics.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Additionally, any errata for Chapter 7, Augmenting a Board Game with Computer Vision, will be posted at http://nummist.com/opencv.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.

You can also contact the authors directly. Alejandra Rodas de Paz, author of Chapters 1 to 6, can be reached at . Joseph Howse, author of Chapter 7, can be reached at , and answers to common questions can be found on his website, http://nummist.com/opencv.