O'Reilly logo

Python Game Programming By Example by Joseph Howse, Alejandro Rodas de Paz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Game scene

The game layer contains several attributes for holding the reference to the HUD layer, the scenario, and the game information, such as the score or the number of points that can be spent to build new turrets.

These classes are added to the gamelayer module, which has contained only the game over transition so far:

class GameLayer(cocos.layer.Layer): def __init__(self, hud, scenario): super(GameLayer, self).__init__() self.hud = hud self.scenario = scenario self.score = self._score = 0 self.points = self._points = 40 self.turrets = [] w, h = director.get_window_size() cell_size = 32 self.coll_man = cm.CollisionManagerGrid(0, w, 0, h, cell_size, cell_size) self.coll_man_slots = cm.CollisionManagerGrid(0, w, 0, h, cell_size, cell_size) for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required