Mercurial > fife-parpg
comparison demos/shooter/scripts/ships/player.py @ 453:cf53848fb187
Scene now gets updated when an object moves from one node to another.
Player is now part of the scene.
Projectiles can be files by both player and enemies.
Some code cleanup.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 06 Apr 2010 19:12:41 +0000 |
parents | f463ab431cc0 |
children | bd7e8f708adf |
comparison
equal
deleted
inserted
replaced
452:f07d779362da | 453:cf53848fb187 |
---|---|
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 | 27 |
28 | 28 |
29 class Player(Ship): | 29 class Player(Ship): |
30 def __init__(self, model, playerName, layer): | 30 def __init__(self, scene, playerName): |
31 super(Player, self).__init__(model, playerName, layer) | 31 super(Player, self).__init__(scene, playerName) |
32 | 32 |
33 self._score = 0 | 33 self._score = 0 |
34 self._maxvelocity = 1.5 | |
34 | 35 |
35 def _getScore(self): | 36 def _getScore(self): |
36 return self._score | 37 return self._score |
37 | 38 |
38 def applyScore(self, sc): | 39 def applyScore(self, sc): |
39 self._score += sc | 40 self._score += sc |
41 | |
42 def destroy(self): | |
43 print "player has been destroyed!" | |
40 | 44 |
41 def update(self, timedelta, keystate, camera): | 45 def update(self, timedelta): |
42 key = False | 46 key = False |
43 | 47 |
44 oldpos = self.location | 48 oldpos = self.location |
45 | 49 |
46 if keystate['UP']: | 50 if self._scene.keystate['UP']: |
47 self.applyThrust(fife.DoublePoint(0,-0.75), timedelta) | 51 self.applyThrust(fife.DoublePoint(0,-1.5), timedelta) |
48 key = True | 52 key = True |
49 if keystate['DOWN']: | 53 if self._scene.keystate['DOWN']: |
50 self.applyThrust(fife.DoublePoint(0,0.75), timedelta) | 54 self.applyThrust(fife.DoublePoint(0,1.5), timedelta) |
51 key = True | 55 key = True |
52 if keystate['LEFT']: | 56 if self._scene.keystate['LEFT']: |
53 self.applyThrust(fife.DoublePoint(-0.75,0), timedelta) | 57 self.applyThrust(fife.DoublePoint(-1.5,0), timedelta) |
54 key = True | 58 key = True |
55 if keystate['RIGHT']: | 59 if self._scene.keystate['RIGHT']: |
56 self.applyThrust(fife.DoublePoint(0.75,0), timedelta) | 60 self.applyThrust(fife.DoublePoint(1.5,0), timedelta) |
57 key = True | 61 key = True |
62 | |
63 #fire the currently selected gun | |
64 if self._scene.keystate['SPACE']: | |
65 prjct = self.fire(self._scene.time, fife.DoublePoint(1,0)) | |
66 if prjct: | |
67 self._scene.addProjectileToScene(prjct) | |
58 | 68 |
59 if not key and self._velocity.length() > 0: | 69 if not key and self._velocity.length() > 0: |
60 self.applyBrake(0.75, timedelta) | 70 self.applyBrake(1.5, timedelta) |
61 | 71 |
62 super(Player, self).update(timedelta) | 72 super(Player, self).update(timedelta) |
63 | 73 |
64 #set up the players camera bounds | 74 #set up the players camera bounds |
65 #TODO: grab screen resolution from somewhere | 75 #TODO: grab screen resolution from somewhere |
66 topleft = camera.toMapCoordinates(fife.ScreenPoint(0,0)) | 76 topleft = self._scene.camera.toMapCoordinates(fife.ScreenPoint(0,0)) |
67 bottomright = camera.toMapCoordinates(fife.ScreenPoint(1024,768)) | 77 bottomright = self._scene.camera.toMapCoordinates(fife.ScreenPoint(1024,768)) |
68 | 78 |
69 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) | 79 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) |
70 | 80 |
71 #player bounding box | 81 #player bounding box |
72 xscale = self._layer.getCellGrid().getXScale() | 82 xscale = self._layer.getCellGrid().getXScale() |