From c9dc996ae2822889c815a9552adb584356f86af8 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 16:52:58 +0200 Subject: [PATCH] Actually add animsurf. --- koperkapel/actors/animsurf.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 koperkapel/actors/animsurf.py diff --git a/koperkapel/actors/animsurf.py b/koperkapel/actors/animsurf.py new file mode 100644 index 0000000..fb9e73a --- /dev/null +++ b/koperkapel/actors/animsurf.py @@ -0,0 +1,23 @@ +""" Surface-based actor with multiple frames. """ + +import random +from pgzero.clock import each_tick +from .orientatedsurf import OrientatedSurfActor + + +class AnimatedSurfActor(OrientatedSurfActor): + def __init__(self, frames, cycle_dt=0.2): + self._frames = frames + self._frame = random.randint(0, len(frames) - 1) + self._dt = 0 + self._cycle_dt = cycle_dt + each_tick(self.update) + super().__init__(surf=frames[self._frame], angle=0) + + def update(self, dt): + self._dt += dt + while self._dt > self._cycle_dt: + self._dt -= self._cycle_dt + self._frame += 1 + self._frame %= len(self._frames) + self.surf = self._frames[self._frame] -- 2.34.1