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

The scenario definition


Once we have loaded the tile map, we need to link the resulting image with the game information. Our scenario class should contain the following:

  • The positions where the turrets can be placed

  • The position of the bunker

  • The initial position for enemy spawning

  • The path that the enemies must follow to reach the bunker

In the following screenshot, we can see this data overlaid on top of our TMX map:

The rectangles represent the slots in which the player can place the turrets. The scenario stores only the centers of these squares, because the game layer will translate these positions into clickable squares.

The lines over the road represent the path that the enemy tanks must follow. This movement will be implemented by chaining the MoveBy and RotateBy actions. We will define two constants for rotation toward the left or the right, and an auxiliary function that returns a MoveBy action whose duration makes the enemies move uniformly:

import cocos.actions as ac

RIGHT = ac.RotateBy...