X-Git-Url: https://git.yukkurigames.com/?p=python-bulletml.git;a=blobdiff_plain;f=bulletml%2Fimpl.py;fp=bulletml%2Fimpl.py;h=f0e8964d806351cd9a2e876db194730da44bc4f9;hp=ca800be7848a15a4799a98e3a4f6835d3a984784;hb=bf5ff1d116840e1330c80894132919ec515596e4;hpb=2af7a59592e4774c3fc9be7202285c44ba9a5c6f diff --git a/bulletml/impl.py b/bulletml/impl.py index ca800be..f0e8964 100644 --- a/bulletml/impl.py +++ b/bulletml/impl.py @@ -23,7 +23,7 @@ class Action(object): """ - def __init__(self, owner, parent, actions, params, rank, repeat=1): + def __init__(self, parent, actions, params, rank, repeat=1): self.actions = actions self.parent = parent self.repeat = repeat @@ -48,6 +48,9 @@ class Action(object): return "%s(pc=%r, actions=%r)" % ( type(self).__name__, self.pc, self.actions) + def Child(self, actions, params, rank, repeat=1): + return type(self)(self, actions, params, rank, repeat) + def vanish(self): """End this action and its parents.""" if self.parent: @@ -117,7 +120,7 @@ class Action(object): if isinstance(action, (parser.ActionDef, parser.ActionRef)): actions, params = action(s_params, rank) - child = self.__class__(owner, self, actions, params, rank) + child = self.__class__(self, actions, params, rank) owner.replace(self, child) child.step(owner, created) break @@ -163,7 +166,7 @@ class Bullet(object): self.tags = set(tags) self.appearance = appearance # New bullets reset the parent hierarchy. - self._actions = [Action(self, None, action, params, rank) + self.actions = [Action(None, action, params, rank) for action, params in actions] @classmethod @@ -178,7 +181,7 @@ class Bullet(object): return ("%s(%r, %r, accel=%r, direction=%r, speed=%r, " "actions=%r, target=%r, appearance=vanished=%r)") % ( type(self).__name__, self.x, self.y, (self.mx, self.my), - self.direction, self.speed, self._actions, self.target, + self.direction, self.speed, self.actions, self.target, self.appearance, self.vanished) @property @@ -208,7 +211,7 @@ class Bullet(object): """ if not self.vanished: return False - for action in self._actions: + for action in self.actions: if not action.finished: return False return True @@ -216,9 +219,9 @@ class Bullet(object): def vanish(self): """Vanish this bullet and stop all actions.""" self.vanished = True - for action in self._actions: + for action in self.actions: action.vanish() - self._actions = [] + self.actions = [] def replace(self, old, new): """Replace an active action with another. @@ -226,11 +229,11 @@ class Bullet(object): This is mostly used by actions internally to queue children. """ try: - idx = self._actions.index(old) + idx = self.actions.index(old) except ValueError: pass else: - self._actions[idx] = new + self.actions[idx] = new def step(self): """Advance by one frame. @@ -242,7 +245,7 @@ class Bullet(object): """ created = [] - for action in self._actions: + for action in self.actions: action.step(self, created) self.px = self.x