Mercurial > fife-parpg
annotate demos/shooter/scripts/scene.py @ 477:6b33d80b468b
Projectiles are now part of the scene.
Cleaned up the scene update() function.
Moved garbage collection to the beginning of the frame.
Introduced global object types.
Projectiles now only check for collisions in a limited number of scene nodes rather than the entire screen.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 22 Apr 2010 19:52:34 +0000 |
parents | 78a1eb57c074 |
children | 41f7754f2a4b |
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 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
25 from scripts.ships.shipbase import * |
446
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() |
476
78a1eb57c074
Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
475
diff
changeset
|
55 self._objectstodelete = list() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
57 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
|
58 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
|
59 |
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._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
|
61 self._timedelta = 0 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
62 self._lasttime = 0 |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
63 |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
64 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
|
65 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
|
66 |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
67 self._paused = False |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
68 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
|
69 |
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
|
70 self._gameover = False |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
71 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
72 def destroyScene(self): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
73 nodestodelete = list() |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
74 objtodelete = list() |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
75 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
76 for node in self._nodes: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
77 nodestodelete.append(node) |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
78 for obj in node.spaceobjects: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
79 objtodelete.append(node) |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
80 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
81 for obj in objtodelete: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
82 if obj in node.spaceobjects: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
83 node.spaceobjects.remove(obj) |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
84 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
85 objtodelete = list() |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
86 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
87 for node in nodestodelete: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
88 if node in self._nodes: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
89 self._nodes.remove(node) |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
90 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
91 self.removeAllProjectiles() |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
92 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
93 def initScene(self, mapobj): |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
94 #initialize our scene array to some arbitrary size |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
95 for i in range(0,self._maxnodes): |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
96 self._nodes.append(SceneNode()) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
97 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
98 self._player = Player(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
|
99 self._player.init() |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
100 self._player.start() |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
101 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
102 enemies = list() |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
103 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
104 temp = self._layer.getInstances('dodge1') |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
105 enemies.extend(temp) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
106 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
107 temp = self._layer.getInstances('dodge2') |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
108 enemies.extend(temp) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
109 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
110 temp = self._layer.getInstances("diag_top_right") |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
111 enemies.extend(temp) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
112 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
113 temp = self._layer.getInstances("diag_bottom_right") |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
114 enemies.extend(temp) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
115 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
116 temp = self._layer.getInstances("streaker") |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
117 enemies.extend(temp) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
118 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
119 temp = self._layer.getInstances("boss") |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
120 enemies.extend(temp) |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
121 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
122 for instance in enemies: |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
123 objectName = instance.getId() |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
124 print objectName |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
125 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
126 if objectName == "dodge1": |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
127 enemy = Saucer1(self, 'enemy', instance, False) |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
128 elif objectName == "dodge2": |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
129 enemy = Saucer2(self, 'enemy', instance, False) |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
130 elif objectName == "diag_top_right": |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
131 enemy = DiagSaucer(self, 'enemy', 0, instance, False) |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
132 elif objectName == "diag_bottom_right": |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
133 enemy = DiagSaucer(self, 'enemy', 1, instance, False) |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
134 elif objectName == "streaker": |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
135 enemy = Streaker(self, 'enemy', instance, False) |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
136 elif objectName == "boss": |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
137 enemy = Boss(self, 'enemy', instance, False) |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
138 else: |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
139 enemy = Ship(self, 'enemy', instance, False) |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
140 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
141 enemy.start() |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
142 |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
143 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
|
144 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
|
145 enemy.scenenodeid = nodeindex |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
146 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
|
147 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
148 #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
|
149 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
|
150 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
151 self.startCamera() |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
152 |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
153 def pause(self, time): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
154 self._pausedtime = time |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
155 self._paused = True |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
156 |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
157 def unpause(self, time): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
158 self._timemod += time - self._pausedtime |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
159 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
|
160 |
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
|
161 def playerHit(self, damage): |
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
|
162 self._player.applyHit(damage) |
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
|
163 |
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
|
164 def gameOver(self): |
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
|
165 self._gameover = True |
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
|
166 self._world.gameOver() |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
167 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
168 def endLevel(self): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
169 self._world.endLevel() |
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
|
170 |
476
78a1eb57c074
Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
475
diff
changeset
|
171 def queueObjectForRemoval(self, obj): |
78a1eb57c074
Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
475
diff
changeset
|
172 self._objectstodelete.append(obj) |
78a1eb57c074
Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
475
diff
changeset
|
173 |
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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 |
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
|
180 for p in projtodelete: |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
181 if p in self._projectiles: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
182 self._projectiles.remove(p) |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
183 |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
184 def getObjectsInNode(self, nodeindex): |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
185 return self._nodes[nodeindex].instances |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
186 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
187 def getObjectsInRange(self, rangeL, rangeR): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
188 objects = list() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
189 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
190 for i in range(rangeL, rangeR): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
191 objects.extend(self._nodes[i].spaceobjects) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
192 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
193 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
|
194 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
195 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
|
196 #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
|
197 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
|
198 nodeindex = int(loc.x * self._xscale) |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
199 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
200 if nodeindex >= 0: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
201 obj.scenenodeid = nodeindex |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
202 self._nodes[nodeindex].spaceobjects.append(obj) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
203 else: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
204 self.queueObjectForRemoval(obj) |
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
|
205 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
210 if nodeindex >= 0: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
211 if nodeindex != obj.scenenodeid: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
212 if obj in self._nodes[obj.scenenodeid].spaceobjects: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
213 self._nodes[obj.scenenodeid].spaceobjects.remove(obj) |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
214 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
215 self._nodes[nodeindex].spaceobjects.append(obj) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
216 |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
217 obj.scenenodeid = nodeindex |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
218 else: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
219 self.queueObjectForRemoval(obj) |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
220 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
221 def removeObjectFromScene(self, obj): |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
222 for node in self._nodes: |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
223 if obj in node.spaceobjects: |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
224 if obj.instance: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
225 self._layer.deleteInstance(obj.instance) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
226 obj.instance = None |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
227 node.spaceobjects.remove(obj) |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
228 break |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
229 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 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
|
231 self._camera = cam |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 self._camera.setLocation(self._player.location) |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
233 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
234 def stopCamera(self): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
235 self._cameraspeed = 0 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
237 def startCamera(self): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
238 self._cameraspeed = 0.001 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
239 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
240 def update(self, time, keystate): |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
241 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
|
242 self._timedelta = timedelta |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
243 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
|
244 |
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 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
|
246 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
247 |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
248 #some garbage cleanup |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
249 for obj in self._objectstodelete: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
250 self.removeObjectFromScene(obj) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
251 |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
252 self._objectstodelete = list() |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
253 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
254 #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
|
255 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
|
256 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
|
257 #slowly move to the right |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
258 exactloc.x += timedelta * self._cameraspeed |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
259 loc.setExactLayerCoordinates(exactloc) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
260 self._camera.setLocation(loc) |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
261 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
262 topleft = self._camera.toMapCoordinates(fife.ScreenPoint(0,0)) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
263 bottomright = self._camera.toMapCoordinates(fife.ScreenPoint(1024,768)) |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
264 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
265 #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
|
266 leftnode = int(topleft.x) |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
267 rightnode = int(bottomright.x) + 1 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
268 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
269 #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
|
270 if leftnode < 0: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
271 leftnode = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
272 if rightnode > self._maxnodes: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
273 rightnode = self._maxnodes |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
274 screenlist = self.getObjectsInRange(leftnode, rightnode) |
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
|
275 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
276 #update objects on the screen |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
277 for obj in screenlist: |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
278 if obj.type == SHTR_LASTBOSS: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
279 if bottomright.x > ((obj.location.getExactLayerCoordinates().x * self._xscale) + 0.5): |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
280 self.stopCamera() |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
281 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
282 if not (obj.type == SHTR_PLAYER and self._gameover): |
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
|
283 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
|
284 |
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
|
285 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
|
286 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
|
287 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
288 if obj.type != SHTR_PLAYER and obj.type != SHTR_PROJECTILE: |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
289 if obj.running and obj.boundingbox.intersects(self._player.boundingbox): |
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
|
290 #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
|
291 #re-initialize scene |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
458
diff
changeset
|
292 if not self._player.invulnerable: |
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
|
293 #collision damage of 1 |
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
|
294 self.playerHit(1) |
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
|
295 obj.applyHit(1) |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
296 |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
297 elif obj.type == SHTR_PROJECTILE: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
298 #could probably just get the nodes in the projectiles scenenode. |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
299 #use a range to be sure. |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
300 pcollide = self.getObjectsInRange(obj.scenenodeid - 1, obj.scenenodeid + 1) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
301 |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
302 for o in pcollide: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
303 #cant get hit by your own bullet |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
304 if obj.owner != o and o.type != SHTR_PROJECTILE: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
305 if o.running and obj.boundingbox.intersects(o.boundingbox): |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
306 if o != self._player and obj.owner.type == SHTR_PLAYER: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
307 o.applyHit(obj.damage) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
308 #check if enemy ship was destroyed |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
309 if not o.running: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
310 self._player.applyScore(o.scorevalue) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
311 obj.destroy() |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
312 elif o == self._player: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
313 #player got hit by a projectile |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
314 if not self._player.invulnerable: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
315 self.playerHit(obj.damage) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
316 obj.destroy() |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
317 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
318 #queue list of projectiles to remove (ttl expired or has been destroyed) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
319 if not obj.running: |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
320 self.queueObjectForRemoval(obj) |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
321 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
322 # self._world.renderBoundingBox(obj) |
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
476
diff
changeset
|
323 |
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
|
324 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
325 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
326 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
|
327 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
|
328 |
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
|
329 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
|
330 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
|
331 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
332 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
|
333 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
|
334 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
335 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
|
336 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
|
337 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
338 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
|
339 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
|
340 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
341 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
|
342 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
|
343 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
452
diff
changeset
|
344 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
|
345 return self._timedelta |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
346 |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
347 def _getPaused(self): |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
348 return self._paused |
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
349 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 timedelta = property(_getTimeDelta) |
455
e686b82d93d0
Added the ability to pause the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
357 paused = property(_getPaused) |