Mercurial > fife-parpg
annotate demos/shooter/scripts/scene.py @ 458:e77ebf128a74
Fixed a small bug where projectiles are not updated when it is game over.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 08 Apr 2010 21:26:46 +0000 |
parents | 597b066d5ccb |
children | 302a69c5141d |
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 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 from scripts.ships.shipbase import Ship |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 from scripts.ships.player import Player |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
27 from scripts.ships.enemies import * |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 from scripts.common.helpers import Rect |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
30 class SceneNode(object): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
31 def __init__(self, spaceobjects = None): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
32 if not spaceobjects: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
33 self._spaceobjects = list() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
34 else: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
35 self._spaceobjects = spaceobjects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
36 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
37 def _getObjects(self): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
38 return self._spaceobjects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
39 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
40 def _setObjects(self, spaceobjects): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
41 self._spaceobjects = spaceobjects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
42 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
43 spaceobjects = property(_getObjects, _setObjects) |
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
|
44 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 class Scene(object): |
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
|
46 def __init__(self, world, engine, objectLayer): |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 self._engine = engine |
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
|
48 self._world = world |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 self._model = engine.getModel() |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 self._layer = objectLayer |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
51 self._nodes = list() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
53 self._player = None |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 self._projectiles = list() |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
56 self._maxnodes = 128 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
57 self._xscale = 0 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
58 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
59 self._time = 0 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
60 self._timedelta = 0 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
61 self._lasttime = 0 |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
62 |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
63 self._xscale = self._layer.getCellGrid().getXScale() |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
64 self._yscale = self._layer.getCellGrid().getYScale() |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
65 |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
66 self._paused = False |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
67 self._timemod = 0 |
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 |
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
|
69 self._gameover = False |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
70 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
71 def initScene(self, mapobj): |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
72 self._player = Player(self, 'player') |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
73 self._player.width = 0.075 |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
74 self._player.height = 0.075 |
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
|
75 self._player.init() |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
76 self._player.start() |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
77 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
78 enemies = self._layer.getInstances('enemy') |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
79 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
80 #initialize our scene array to some arbitrary size |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
81 for i in range(0,self._maxnodes): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
82 self._nodes.append(SceneNode()) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
83 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
84 for instance in enemies: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
85 objectName = instance.getObject().getId() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
86 print objectName |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
87 |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
88 if objectName == "saucer1": |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
89 enemy = Saucer1(self, 'enemy', False) |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
90 elif objectName == "saucer2": |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
91 enemy = Saucer2(self, 'enemy', False) |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
92 else: |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
93 enemy = Ship(self, 'enemy', False) |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
94 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
95 enemy.instance = instance |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
96 enemy.start() |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
97 |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
98 loc = instance.getLocation().getExactLayerCoordinates() |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
99 nodeindex = int(loc.x * self._xscale) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
100 enemy.scenenodeid = nodeindex |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
101 self._nodes[nodeindex].spaceobjects.append(enemy) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
102 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
103 #and finally add the player to the scene |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
104 self.addObjectToScene(self._player) |
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
|
105 |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
106 def pause(self, time): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
107 self._pausedtime = time |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
108 self._paused = True |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
109 |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
110 def unpause(self, time): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
111 self._timemod += time - self._pausedtime |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
112 self._paused = False |
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
|
113 |
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
|
114 def playerDied(self): |
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
|
115 self._player.destroy() |
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
|
116 if self._player.lives <= -1: |
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
|
117 self._gameover = True |
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
|
118 self._world.gameOver() |
458
e77ebf128a74
Fixed a small bug where projectiles are not updated when it is game over.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
119 self.removeAllProjectiles() |
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
|
120 return |
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
|
121 |
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
|
122 #TODO: Have to find a better way to do this. If the player |
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
|
123 #dies too many times right at the start of the level he will |
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
|
124 #get pushed past the edge of the map to the left. |
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
|
125 #IDEA: count down to ready player to start again |
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
|
126 oldpos = self._player.location |
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
|
127 pos = oldpos.getExactLayerCoordinates() |
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
|
128 pos.x -= 5 |
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
|
129 oldpos.setExactLayerCoordinates(pos) |
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
|
130 self._player.location = oldpos |
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
|
131 self._camera.setLocation(self._player.location) |
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
|
132 |
458
e77ebf128a74
Fixed a small bug where projectiles are not updated when it is game over.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
133 self.removeAllProjectiles() |
e77ebf128a74
Fixed a small bug where projectiles are not updated when it is game over.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
134 |
e77ebf128a74
Fixed a small bug where projectiles are not updated when it is game over.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
135 def removeAllProjectiles(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
|
136 projtodelete = list() |
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
|
137 for p in self._projectiles: |
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
|
138 p.destroy() |
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
|
139 projtodelete.append(p) |
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
|
140 |
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
|
141 for p in projtodelete: |
458
e77ebf128a74
Fixed a small bug where projectiles are not updated when it is game over.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
142 self._projectiles.remove(p) |
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
|
143 |
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
|
144 def gameOver(self): |
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
|
145 self._world.gameOver() |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
146 |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
147 def getObjectsInNode(self, nodeindex): |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
148 return self._nodes[nodeindex].instances |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
149 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
150 def getObjectsInRange(self, rangeL, rangeR): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
151 objects = list() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
152 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
153 for i in range(rangeL, rangeR): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
154 objects.extend(self._nodes[i].spaceobjects) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
155 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
156 return objects |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
157 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
158 def addObjectToScene(self, obj): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
159 #TODO: search to ensure the object isn't already part of the scene |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
160 loc = obj.instance.getLocation().getExactLayerCoordinates() |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
161 nodeindex = int(loc.x * self._xscale) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
162 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
163 self._nodes[nodeindex].spaceobjects.append(obj) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
164 obj.scenenodeid = nodeindex |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
165 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
166 def addProjectileToScene(self, projectile): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
167 self._projectiles.append(projectile) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
168 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
169 def moveObjectInScene(self, obj): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
170 loc = obj.instance.getLocation().getExactLayerCoordinates() |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
171 nodeindex = int(loc.x * self._xscale) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
172 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
173 if nodeindex != obj.scenenodeid: |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
174 self._nodes[obj.scenenodeid].spaceobjects.remove(obj) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
175 self._nodes[nodeindex].spaceobjects.append(obj) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
176 obj.scenenodeid = nodeindex |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
177 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
178 def removeObjectFromScene(self, obj): |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
179 for node in self._nodes: |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
180 if obj in node.spaceobjects: |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
181 node.spaceobjects.remove(obj) |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
182 return |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
183 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 def attachCamera(self, cam): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 self._camera = cam |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 self._camera.setLocation(self._player.location) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 def update(self, time, keystate): |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
189 timedelta = (time - self._timemod) - self._time |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
190 self._timedelta = timedelta |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
191 self._time = time - self._timemod |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
192 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
193 self._keystate = keystate |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
195 #update camera location |
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
|
196 loc = self._camera.getLocation() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 exactloc = self._camera.getLocation().getExactLayerCoordinates() |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
198 #slowly move to the right |
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
|
199 exactloc.x += timedelta * 0.001 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 loc.setExactLayerCoordinates(exactloc) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 self._camera.setLocation(loc) |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
202 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
203 topleft = self._camera.toMapCoordinates(fife.ScreenPoint(0,0)) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
204 bottomright = self._camera.toMapCoordinates(fife.ScreenPoint(1024,768)) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
205 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
206 #which scene nodes to use to update objects |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
207 leftnode = int(topleft.x) |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
208 rightnode = int(bottomright.x) + 1 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
209 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
210 #get a list of objects on the screen |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
211 if leftnode < 0: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
212 leftnode = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
213 if rightnode > self._maxnodes: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
214 rightnode = self._maxnodes |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
215 screenlist = self.getObjectsInRange(leftnode, rightnode) |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
216 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
217 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
218 #update objects on the screen |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
219 for obj in screenlist: |
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
|
220 if not (obj == self._player and self._gameover): |
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
|
221 obj.update() |
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
|
222 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
223 if obj.changedposition: |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
224 self.moveObjectInScene(obj) |
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
|
225 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
226 if obj != self._player: |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
227 #TODO: enemy should fire weapon in their update function |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
228 obj.fire(fife.DoublePoint(-1,0)) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
229 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
230 if obj.boundingbox.intersects(self._player.boundingbox): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
231 #player touched an enemy. Destroy player and |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
232 #re-initialize scene |
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
|
233 self.playerDied() |
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
|
234 return |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
235 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 #update the list of projectiles |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
238 projtodelete = list() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
239 for p in self._projectiles: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
240 p.update() |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
241 #check to see if the projectile hit any object on the screen |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
242 for o in screenlist: |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
243 #cant get hit by your own bullet |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
244 if p.owner != o: |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
245 if p.boundingbox.intersects(o.boundingbox): |
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
|
246 if o != self._player: |
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
|
247 self._player.applyScore(100) |
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
|
248 p.destroy() |
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
|
249 o.destroy() |
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
|
250 #TODO: the destroy functions should spawn an explosion |
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
|
251 #and also destroy the instance and remove itself from the scene |
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
|
252 self.removeObjectFromScene(o) |
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
|
253 else: |
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
|
254 #player got hit by a projectile |
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
|
255 p.destroy() |
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
|
256 self.playerDied() |
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
|
257 return |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
258 |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
259 #build a list of projectiles to remove (ttl expired) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
260 if not p.running: |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
261 projtodelete.append(p) |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
262 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
263 #remove any expired projectiles |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
264 for p in projtodelete: |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
265 self._projectiles.remove(p) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
266 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
267 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
268 def _getPlayer(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
269 return self._player |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
270 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
271 def _getKeyState(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
272 return self._keystate |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
273 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
274 def _getCamera(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
275 return self._camera |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
276 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
277 def _getObjectLayer(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
278 return self._layer |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
279 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
280 def _getModel(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
281 return self._model |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
282 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
283 def _getTime(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
284 return self._time |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
285 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
286 def _getTimeDelta(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
287 return self._timedelta |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
288 |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
289 def _getPaused(self): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
290 return self._paused |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
291 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
292 player = property(_getPlayer) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
293 keystate = property(_getKeyState) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
294 camera = property(_getCamera) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
295 objectlayer = property(_getObjectLayer) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
296 model = property(_getModel) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
297 time = property(_getTime) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
298 timedelta = property(_getTimeDelta) |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
299 paused = property(_getPaused) |