Bullet tagging. (Fixes issue #7)
[python-bulletml.git] / bulletml / impl.py
index 358aae1..8f94d55 100644 (file)
@@ -224,6 +224,15 @@ class Action(object):
                     elif type == "relative":
                         self.my = my / frames
 
+            elif isinstance(action, parser.Tag):
+                owner.tags.add(action.tag)
+
+            elif isinstance(action, parser.Untag):
+                try:
+                    owner.tags.remove(action.tag)
+                except KeyError:
+                    pass
+
             elif isinstance(action, parser.Wait):
                 self.wait_frames = action(self.params, rank)
                 break
@@ -246,6 +255,7 @@ class Bullet(object):
     target - object with .x and .y fields for "aim" directions
     vanished - set to true by a <vanish> action
     rank - game difficulty, 0 to 1, default 0.5
+    tags - string tags set by the running actions
 
     Contructor Arguments:
     x, y, direction, speed, target, rank - same as the attributes
@@ -266,6 +276,7 @@ class Bullet(object):
         self.vanished = False
         self.target = target
         self.rank = rank
+        self.tags = set()
         # New bullets reset the parent hierarchy.
         self._actions = [Action(self, None, action, params, rank)
                          for action, params in actions]