--- /dev/null
+""" 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]