Further modifications to support Level loading
YAML level format no longer supports arbitrary class loading; leaving
Sprite support would have complicated things unnecessarily. Now all
level things must be Actor subclasses. (Maybe rename that section to
"actors"?) Level loader automagically loads from the classes directory.
from Sprite import *
class Actor:
- def __init__(self, surfaces=None):
+ def __init__(self, surfaces = None, position = [0,0]):
self.states = {}
self.currentstate = None
self.surfaces = surfaces
- self.position = [0,0]
+ self.position = position
def defineState(self, statename, sprite):
+import sys
import os
import imp
import yaml
from Surface import SurfaceSet
from Stage import Stage, Layer
-classpath = ['classes', 'Richter']
+classpath = ['classes']
+for path in classpath:
+ sys.path.append(path)
+
def findClass(classname):
"A fun bit of metaprogramming, loading a class based on its name"
self.stage = Stage()
for layer in layers:
- print layer
collage = None
surfaces = None
scale = 1.0
parallax = 1.0
- print 'Name:', layer['name']
+ print 'Creating layer', layer['name']
if layer.has_key('collage'):
collage = Collage(os.path.join(dir, 'collages', layer['collage']))
if layer.has_key('surfaces'):
def compileThings(self, layer, things):
for (name, t) in things.iteritems():
+ print "Creating", t['class'], name
c = findClass(t['class'])
properties = {}
if t.has_key('properties'):
properties = t['properties']
+ properties['surfaces'] = layer.surfaces
self.env[name] = c(**properties)
layer.add(self.env[name])