"""
- 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
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:
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
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
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
"""
if not self.vanished:
return False
- for action in self._actions:
+ for action in self.actions:
if not action.finished:
return False
return True
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.
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.
"""
created = []
- for action in self._actions:
+ for action in self.actions:
action.step(self, created)
self.px = self.x
def __call__(self, owner, action, params, rank, created):
repeat = self.times(params, rank)
actions, params = self.action(params, rank)
- child = action.__class__(
- owner, action, actions, params, rank, repeat)
+ child = action.Child(actions, params, rank, repeat)
owner.replace(action, child)
child.step(owner, created)
return True
if branch:
actions, params = branch(params, rank)
- child = action.__class__(owner, action, actions, params, rank)
+ child = action.Child(actions, params, rank)
owner.replace(action, child)
child.step(owner, created)
return True