comparison demos/shooter/scripts/ships/player.py @ 447:64676ea55472

Added the ability to set the scale of the object layer. Tweaked the player controls a little bit. A little more work needs to be done to keep the player within the bounds of the camera.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 31 Mar 2010 21:13:07 +0000
parents 2046a1f2f5f2
children 5e2ec84902a7
comparison
equal deleted inserted replaced
446:2046a1f2f5f2 447:64676ea55472
35 key = False 35 key = False
36 36
37 oldpos = self.location 37 oldpos = self.location
38 38
39 if keystate['UP']: 39 if keystate['UP']:
40 self.applyThrust(fife.DoublePoint(0,-0.075)) 40 self.applyThrust(fife.DoublePoint(0,-0.075), timedelta)
41 key = True 41 key = True
42 if keystate['DOWN']: 42 if keystate['DOWN']:
43 self.applyThrust(fife.DoublePoint(0,0.075)) 43 self.applyThrust(fife.DoublePoint(0,0.075), timedelta)
44 key = True 44 key = True
45 if keystate['LEFT']: 45 if keystate['LEFT']:
46 self.applyThrust(fife.DoublePoint(-0.075,0)) 46 self.applyThrust(fife.DoublePoint(-0.075,0), timedelta)
47 key = True 47 key = True
48 if keystate['RIGHT']: 48 if keystate['RIGHT']:
49 self.applyThrust(fife.DoublePoint(0.075,0)) 49 self.applyThrust(fife.DoublePoint(0.075,0), timedelta)
50 key = True 50 key = True
51 51
52 if not key and self._velocity.length() > 0: 52 if not key and self._velocity.length() > 0:
53 self.applyBrake(0.075) 53 self.applyBrake(0.075)
54 54
57 #set up the players camera bounds 57 #set up the players camera bounds
58 #TODO: grab screen resolution from somewhere 58 #TODO: grab screen resolution from somewhere
59 topleft = camera.toMapCoordinates(fife.ScreenPoint(0,0)) 59 topleft = camera.toMapCoordinates(fife.ScreenPoint(0,0))
60 bottomright = camera.toMapCoordinates(fife.ScreenPoint(1024,768)) 60 bottomright = camera.toMapCoordinates(fife.ScreenPoint(1024,768))
61 61
62 #add a little padding to the left edge
63 topleft.x += 0.1
64
65 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) 62 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y)
66 63
67 #player bounding box 64 #player bounding box
68 #TODO: make this configurable 65 #TODO: make this configurable
66 xscale = self._layer.getCellGrid().getXScale()
67 yscale = self._layer.getCellGrid().getYScale()
69 pos = self.location.getExactLayerCoordinates() 68 pos = self.location.getExactLayerCoordinates()
70 bbox = Rect() 69 bbox = Rect()
71 bbox.x = pos.x - 0.005 70 bbox.x = pos.x*xscale - 0.175
72 bbox.y = pos.y - 0.005 71 bbox.y = pos.y*yscale - 0.175
73 bbox.w = 0.01 72 bbox.w = 0.25
74 bbox.h = 0.01 73 bbox.h = 0.25
74
75 #add the padding to the edge
76 camrect.x += bbox.w
77 camrect.y += bbox.h
78 camrect.w -= 2*bbox.w
79 camrect.h -= 2*bbox.h
80
75 81
76 if not bbox.intersects(camrect): 82 if not bbox.intersects(camrect):
77 if pos.x < topleft.x: 83 if (bbox.x + bbox.w) < camrect.x:
78 pos.x += timedelta * 0.0005 84 #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale
79 oldpos.setExactLayerCoordinates(pos) 85 #oldpos.setExactLayerCoordinates(pos)
80 self._velocity.x = timedelta * 0.0005 86 self._velocity.x = (timedelta * 0.001) / xscale
87
88 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y:
89 # pos.x += self._velocity.x * (timedelta/1000.0)
90 # oldpos.setExactLayerCoordinates(pos)
91 # self._velocity.y = 0
81 else: 92 else:
82 self._velocity.x = 0 93 self._velocity.x = 0
94 self._velocity.y = 0
83 95
84 self._velocity.y = 0 96
85 97
86 self.location = oldpos 98 self.location = oldpos
87 99