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
Actor implementation in the previous chapter, when the sprite was displaced by calling the
move() method, both
position were updated at the same time. However, ...