commit:65edab8337744d230022bb71f20a1be56204ab48
author:Chip Black
committer:Chip Black
date:Sun Jul 27 02:22:36 2008 -0500
parents:91c385ebe24eebf695c24551b1dfdf2621c660c4
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.
diff --git a/Richter/Actor.py b/Richter/Actor.py
line changes: +2/-2
index bc1bb84..672b5b7
--- a/Richter/Actor.py
+++ b/Richter/Actor.py
@@ -1,11 +1,11 @@
 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):

diff --git a/Richter/Level.py b/Richter/Level.py
line changes: +8/-3
index 2c5671f..365780a
--- a/Richter/Level.py
+++ b/Richter/Level.py
@@ -1,3 +1,4 @@
+import sys
 import os
 import imp
 import yaml
@@ -5,7 +6,10 @@ from Collage import Collage
 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"
@@ -32,13 +36,12 @@ class Level:
 		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'):
@@ -58,9 +61,11 @@ class Level:
 
 	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])