commit:0517cbc2c1d9353ef18e5a461fa00580252f8bb8
author:Chip Black
committer:Chip Black
date:Sun Jul 27 15:48:29 2008 -0500
parents:ecd308b1d0473e781737eef4544e4d51a94ad74b
Added Level surface displaying bits, fixed YAML Layer property parsing
diff --git a/Richter/Level.py b/Richter/Level.py
line changes: +35/-27
index 87e4a3a..1e6d984
--- a/Richter/Level.py
+++ b/Richter/Level.py
@@ -30,6 +30,8 @@ class Layer:
 		self.position = (0, 0)
 		self.things = []
 
+		self.drawsurfaces = False
+
 
 	def add(self, thing):
 		self.things.append(thing)
@@ -44,6 +46,18 @@ class Layer:
 			t.update()
 
 
+	def drawSurfaces(self):
+		self.drawsurfaces = True
+
+
+	def hideSurfaces(self):
+		self.drawsurfaces = False
+
+
+	def toggleDrawSurfaces(self):
+		self.drawsurfaces = not self.drawsurfaces
+
+
 	def draw(self):
 		glPushMatrix()
 		if self.scale != 1.0:
@@ -52,6 +66,8 @@ class Layer:
 		self.collage.draw()
 		for t in self.things:
 			t.draw()
+		if self.drawsurfaces and self.surfaces:
+			self.surfaces.draw()
 		glPopMatrix()
 
 
@@ -59,7 +75,6 @@ class Level:
 	def __init__(self, dir):
 		self.layers = []
 		self.position = (0, 0)
-		self.drawsurfaces = False
 		self.env = {}
 
 		self.load(dir)
@@ -77,17 +92,16 @@ class Level:
 			scale = 1.0
 			parallax = 1.0
 
-			print 'Creating layer', layer['name']
 			if layer.has_key('collage'):
 				collage = Collage(os.path.join(dir, 'collages', layer['collage']))
 			if layer.has_key('surfaces'):
 				surfaces = SurfaceSet(os.path.join(dir, 'surfaces', layer['surfaces']))
-			if layer.has_key('properties'):
-				if layer['properties'].has_key('scale'):
-					scale = layer['properties']['scale']
-				if layer['properties'].has_key('parallax'):
-					parallax = layer['properties']['parallax']
+			if layer.has_key('scale'):
+				scale = layer['scale']
+			if layer.has_key('parallax'):
+				parallax = layer['parallax']
 
+			print 'Creating layer', layer['name'], 'with scale=%f, parallax=%f' % (scale, parallax)
 			new_layer = Layer(collage, surfaces, scale, parallax)
 			self.addLayerBack(new_layer)
 
@@ -149,38 +163,32 @@ class Level:
 		self.layers.append(layer)
 
 
-	def setSurfaces(self, datafile):
-		self.surfaces = SurfaceSet(datafile)
-
-
-	def drawSurfaces(self):
-		self.drawsurfaces = True
+	def moveTo(self, x, y):
+		self.position = [x,y]
+		for l in self.layers:
+			l.moveTo(x, y)
 
 
-	def hideSurfaces(self):
-		self.drawsurfaces = False
+	def update(self):
+		for l in self.layers:
+			l.update()
 
 
-	def toggleDrawSurfaces(self):
-		self.drawsurfaces = not self.drawsurfaces
+	def drawSurfaces(self):
+		for l in self.layers:
+			l.drawSurfaces()
 
 
-	def moveTo(self, x, y):
-		self.position = [x,y]
+	def hideSurfaces(self):
 		for l in self.layers:
-			l.moveTo(x, y)
+			l.hideSurfaces()
 
 
-	def update(self):
+	def toggleDrawSurfaces(self):
 		for l in self.layers:
-			l.update()
+			l.toggleDrawSurfaces()
 
 
 	def draw(self):
 		for l in self.layers:
 			l.draw()
-		if self.drawsurfaces:
-			glPushMatrix()
-			glTranslate(-self.position[0], -self.position[1], 0)
-			self.surfaces.draw()
-			glPopMatrix()