Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Game Programming By Example

You're reading from   Python Game Programming By Example A pragmatic guide for developing your own games with Python

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785281532
Length 230 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime