Hack keyboard behaviour to be different. Also incidently allow rotating in place
[koperkapel.git] / koperkapel / actors / animsurf.py
1 """ Surface-based actor with multiple frames. """
2
3 import random
4 from pgzero.clock import each_tick
5 from .orientatedsurf import OrientatedSurfActor
6
7
8 class AnimatedSurfActor(OrientatedSurfActor):
9     def __init__(self, frames, cycle_dt=0.2, **kw):
10         self._frames = frames
11         self._frame = random.randint(0, len(frames) - 1)
12         self._dt = 0
13         self._cycle_dt = cycle_dt
14         each_tick(self.update)
15         super().__init__(surf=frames[self._frame], **kw)
16
17     def update(self, dt):
18         self._dt += dt
19         while self._dt > self._cycle_dt:
20             self._dt -= self._cycle_dt
21             self._frame += 1
22             self._frame %= len(self._frames)
23         self.surf = self._frames[self._frame]