Mercurial > fife-parpg
annotate demos/shooter/scripts/scene.py @ 452:f07d779362da
Added different enemy types which behave differently.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 03 Apr 2010 19:19:33 +0000 |
parents | f463ab431cc0 |
children | cf53848fb187 |
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 |
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
|
30 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
31 class SceneNode(object): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
32 def __init__(self, spaceobjects = None): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
33 if not spaceobjects: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
34 self._spaceobjects = list() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
35 else: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
36 self._spaceobjects = spaceobjects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
37 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
38 def _getObjects(self): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
39 return self._spaceobjects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
40 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
41 def _setObjects(self, spaceobjects): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
42 self._spaceobjects = spaceobjects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
43 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
44 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
|
45 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 class Scene(object): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 def __init__(self, engine, objectLayer): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 self._engine = engine |
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 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 self._player = Player(self._model, 'player', self._layer) |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
54 self._player.width = 0.075 |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
55 self._player.height = 0.075 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
56 self._player.start() |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
57 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 self._projectiles = list() |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 self._lasttime = 0 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
61 self._maxnodes = 128 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
62 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
63 def initScene(self, mapobj): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
64 layer = mapobj.getLayer('objects') |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
65 xscale = layer.getCellGrid().getXScale() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
66 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
67 enemies = layer.getInstances('enemy') |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
68 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
69 #initialize our scene array to some arbitrary size |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
70 for i in range(0,self._maxnodes): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
71 self._nodes.append(SceneNode()) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
72 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
73 for instance in enemies: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
74 objectName = instance.getObject().getId() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
75 print objectName |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
76 |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
77 if objectName == "saucer1": |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
78 enemy = Saucer1(self._model, 'enemy', self._layer, False) |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
79 elif objectName == "saucer2": |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
80 enemy = Saucer2(self._model, 'enemy', self._layer, False) |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
81 else: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
82 enemy = Ship(self._model, 'enemy', self._layer, False) |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
83 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
84 enemy.instance = instance |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
85 enemy.start() |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
86 |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
87 loc = instance.getLocation().getExactLayerCoordinates() |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
88 nodeindex = int(loc.x * xscale) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
89 self._nodes[nodeindex].spaceobjects.append(enemy) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
90 |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
91 def getObjectsInNode(self, nodeindex): |
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
92 return self._nodes[nodeindex].instances |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
93 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
94 def getObjectsInRange(self, rangeL, rangeR): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
95 objects = list() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
96 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
97 for i in range(rangeL, rangeR): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
98 objects.extend(self._nodes[i].spaceobjects) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
99 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
100 return objects |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
101 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
102 def removeObjectFromScene(self, obj): |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
103 for node in self._nodes: |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
104 if obj in node.spaceobjects: |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
105 node.spaceobjects.remove(obj) |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
106 return |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
107 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 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
|
109 self._camera = cam |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 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
|
111 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 def _getPlayer(self): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 return self._player |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 def update(self, time, keystate): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 timedelta = time - self._lasttime |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 self._lasttime = time |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 #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
|
120 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
|
121 exactloc = self._camera.getLocation().getExactLayerCoordinates() |
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
|
122 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
|
123 loc.setExactLayerCoordinates(exactloc) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 self._camera.setLocation(loc) |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
125 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
126 topleft = self._camera.toMapCoordinates(fife.ScreenPoint(0,0)) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
127 bottomright = self._camera.toMapCoordinates(fife.ScreenPoint(1024,768)) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
128 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
129 #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
|
130 leftnode = int(topleft.x) |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
131 rightnode = int(bottomright.x) + 1 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
132 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
133 #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
|
134 if leftnode < 0: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
135 leftnode = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
136 if rightnode > self._maxnodes: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
137 rightnode = self._maxnodes |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
138 screenlist = self.getObjectsInRange(leftnode, rightnode) |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
139 |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
140 #update objects on the screen |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
141 for obj in screenlist: |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
142 obj.update(timedelta) |
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
|
143 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
144 #update the player |
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
|
145 self._player.update(timedelta, keystate, self._camera) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 #update the list of projectiles |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
148 projtodelete = list() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 for p in self._projectiles: |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
150 p.update(timedelta) |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
151 #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
|
152 for o in screenlist: |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
153 if p.boundingbox.intersects(o.boundingbox): |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
154 self._player.applyScore(100) |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
155 p.destroy() |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
156 o.destroy() |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
157 self.removeObjectFromScene(o) |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
158 |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
159 #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
|
160 if not p.running: |
450
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
161 projtodelete.append(p) |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
162 |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
163 #remove any non running projectiles |
ba6817013343
Added score keeping ability.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
449
diff
changeset
|
164 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
|
165 self._projectiles.remove(p) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 #fire the currently selected gun |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 if keystate['SPACE']: |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 prjct = self._player.fire(time) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 if prjct: |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 self._projectiles.append(prjct) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 player = property(_getPlayer) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 |