comparison 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
comparison
equal deleted inserted replaced
459:302a69c5141d 460:5e1d6e40d19d
31 def __init__(self, scene, playerName): 31 def __init__(self, scene, playerName):
32 super(Player, self).__init__(scene, playerName) 32 super(Player, self).__init__(scene, playerName)
33 33
34 self._score = 0 34 self._score = 0
35 self._maxvelocity = 1.5 35 self._maxvelocity = 1.5
36
37 self.width = 0.22
38 self.height = 0.12
36 39
37 #give player the default weapon (the cannon) 40 #give player the default weapon (the cannon)
38 self.weapon = Cannon(self._scene, self, 200) 41 self.weapon = Cannon(self._scene, self, 200)
39 42
40 self._lives = 3 43 self._lives = 3
103 camrect.x += self._boundingBox.w 106 camrect.x += self._boundingBox.w
104 camrect.y += self._boundingBox.h 107 camrect.y += self._boundingBox.h
105 camrect.w -= 2*self._boundingBox.w 108 camrect.w -= 2*self._boundingBox.w
106 camrect.h -= 2*self._boundingBox.h 109 camrect.h -= 2*self._boundingBox.h
107 110
111 pos = oldpos.getExactLayerCoordinates()
112
108 if not self._boundingBox.intersects(camrect): 113 if not self._boundingBox.intersects(camrect):
109 if (self._boundingBox.x + self._boundingBox.w) < camrect.x: 114 if (self._boundingBox.x + self._boundingBox.w) < camrect.x:
110 #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale 115 self._velocity.x = 0
111 #oldpos.setExactLayerCoordinates(pos) 116 pos.x += (camrect.x - (self._boundingBox.x + self._boundingBox.w))/self._xscale + 0.03
112 self._velocity.x = (self._scene.timedelta * 0.01) / self._xscale 117 pos.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale
118 oldpos.setExactLayerCoordinates(pos)
113 119
114 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y: 120 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y:
115 # pos.x += self._velocity.x * (timedelta/1000.0) 121 # pos.x += self._velocity.x * (timedelta/1000.0)
116 # oldpos.setExactLayerCoordinates(pos) 122 # oldpos.setExactLayerCoordinates(pos)
117 # self._velocity.y = 0 123 # self._velocity.y = 0
124 elif (self._boundingBox.y + self._boundingBox.h) < camrect.y or self._boundingBox.y > (camrect.y + camrect.h):
125 pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
126 self._velocity.y = 0
127 oldpos.setExactLayerCoordinates(pos)
118 else: 128 else:
119 self._velocity.x = 0 129 self._velocity.x = 0
120 self._velocity.y = 0 130 self._velocity.y = 0
121
122
123 131
124 self.location = oldpos 132 self.location = oldpos
125 133
126 def _getLives(self): 134 def _getLives(self):
127 return self._lives 135 return self._lives