Added event handling support
Actor class now has several (not completely implemented) event handling
stubs, which are filled in by the Level loader.
(collided, delta) = self.moveDelta(delta)
self.position[0] += delta[0]
self.position[1] += delta[1]
+ if collided:
+ self.hitWall()
return collided
+ def hitWall(self):
+ "Called when this object hits a wall after attempting to move"
+ pass
+
+
+ def collideStart(self, obj):
+ "Called when this object begins colliding with another"
+ pass
+
+
+ def collideEnd(self, obj):
+ "Called when this object stops colliding with another"
+ pass
+
+
def update(self):
"Override this function. Called once per frame."
pass
import sys
import os
-import imp
+import re
import yaml
from Collage import Collage
from Surface import SurfaceSet
classpath = ['classes']
sys.path += classpath
+function_re = re.compile('^(\w+)\(([^)]*)\)$')
+
class Layer:
"""Container for layer data.
properties['surfaces'] = layer.surfaces
self.env[name] = eval('%s(**properties)' % t['class'], self.env, {'properties': properties})
+
+ if t.has_key('events'):
+ for (fdef, str) in t['events'].iteritems():
+ m = function_re.match(fdef)
+ if not m:
+ print "Malformed function definition:", fdef
+ continue
+
+ code = "def %s:\n" % m.group(0)
+ for s in str.split("\n"):
+ if not s: continue
+ code += "\t" + s + "\n"
+ code += "%s.%s = %s\n" % (name, m.group(1), m.group(1))
+ code += "del %s\n" % m.group(1)
+ exec code in self.env
layer.add(self.env[name])