Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import system
- # Entities that need animation get an AnimationComponent
- class AnimationComponent(object):
- __slots__ = ('animations', 'enabled')
- def __init__(self, *, animations=[]):
- # List of currently applied (not necessarily running!) animations
- self.animations = animations
- # Enable/disable animations with a single flag (i.e. for pausing the game)
- self.enabled = True
- class AnimationSystem(system.System):
- def __init__(self, mgr):
- super().__init__(mgr)
- # Boilerplate for the main Entity Manager to know how to interact with the AnimationSystem
- self.component = AnimationComponent
- self.component_name = 'Animation'
- # Specifies the priority it gets to run.
- # Different Systems run on different tick rates, but if they occur on the frame update,
- self.priority = 25
- def startup(self):
- super().startup()
- def shutdown(self):
- super().shutdown()
- def update(self, tick):
- # Receive a "tick" which is a time delta from the last game loop
- super().update(tick)
- # For each AnimationComponent and each active animation, update it.
- # self._data is an entity->component lookup table for every System
- entities = [ (entity, self._mgr.get_component(entity,'Render'), animation_comp.animations)
- for entity, animation_comp in self._data.items() if animation_comp.enabled ]
- # Loop over the active animation entities
- for entity, render, animations in entities:
- # Entities may have multiple simultaneous animations, run them in order
- for animation in animations:
- animation.update(tick)
- def handle_event(self, event):
- pass
Add Comment
Please, Sign In to add comment