Mercurial > fife-parpg
annotate demos/shooter/scripts/ships/player.py @ 475:afde89c1d50b
Switched to a damage system. Collisions with objects now cause 1 damage to the player.
When the boss switches weapons it now waits for the weapons firerate value in time to pass before it fires its first burst with the new weapon.
Fixed a little problem with the high score dialog as it operates in modal mode. It now waits for the entire frame to be complete before displaying the dialog box.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 21 Apr 2010 18:20:13 +0000 |
parents | 10aff123c62c |
children | 6b33d80b468b |
rev | line source |
---|---|
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2009 by the FIFE team |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.de |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 from fife import fife |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
25 from scripts.ships.shipbase import * |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
26 from scripts.common.helpers import * |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
27 from scripts.weapons import * |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
30 class PlayerActionListener(ShipActionListener): |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
31 def __init__(self, ship): |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
32 super(PlayerActionListener, self).__init__(ship) |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
33 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
34 def onInstanceActionFinished(self, instance, action): |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
35 super(PlayerActionListener, self).onInstanceActionFinished(instance, action) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
36 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
37 if action.getId() == 'explode': |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
38 self._ship.respawn() |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
39 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
40 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
41 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 class Player(Ship): |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
43 def __init__(self, scene, playerName): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
44 super(Player, self).__init__(scene, playerName) |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
45 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
46 self._score = 0 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
47 self._maxvelocity = 1.5 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
48 self._acceleration = 1.0 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
49 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
50 self.width = 0.22 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
51 self.height = 0.12 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
52 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
53 self._isplayer = True |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
54 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
55 self._actionlistener = PlayerActionListener(self) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
56 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
57 self._lives = 3 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
58 self.init() |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
59 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
60 def init(self): |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
61 self._hitpoints = 2 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
62 self._dead = False |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
63 self._invulnerable = False |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
64 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
65 #give player the default weapon (the cannon) |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
66 self.weapon = Cannon(self._scene, self, 200) |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
67 |
457
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
455
diff
changeset
|
68 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
69 def _getScore(self): |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
70 return self._score |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
72 def respawn(self): |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
73 if self._lives >= 0: |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
74 self.init() |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
75 self.setInvulnerable(1000) |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
76 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
77 campos = self._scene.camera.getLocation().getExactLayerCoordinates() |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
78 location = self.location |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
79 playerpos = location.getExactLayerCoordinates() |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
80 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
81 playerpos.x = campos.x - 6.5 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
82 playerpos.y = campos.y |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
83 location.setExactLayerCoordinates(playerpos) |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
84 self.location = location |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
85 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
86 else: |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
87 self._instance.get2dGfxVisual().setVisible(False) |
475
afde89c1d50b
Switched to a damage system. Collisions with objects now cause 1 damage to the player.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
474
diff
changeset
|
88 self._scene.gameOver() |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
89 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
90 def setInvulnerable(self, milliseconds): |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
91 #50 is defined in the players "flash" animation file |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
92 #2 is the number of frames in the animation |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
93 #TODO: read these values somehow from the animation |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
94 number = (milliseconds / 50) / 2 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
95 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
96 self._invulnerable = True |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
97 self.flash(number) |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
98 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
99 def applyScore(self, sc): |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
100 self._score += sc |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
101 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
102 def applyHit(self, hp): |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
103 if not self._invulnerable and not self._dead: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
104 super(Player, self).applyHit(hp) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
105 if not self._dead: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
106 self.flash(1) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
107 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
108 def destroy(self): |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
109 if not self._invulnerable and not self._dead: |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
110 self._instance.act('explode', self._instance.getFacingLocation()) |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
111 self._dead = True |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
112 self._invulnerable = True |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
113 self._lives -= 1 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
114 |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
115 def fire(self, direction): |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
116 return self._weapon.fire(direction) |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
117 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
118 def update(self): |
457
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
455
diff
changeset
|
119 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
120 NSkey = False |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
121 EWkey = False |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
122 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
123 #player is no longer invulnerable |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
124 if not self._flashing and self._invulnerable and not self._dead: |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
125 self._invulnerable = False |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
126 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 oldpos = self.location |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
129 if not self._dead: |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
130 if self._scene.keystate['UP']: |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
131 self.applyThrust(fife.DoublePoint(0,-1*self._acceleration)) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
132 NSkey = True |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
133 if self._scene.keystate['DOWN']: |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
134 self.applyThrust(fife.DoublePoint(0,self._acceleration)) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
135 NSkey = True |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
136 if self._scene.keystate['LEFT']: |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
137 self.applyThrust(fife.DoublePoint(-1*self._acceleration,0)) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
138 EWkey = True |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
139 if self._scene.keystate['RIGHT']: |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
140 self.applyThrust(fife.DoublePoint(self._acceleration,0)) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
141 EWkey = True |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
142 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
143 if NSkey and not EWkey: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
144 if self._velocity.x != 0: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
145 vel = self._acceleration * cmp(self._velocity.x, 0) * -1 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
146 self.applyThrust(fife.DoublePoint(vel, 0)) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
147 elif EWkey and not NSkey: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
148 if self._velocity.y != 0: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
149 vel = self._acceleration * cmp(self._velocity.y, 0) * -1 |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
150 self.applyThrust(fife.DoublePoint(0, vel)) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
151 elif not NSkey and not EWkey: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
152 self.applyBrake(self._acceleration) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
153 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
154 #fire the currently selected gun |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
155 if self._scene.keystate['SPACE']: |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
156 self.fire(fife.DoublePoint(1,0)) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
158 if self._dead and self._velocity.length() > 0: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
159 self.applyBrake(self._acceleration) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
161 super(Player, self).update() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 #set up the players camera bounds |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 #TODO: grab screen resolution from somewhere |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
165 topleft = self._scene.camera.toMapCoordinates(fife.ScreenPoint(0,0)) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
166 bottomright = self._scene.camera.toMapCoordinates(fife.ScreenPoint(1024,768)) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
170 #add the padding to the edge |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
171 camrect.x += self._boundingBox.w |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
172 camrect.y += self._boundingBox.h |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
173 camrect.w -= 2*self._boundingBox.w |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
174 camrect.h -= 2*self._boundingBox.h |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
176 pos = oldpos.getExactLayerCoordinates() |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
177 |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
178 if not self._boundingBox.intersects(camrect): |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
179 if (self._boundingBox.x + self._boundingBox.w) < camrect.x: |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
180 self._velocity.x = 0 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
181 pos.x += (camrect.x - (self._boundingBox.x + self._boundingBox.w))/self._xscale + 0.03 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
182 pos.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
183 oldpos.setExactLayerCoordinates(pos) |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
184 |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
185 # elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y: |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
186 # pos.x += self._velocity.x * (timedelta/1000.0) |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
187 # oldpos.setExactLayerCoordinates(pos) |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
188 # self._velocity.y = 0 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
189 elif (self._boundingBox.y + self._boundingBox.h) < camrect.y or self._boundingBox.y > (camrect.y + camrect.h): |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
190 pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
191 self._velocity.y = 0 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
192 oldpos.setExactLayerCoordinates(pos) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 else: |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 self._velocity.x = 0 |
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.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
195 self._velocity.y = 0 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 self.location = oldpos |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
199 def _getLives(self): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
200 return self._lives |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
201 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
202 def _getInvulnerable(self): |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
203 return self._invulnerable |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
204 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
205 def _setInvulnerable(self, inv): |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
206 self._invulnerable = inv |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
207 |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
208 score = property(_getScore) |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
209 lives = property(_getLives) |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
210 invulnerable = property(_getInvulnerable, _setInvulnerable) |