commit:c198192398ad49ffae0e53eb37692b23a66acadb
author:Chip Black
committer:Chip Black
date:Sun Jul 27 15:39:48 2008 -0500
parents:c6b7c25cb352bd024be02ca0dfcc6175e258ba3d
Added Level bounding box computation

Changed level YAML format to add arbitrary top-level properties and put
the layers list in a 'level' property.  Modified Level loading to match.
Enabled platformtest Camera bbox bits.
diff --git a/Richter/Level.py b/Richter/Level.py
line changes: +15/-1
index d27a79c..87e4a3a
--- a/Richter/Level.py
+++ b/Richter/Level.py
@@ -4,6 +4,7 @@ import re
 import yaml
 from Collage import Collage
 from Surface import SurfaceSet
+import pygame
 from OpenGL.GL import *
 
 classpath = ['classes']
@@ -66,8 +67,9 @@ class Level:
 
 	def load(self, dir):
 		f = open(os.path.join(dir, 'level.yaml'), 'r')
-		layers = yaml.safe_load(f)
+		level = yaml.safe_load(f)
 		f.close()
+		layers = level['layers']
 
 		for layer in layers:
 			collage = None
@@ -92,6 +94,18 @@ class Level:
 			if layer.has_key('things'):
 				self.compileThings(new_layer, layer['things'])
 
+		# Load or compute level bounding box
+		if level.has_key('bbox'):
+			self.bbox = pygame.Rect(level['bbox'])
+		else:
+			bboxes = filter(None, [c.bbox for c in filter(None, [l.collage for l in self.layers])])
+			if bboxes:
+				self.bbox = bboxes[0]
+				self.bbox.unionall_ip(bboxes[1:])
+			else:
+				self.bbox = None
+		print "Bounding box:", self.bbox
+
 
 	def compileThings(self, layer, things):
 		for (name, t) in things.iteritems():