X-Git-Url: https://git.yukkurigames.com/?p=python-bulletml.git;a=blobdiff_plain;f=bulletml%2Fimpl.py;fp=bulletml%2Fimpl.py;h=262b7dc4d67f02fcc7429bd4584b22aaa6274ca7;hp=b2a0aaecfe5f86c712c6bf775d5dcb62dd45d6d5;hb=a3105f5ddabb9c6416158a5deadd00fe68ad87a3;hpb=1b7e588b12fd0885a8c82e9fbd3680a645b7d9bc diff --git a/bulletml/impl.py b/bulletml/impl.py index b2a0aae..262b7dc 100644 --- a/bulletml/impl.py +++ b/bulletml/impl.py @@ -21,8 +21,15 @@ class Action(object): your custom action type. - Pass the impl.Bullet constructor your Action subclass when creating your root Bullet. + + Or, for very simple actions, add it to the Action.CUSTOM + dictionary. The key should be the type of the action and the + value a 3-ary callable that recieves the Action instance, the + owner, and a list to append created bullets to. """ + CUSTOM = {} + def __init__(self, owner, parent, actions, params, rank, repeat=1): self.actions = actions self.parent = parent @@ -78,10 +85,7 @@ class Action(object): owner.speed += self.speed if self.direction_frames > 0: - # The Noiz implementation was a little weird here, I think - # there was a bug in it that prevented it from working if - # the frame count was 1. I'm still not sure what the aim - # check is supposed to do, exactly. + # I'm still not sure what the aim check is supposed to do. self.direction_frames -= 1 if self.aiming and self.direction_frames <= 0: owner.direction += owner.aim @@ -273,7 +277,12 @@ class Action(object): def handle(self, action, owner, created): """Override in subclasses for new action types.""" - raise NotImplementedError(action.__class__.__name__) + try: + handler = self.CUSTOM[type(action)] + except KeyError: + raise NotImplementedError(action.__class__.__name__) + else: + handler(self, owner, created) class Bullet(object): """Simple bullet implementation.