commit:ca9d57f5ac3b1750f2424ac5d8e1623f5e91f1cc
author:Chip Black
committer:Chip Black
date:Mon Jul 7 06:36:32 2008 -0500
parents:7cf90be44ef52b5cd162d0baccea07713fc1085f
Added stage bounding box camera constraints (to be moved into a Camera object later)
diff --git a/Collage.py b/Collage.py
line changes: +4/-0
index ee5bb66..b01d538
--- a/Collage.py
+++ b/Collage.py
@@ -1,12 +1,14 @@
 from Sprite import Sprite
 from OpenGL.GL import *
 from Numeric import array
+import pygame
 
 import TexMan
 
 class Collage:
 	tiles = None
 	displaylist = None
+	bbox = None
 
 	def __init__(self, file):
 		self.parse(file)
@@ -37,6 +39,8 @@ class Collage:
 			args = args[1:]
 			if cmd == 'tilesize':
 				mf = (int(args[0]),int(args[1]))
+			elif cmd == 'bbox':
+				self.bbox = pygame.Rect(0, 0, mf[0] * int(args[0]), mf[1] * int(args[1]))
 			elif cmd == 'texture':
 				if nvertices > 0:	# dump vertex array
 					glVertexPointer(3, GL_FLOAT, 0, array(vertexarray,'f'))

diff --git a/Stage.py b/Stage.py
line changes: +1/-0
index b6afc2b..71af6e9
--- a/Stage.py
+++ b/Stage.py
@@ -13,6 +13,7 @@ class Layer:
 	def __init__(self, collage, scale=1.0, parallax=1.0):
 		if collage:
 			self.collage = Collage(collage)
+			self.bbox = self.collage.bbox
 		self.scale = scale
 		self.parallax = parallax
 		self.position = (0, 0)

diff --git a/data/example1 b/data/example1
line changes: +1/-0
index 3f776a0..0386278
--- a/data/example1
+++ b/data/example1
@@ -1,4 +1,5 @@
 tilesize 64 64
+bbox 19 7
 texture img/block.png
 tile 0 0
 tile 1 0

diff --git a/platformtest.py b/platformtest.py
line changes: +16/-1
index c9d9ac7..057739f
--- a/platformtest.py
+++ b/platformtest.py
@@ -130,7 +130,22 @@ def update():
 	richter.update()
 	if richter.position[1] < 0:
 		richter.position = [richter.position[0],480]
-	stage.moveTo(richter.position[0] - resolution[0]/2, richter.position[1] - resolution[1]/4)
+	stagepos = [richter.position[0] - resolution[0]/2, richter.position[1] - resolution[1]/4]
+
+	### Stage bounding box stuff should be moved upstream
+	# This is a wee bit confusing since Rects assume (0,0) in the upper
+	# left, but we want it in the lower left.  Flip tops and bottoms.
+	if main.bbox.height < resolution[1] or stagepos[1] < main.bbox.top:
+		stagepos[1] = main.bbox.top
+	elif stagepos[1] + resolution[1] > main.bbox.bottom:
+		stagepos[1] = main.bbox.bottom - resolution[1]
+
+	if main.bbox.width < resolution[0] or stagepos[0] < main.bbox.left:
+		stagepos[0] = main.bbox.left
+	elif stagepos[0] + resolution[0] > main.bbox.right:
+		stagepos[0] = main.bbox.right- resolution[0]
+
+	stage.moveTo(stagepos[0], stagepos[1])
 
 
 n = 0