Mercurial > fife-parpg
comparison demos/shooter/scripts/ships/player.py @ 454:bd7e8f708adf
Time is now managed by the Scene object.
Enemy projectiles are now a bit slower.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 06 Apr 2010 21:25:10 +0000 |
parents | cf53848fb187 |
children | e686b82d93d0 |
comparison
equal
deleted
inserted
replaced
453:cf53848fb187 | 454:bd7e8f708adf |
---|---|
22 # #################################################################### | 22 # #################################################################### |
23 | 23 |
24 from fife import fife | 24 from fife import fife |
25 from scripts.ships.shipbase import Ship | 25 from scripts.ships.shipbase import Ship |
26 from scripts.common.helpers import Rect | 26 from scripts.common.helpers import Rect |
27 from scripts.weapons import * | |
27 | 28 |
28 | 29 |
29 class Player(Ship): | 30 class Player(Ship): |
30 def __init__(self, scene, playerName): | 31 def __init__(self, scene, playerName): |
31 super(Player, self).__init__(scene, playerName) | 32 super(Player, self).__init__(scene, playerName) |
32 | 33 |
33 self._score = 0 | 34 self._score = 0 |
34 self._maxvelocity = 1.5 | 35 self._maxvelocity = 1.5 |
36 | |
37 #give player the default weapon (the cannon) | |
38 self.weapon = Cannon(self._scene, self, 200) | |
35 | 39 |
36 def _getScore(self): | 40 def _getScore(self): |
37 return self._score | 41 return self._score |
38 | 42 |
39 def applyScore(self, sc): | 43 def applyScore(self, sc): |
40 self._score += sc | 44 self._score += sc |
41 | 45 |
42 def destroy(self): | 46 def destroy(self): |
43 print "player has been destroyed!" | 47 print "player has been destroyed!" |
44 | 48 |
45 def update(self, timedelta): | 49 def update(self): |
46 key = False | 50 key = False |
47 | 51 |
48 oldpos = self.location | 52 oldpos = self.location |
49 | 53 |
50 if self._scene.keystate['UP']: | 54 if self._scene.keystate['UP']: |
51 self.applyThrust(fife.DoublePoint(0,-1.5), timedelta) | 55 self.applyThrust(fife.DoublePoint(0,-1.5)) |
52 key = True | 56 key = True |
53 if self._scene.keystate['DOWN']: | 57 if self._scene.keystate['DOWN']: |
54 self.applyThrust(fife.DoublePoint(0,1.5), timedelta) | 58 self.applyThrust(fife.DoublePoint(0,1.5)) |
55 key = True | 59 key = True |
56 if self._scene.keystate['LEFT']: | 60 if self._scene.keystate['LEFT']: |
57 self.applyThrust(fife.DoublePoint(-1.5,0), timedelta) | 61 self.applyThrust(fife.DoublePoint(-1.5,0)) |
58 key = True | 62 key = True |
59 if self._scene.keystate['RIGHT']: | 63 if self._scene.keystate['RIGHT']: |
60 self.applyThrust(fife.DoublePoint(1.5,0), timedelta) | 64 self.applyThrust(fife.DoublePoint(1.5,0)) |
61 key = True | 65 key = True |
62 | 66 |
63 #fire the currently selected gun | 67 #fire the currently selected gun |
64 if self._scene.keystate['SPACE']: | 68 if self._scene.keystate['SPACE']: |
65 prjct = self.fire(self._scene.time, fife.DoublePoint(1,0)) | 69 self.fire(fife.DoublePoint(1,0)) |
66 if prjct: | |
67 self._scene.addProjectileToScene(prjct) | |
68 | 70 |
69 if not key and self._velocity.length() > 0: | 71 if not key and self._velocity.length() > 0: |
70 self.applyBrake(1.5, timedelta) | 72 self.applyBrake(1.5) |
71 | 73 |
72 super(Player, self).update(timedelta) | 74 super(Player, self).update() |
73 | 75 |
74 #set up the players camera bounds | 76 #set up the players camera bounds |
75 #TODO: grab screen resolution from somewhere | 77 #TODO: grab screen resolution from somewhere |
76 topleft = self._scene.camera.toMapCoordinates(fife.ScreenPoint(0,0)) | 78 topleft = self._scene.camera.toMapCoordinates(fife.ScreenPoint(0,0)) |
77 bottomright = self._scene.camera.toMapCoordinates(fife.ScreenPoint(1024,768)) | 79 bottomright = self._scene.camera.toMapCoordinates(fife.ScreenPoint(1024,768)) |
78 | 80 |
79 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) | 81 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) |
80 | 82 |
81 #player bounding box | |
82 xscale = self._layer.getCellGrid().getXScale() | |
83 yscale = self._layer.getCellGrid().getYScale() | |
84 | |
85 | |
86 #add the padding to the edge | 83 #add the padding to the edge |
87 camrect.x += self._boundingBox.w | 84 camrect.x += self._boundingBox.w |
88 camrect.y += self._boundingBox.h | 85 camrect.y += self._boundingBox.h |
89 camrect.w -= 2*self._boundingBox.w | 86 camrect.w -= 2*self._boundingBox.w |
90 camrect.h -= 2*self._boundingBox.h | 87 camrect.h -= 2*self._boundingBox.h |
91 | 88 |
92 if not self._boundingBox.intersects(camrect): | 89 if not self._boundingBox.intersects(camrect): |
93 if (self._boundingBox.x + self._boundingBox.w) < camrect.x: | 90 if (self._boundingBox.x + self._boundingBox.w) < camrect.x: |
94 #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale | 91 #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale |
95 #oldpos.setExactLayerCoordinates(pos) | 92 #oldpos.setExactLayerCoordinates(pos) |
96 self._velocity.x = (timedelta * 0.01) / xscale | 93 self._velocity.x = (self._scene.timedelta * 0.01) / self._xscale |
97 | 94 |
98 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y: | 95 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y: |
99 # pos.x += self._velocity.x * (timedelta/1000.0) | 96 # pos.x += self._velocity.x * (timedelta/1000.0) |
100 # oldpos.setExactLayerCoordinates(pos) | 97 # oldpos.setExactLayerCoordinates(pos) |
101 # self._velocity.y = 0 | 98 # self._velocity.y = 0 |