comparison demos/shooter/scripts/ships/player.py @ 451:f463ab431cc0

Movement shouldn't be dependent on framerate anymore. Some minor tweaks.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 01 Apr 2010 21:14:23 +0000
parents ba6817013343
children cf53848fb187
comparison
equal deleted inserted replaced
450:ba6817013343 451:f463ab431cc0
27 27
28 28
29 class Player(Ship): 29 class Player(Ship):
30 def __init__(self, model, playerName, layer): 30 def __init__(self, model, playerName, layer):
31 super(Player, self).__init__(model, playerName, layer) 31 super(Player, self).__init__(model, playerName, layer)
32 self._bounds = Rect(-100,-100,200,200) 32
33 self._score = 0 33 self._score = 0
34 34
35 def _getScore(self): 35 def _getScore(self):
36 return self._score 36 return self._score
37 37
42 key = False 42 key = False
43 43
44 oldpos = self.location 44 oldpos = self.location
45 45
46 if keystate['UP']: 46 if keystate['UP']:
47 self.applyThrust(fife.DoublePoint(0,-0.075), timedelta) 47 self.applyThrust(fife.DoublePoint(0,-0.75), timedelta)
48 key = True 48 key = True
49 if keystate['DOWN']: 49 if keystate['DOWN']:
50 self.applyThrust(fife.DoublePoint(0,0.075), timedelta) 50 self.applyThrust(fife.DoublePoint(0,0.75), timedelta)
51 key = True 51 key = True
52 if keystate['LEFT']: 52 if keystate['LEFT']:
53 self.applyThrust(fife.DoublePoint(-0.075,0), timedelta) 53 self.applyThrust(fife.DoublePoint(-0.75,0), timedelta)
54 key = True 54 key = True
55 if keystate['RIGHT']: 55 if keystate['RIGHT']:
56 self.applyThrust(fife.DoublePoint(0.075,0), timedelta) 56 self.applyThrust(fife.DoublePoint(0.75,0), timedelta)
57 key = True 57 key = True
58 58
59 if not key and self._velocity.length() > 0: 59 if not key and self._velocity.length() > 0:
60 self.applyBrake(0.075, timedelta) 60 self.applyBrake(0.75, timedelta)
61 61
62 super(Player, self).update(timedelta) 62 super(Player, self).update(timedelta)
63 63
64 #set up the players camera bounds 64 #set up the players camera bounds
65 #TODO: grab screen resolution from somewhere 65 #TODO: grab screen resolution from somewhere
67 bottomright = camera.toMapCoordinates(fife.ScreenPoint(1024,768)) 67 bottomright = camera.toMapCoordinates(fife.ScreenPoint(1024,768))
68 68
69 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) 69 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y)
70 70
71 #player bounding box 71 #player bounding box
72 #TODO: make this configurable
73 xscale = self._layer.getCellGrid().getXScale() 72 xscale = self._layer.getCellGrid().getXScale()
74 yscale = self._layer.getCellGrid().getYScale() 73 yscale = self._layer.getCellGrid().getYScale()
75 pos = self.location.getExactLayerCoordinates() 74
76 bbox = Rect()
77 bbox.x = pos.x*xscale - 0.175
78 bbox.y = pos.y*yscale - 0.175
79 bbox.w = 0.25
80 bbox.h = 0.25
81 75
82 #add the padding to the edge 76 #add the padding to the edge
83 camrect.x += bbox.w 77 camrect.x += self._boundingBox.w
84 camrect.y += bbox.h 78 camrect.y += self._boundingBox.h
85 camrect.w -= 2*bbox.w 79 camrect.w -= 2*self._boundingBox.w
86 camrect.h -= 2*bbox.h 80 camrect.h -= 2*self._boundingBox.h
87
88 81
89 if not bbox.intersects(camrect): 82 if not self._boundingBox.intersects(camrect):
90 if (bbox.x + bbox.w) < camrect.x: 83 if (self._boundingBox.x + self._boundingBox.w) < camrect.x:
91 #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale 84 #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale
92 #oldpos.setExactLayerCoordinates(pos) 85 #oldpos.setExactLayerCoordinates(pos)
93 self._velocity.x = (timedelta * 0.001) / xscale 86 self._velocity.x = (timedelta * 0.01) / xscale
94 87
95 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y: 88 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y:
96 # pos.x += self._velocity.x * (timedelta/1000.0) 89 # pos.x += self._velocity.x * (timedelta/1000.0)
97 # oldpos.setExactLayerCoordinates(pos) 90 # oldpos.setExactLayerCoordinates(pos)
98 # self._velocity.y = 0 91 # self._velocity.y = 0