changeset 460:5e1d6e40d19d

Fixed bounding boxes. Added bounding box renderer. The player is now better confined to the screen. Added more enemies to the map.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 09 Apr 2010 21:42:28 +0000
parents 302a69c5141d
children f87f686b5b59
files demos/shooter/maps/shooter_map1.xml demos/shooter/scripts/common/baseobject.py demos/shooter/scripts/scene.py demos/shooter/scripts/ships/enemies.py demos/shooter/scripts/ships/player.py demos/shooter/scripts/ships/shipbase.py demos/shooter/scripts/world.py
diffstat 7 files changed, 109 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/demos/shooter/maps/shooter_map1.xml	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/maps/shooter_map1.xml	Fri Apr 09 21:42:28 2010 +0000
@@ -454,10 +454,15 @@
 			<i r="0" id="diag_bottom_right" x="34.0" o="saucer1" z="0.0" y="8.0"></i>
 			<i r="0" id="diag_bottom_right" x="35.0" o="saucer1" z="0.0" y="9.0"></i>
 			
-			<i r="0" id="streaker" x="37.0" o="saucer1" z="0.0" y="-2.0"></i>
-			<i r="0" id="streaker" x="37.0" o="saucer1" z="0.0" y="1.0"></i>
-			<i r="0" id="streaker" x="37.0" o="saucer1" z="0.0" y="4.0"></i>
-			<i r="0" id="streaker" x="37.0" o="saucer1" z="0.0" y="-5.0"></i>			
+			<i r="0" id="dodge2" x="37.0" o="saucer2" z="0.0" y="-2.0"></i>
+			<i r="0" id="dodge2" x="37.0" o="saucer2" z="0.0" y="1.0"></i>
+			<i r="0" id="streaker" x="37.0" o="saucer2" z="0.0" y="4.0"></i>
+			<i r="0" id="streaker" x="37.0" o="saucer2" z="0.0" y="-5.0"></i>			
+
+		</instances>
+	</layer>
+	<layer y_scale="0.25" y_offset="0.0" pathing="cell_edges_and_diagonals" grid_type="square" id="boundingbox" rotation="0.0" x_scale="0.25" x_offset="0.0" transparency="0">
+		<instances>
 
 		</instances>
 	</layer>
--- a/demos/shooter/scripts/common/baseobject.py	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/common/baseobject.py	Fri Apr 09 21:42:28 2010 +0000
@@ -57,8 +57,8 @@
 			exactloc.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
 			exactloc.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale
 		
-			self._boundingBox.x = (exactloc.x - self._boundingBox.w/2) * self._xscale
-			self._boundingBox.y = (exactloc.y - self._boundingBox.h/2) * self._yscale
+			self._boundingBox.x = (exactloc.x * self._xscale - self._boundingBox.w/2)
+			self._boundingBox.y = (exactloc.y * self._yscale - self._boundingBox.h/2)
 				
 			shiploc.setExactLayerCoordinates(exactloc)
 			
--- a/demos/shooter/scripts/scene.py	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/scene.py	Fri Apr 09 21:42:28 2010 +0000
@@ -74,8 +74,6 @@
 			self._nodes.append(SceneNode())
 
 		self._player = Player(self, 'player')
-		self._player.width = 0.075
-		self._player.height = 0.075
 		self._player.init()
 		self._player.start()
 
@@ -137,7 +135,7 @@
 		if self._player.lives <= -1:
 			self._gameover = True
 			self._world.gameOver()
-			self.removeAllProjectiles()
+			#self.removeAllProjectiles()
 			return
 
 		self._player.setInvulnerable(2)
@@ -240,6 +238,9 @@
 					#re-initialize scene
 					if not self._player.invulnerable:
 						self.playerHit()
+						obj.destroy()
+						
+#			self._world.renderBoundingBox(obj)
 					
 		
 		
@@ -258,12 +259,14 @@
 							o.destroy()
 							#TODO:  the destroy functions should spawn an explosion
 							#and also destroy the instance and remove itself from the scene
-							self.removeObjectFromScene(o)
+							#self.removeObjectFromScene(o)
 						else:
 							#player got hit by a projectile
 							if not self._player.invulnerable:
 								p.destroy()
 								self.playerHit()
+			
+#			self._world.renderBoundingBox(p)
 							
 			
 			#build a list of projectiles to remove (ttl expired)
--- a/demos/shooter/scripts/ships/enemies.py	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/ships/enemies.py	Fri Apr 09 21:42:28 2010 +0000
@@ -32,7 +32,7 @@
 		super(Saucer1, self).__init__(scene, name, findInstance)
 		self._dir = 0
 		self._time = 500
-		self.width = 0.075
+		self.width = 0.2
 		self.height = 0.075
 		self.velocity.x = -0.5
 		
@@ -91,7 +91,7 @@
 	def __init__(self, scene, name, direction, findInstance=True):
 		super(DiagSaucer, self).__init__(scene, name, findInstance)
 		self.width = 0.2
-		self.height = 0.2
+		self.height = 0.075
 		
 		if direction == 0:
 			self._ythrust = 0.25
@@ -109,6 +109,9 @@
 	def __init__(self, scene, name, findInstance=True):
 		super(Streaker, self).__init__(scene, name, findInstance)
 		
+		self.width = 0.2
+		self.height = 0.2		
+		
 		self._maxvelocity = 2.0
 		
 		self.weapon = Cannon(self._scene, self, 2000)
--- a/demos/shooter/scripts/ships/player.py	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/ships/player.py	Fri Apr 09 21:42:28 2010 +0000
@@ -34,6 +34,9 @@
 		self._score = 0
 		self._maxvelocity = 1.5
 		
+		self.width = 0.22
+		self.height = 0.12		
+		
 		#give player the default weapon (the cannon)
 		self.weapon = Cannon(self._scene, self, 200)
 		
@@ -105,22 +108,27 @@
 		camrect.w -= 2*self._boundingBox.w
 		camrect.h -= 2*self._boundingBox.h
 		
+		pos = oldpos.getExactLayerCoordinates()
+		
 		if not self._boundingBox.intersects(camrect):
 			if (self._boundingBox.x + self._boundingBox.w) < camrect.x:
-				#pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale
-				#oldpos.setExactLayerCoordinates(pos)
-				self._velocity.x = (self._scene.timedelta * 0.01) / self._xscale
+				self._velocity.x = 0
+				pos.x += (camrect.x - (self._boundingBox.x + self._boundingBox.w))/self._xscale + 0.03
+				pos.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale
+				oldpos.setExactLayerCoordinates(pos)
 			
 #			elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y:
 #				pos.x += self._velocity.x * (timedelta/1000.0)
 #				oldpos.setExactLayerCoordinates(pos)
 #				self._velocity.y = 0
+			elif (self._boundingBox.y + self._boundingBox.h) < camrect.y or self._boundingBox.y > (camrect.y + camrect.h):
+				pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
+				self._velocity.y = 0
+				oldpos.setExactLayerCoordinates(pos)
 			else:
 				self._velocity.x = 0
 				self._velocity.y = 0
 
-
-
 			self.location = oldpos
 
 	def _getLives(self):
--- a/demos/shooter/scripts/ships/shipbase.py	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/ships/shipbase.py	Fri Apr 09 21:42:28 2010 +0000
@@ -62,6 +62,9 @@
 		self._flashrate = rate * 2
 		self._flashnumber = number * 2
 	
+	def destroy(self):
+		self._scene.removeObjectFromScene(self)
+		super(Ship, self).destroy()
 	
 	def update(self):
 		if self._flashing:
--- a/demos/shooter/scripts/world.py	Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/world.py	Fri Apr 09 21:42:28 2010 +0000
@@ -22,6 +22,7 @@
 # ####################################################################
 
 from fife import fife
+import copy
 import math, random
 from fife.extensions import pychan
 from fife.extensions.pychan import widgets
@@ -71,8 +72,10 @@
 		self._hudwindow.hide()
 
 		self._gameover = GameOverDisplay()
-		self._gameover.hide()		
-	
+		self._gameover.hide()
+		
+		self._genericrenderer = None
+		
 	def showMainMenu(self):
 		if self.scene:
 			self._paused = True
@@ -118,6 +121,67 @@
 		self._gameover.hide()
 		
 		self._starttime = self.timemanager.getTime()
+		
+		self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main'])
+		self._genericrenderer.clearActiveLayers()
+		self._genericrenderer.addActiveLayer(self.map.getLayer('objects'))
+		self._genericrenderer.setEnabled(True)
+
+
+	def renderBoundingBox(self, obj):
+		bbox = copy.copy(obj.boundingbox)
+		
+		#apply the object layer scale
+		bbox.x /= 0.25
+		bbox.y /= 0.25
+		bbox.w /= 0.25
+		bbox.h /= 0.25
+	
+		obj_topleft = fife.ExactModelCoordinate(bbox.x, bbox.y)
+		obj_topright = fife.ExactModelCoordinate(bbox.x + bbox.w, bbox.y)
+		obj_bottomright = fife.ExactModelCoordinate(bbox.x + bbox.w, bbox.y + bbox.h)
+		obj_bottomleft = fife.ExactModelCoordinate(bbox.x, bbox.y + bbox.h)
+		
+		loc_topleft = fife.Location()
+		loc_topleft.setLayer(self.map.getLayer('boundingbox'))
+		loc_topleft.setExactLayerCoordinates(obj_topleft)
+		
+		loc_topright = fife.Location()
+		loc_topright.setLayer(self.map.getLayer('boundingbox'))
+		loc_topright.setExactLayerCoordinates(obj_topright)
+		
+		loc_bottomright = fife.Location()
+		loc_bottomright.setLayer(self.map.getLayer('boundingbox'))
+		loc_bottomright.setExactLayerCoordinates(obj_bottomright)
+		
+		loc_bottomleft = fife.Location()
+		loc_bottomleft.setLayer(self.map.getLayer('boundingbox'))
+		loc_bottomleft.setExactLayerCoordinates(obj_bottomleft)
+		
+		node_topleft = fife.GenericRendererNode(loc_topleft)
+		node_topright = fife.GenericRendererNode(loc_topright)
+		node_bottomright = fife.GenericRendererNode(loc_bottomright)
+		node_bottomleft = fife.GenericRendererNode(loc_bottomleft)
+
+
+		self._genericrenderer.addLine("quads", node_topleft, node_topright, 255, 255, 255)
+		self._genericrenderer.addLine("quads", node_topright, node_bottomright, 255, 255, 255)
+		self._genericrenderer.addLine("quads", node_bottomright, node_bottomleft, 255, 255, 255)
+		self._genericrenderer.addLine("quads", node_bottomleft, node_topleft, 255, 255, 255)
+		
+		#had to do this or it would segfault
+		obj_topleft.thisown = 0
+		obj_topright.thisown = 0
+		obj_bottomright.thisown = 0
+		obj_bottomleft.thisown = 0
+		loc_topleft.thisown = 0
+		loc_topright.thisown = 0
+		loc_bottomright.thisown = 0
+		loc_bottomleft.thisown = 0				
+		node_topleft.thisown = 0
+		node_topright.thisown = 0
+		node_bottomright.thisown = 0
+		node_bottomleft.thisown = 0
 
 	def gameOver(self):
 		self._gameover.show()
@@ -199,6 +263,10 @@
 		"""
 		Called every frame.
 		"""
+	
+		if self._genericrenderer:
+			self._genericrenderer.removeAll("quads")
+
 		
 		if not self.scene:
 			return