diff demos/shooter/scripts/ships/player.py @ 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
line wrap: on
line diff
--- 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):