The tower defense actors
We will define several classes in the actors.py
module to represent the game objects.
As with our previous game, we will include a base class, from which the rest of the actor classes will inherit:
import cocos.sprite import cocos.euclid as eu import cocos.collision_model as cm class Actor(cocos.sprite.Sprite): def __init__(self, img, x, y): super(Actor, self).__init__(img, position=(x, y)) self._cshape = cm.CircleShape(self.position, self.width * 0.5) @property def cshape(self): self._cshape.center = eu.Vector2(self.x, self.y) return self._cshape
In the Actor
implementation in the previous chapter, when the sprite was displaced by calling the move()
method, both cshape
and position
were updated at the same time. However, ...
Get Python Game Programming By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.