Book Image

Python Game Programming By Example

By : Alejandro Rodas de Paz, Joseph Howse
Book Image

Python Game Programming By Example

By: Alejandro Rodas de Paz, Joseph Howse

Overview of this book

With a growing interest in learning to program, game development is an appealing topic for getting started with coding. From geometry to basic Artificial Intelligence algorithms, there are plenty of concepts that can be applied in almost every game. Python is a widely used general-purpose, high-level programming language. It provides constructs intended to enable clear programs on both a small and large scale. It is the third most popular language whose grammatical syntax is not predominantly based on C. Python is also very easy to code and is also highly flexible, which is exactly what is required for game development. The user-friendliness of this language allows beginners to code games without too much effort or training. Python also works with very little code and in most cases uses the “use cases” approach, reserving lengthy explicit coding for outliers and exceptions, making game development an achievable feat. Python Game Programming by Example enables readers to develop cool and popular games in Python without having in-depth programming knowledge of Python. The book includes seven hands-on projects developed with several well-known Python packages, as well as a comprehensive explanation about the theory and design of each game. It will teach readers about the techniques of game design and coding of some popular games like Pong and tower defense. Thereafter, it will allow readers to add levels of complexities to make the games more fun and realistic using 3D. At the end of the book, you will have added several GUI libraries like Chimpunk2D, cocos2d, and Tkinter in your tool belt, as well as a handful of recipes and algorithms for developing games with Python.
Table of Contents (9 chapters)
8
Index

Creating game assets

We will need a few basic images for our cocos2d sprites. They will be the visual representations of the player's cannon and the different types of aliens.

The following image shows how these sprites can be drawn with an image editor program, with the help of a grid:

Creating game assets

Unfortunately, the usage of image manipulation tools is beyond the scope of this book. There is a wide variety in these programs, and for basic sprites (such as the ones shown in the previous image), you can use MS Paint on Windows systems.

Under the img folder, you can find the different images that we will use in our game. Feel free to edit them and change their colors. However, do not modify their size as it is used to determine the width and the height of the Sprite and its Cshape member.

Tip

Creating your own "pixel art"

There are more advanced applications that can be run on any platform. This is the case of GIMP, an open source program that is part of the GNU project. The sprites used in...