annotate demos/shooter/scripts/scene.py @ 448:5e2ec84902a7

Did a little re-factoring. Introduced the scene graph for collision detection. Changed the time scale to be accurate.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 01 Apr 2010 17:03:34 +0000
parents 64676ea55472
children 1cf56403347a
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
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 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
28
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
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):
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 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
47 self._engine = engine
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 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
49 self._layer = objectLayer
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
50 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
51
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 self._player = Player(self._model, 'player', self._layer)
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self._projectiles = list()
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 self._lasttime = 0
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
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
57
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
58 def initScene(self, mapobj):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
59 layer = mapobj.getLayer('objects')
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
60 xscale = layer.getCellGrid().getXScale()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
61
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
62 enemies = layer.getInstances('enemy')
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
63
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
64 #initialize our scene array to some arbitrary size
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
65 for i in range(0,self._maxnodes):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
66 self._nodes.append(SceneNode())
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
67
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
68 for instance in enemies:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
69 loc = instance.getLocation().getExactLayerCoordinates()
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 objectName = instance.getObject().getId()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
72 print objectName
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
73
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
74 enemy = Ship(self._model, 'enemy', self._layer, False)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
75 enemy.instance = instance
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
76
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
77 nodeindex = int(loc.x * xscale)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
78 self._nodes[nodeindex].spaceobjects.append(enemy)
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 def getObjectsInNode(self, node):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
81 return self._nodes[node].instances
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
82
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
83 def getObjectsInRange(self, rangeL, rangeR):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
84 objects = list()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
85
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
86 for i in range(rangeL, rangeR):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
87 objects.extend(self._nodes[i].spaceobjects)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
88
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
89 return objects
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
90
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
91 def checkCollision(self, instance1, instance2):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
92 pos1 = instnace1.getLocation().getExactLayerCoordinates()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
93 pos2 = instnace2.getLocation().getExactLayerCoordinates()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
94
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
95
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
96
446
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 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
98 self._camera = cam
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 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
100
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 def _getPlayer(self):
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 return self._player
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 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
105 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
106 self._lasttime = time
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 #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
109 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
110 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
111 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
112 loc.setExactLayerCoordinates(exactloc)
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 self._camera.setLocation(loc)
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
114
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
115 topleft = self._camera.toMapCoordinates(fife.ScreenPoint(0,0))
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
116 bottomright = self._camera.toMapCoordinates(fife.ScreenPoint(1024,768))
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
117
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
118 leftnode = int(topleft.x)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
119 rightnode = int(bottomright.x) + 1
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
120
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
121 if leftnode < 0:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
122 leftnode = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
123 if rightnode > self._maxnodes:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
124 rightnode = self._maxnodes
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 447
diff changeset
125 collisionlist = self.getObjectsInRange(leftnode, rightnode)
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
126
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
127 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
128
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 #update the list of projectiles
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 todelete = list()
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 for p in self._projectiles:
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 p.update(time)
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 if not p.running:
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 todelete.append(p)
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 for p in todelete:
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 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
137
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 #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
139 if keystate['SPACE']:
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 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
141 if prjct:
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 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
143
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 player = property(_getPlayer)
2046a1f2f5f2 Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145