Mercurial > fife-parpg
comparison demos/shooter/scripts/scene.py @ 446:2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 31 Mar 2010 15:40:00 +0000 |
parents | |
children | 64676ea55472 |
comparison
equal
deleted
inserted
replaced
445:f855809822cf | 446:2046a1f2f5f2 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 from fife import fife | |
25 from scripts.ships.shipbase import Ship | |
26 from scripts.ships.player import Player | |
27 from scripts.common.helpers import Rect | |
28 | |
29 class Scene(object): | |
30 def __init__(self, engine, objectLayer): | |
31 self._engine = engine | |
32 self._model = engine.getModel() | |
33 self._layer = objectLayer | |
34 | |
35 self._player = Player(self._model, 'player', self._layer) | |
36 self._projectiles = list() | |
37 self._lasttime = 0 | |
38 | |
39 def attachCamera(self, cam): | |
40 self._camera = cam | |
41 self._camera.setLocation(self._player.location) | |
42 | |
43 def _getPlayer(self): | |
44 return self._player | |
45 | |
46 def update(self, time, keystate): | |
47 timedelta = time - self._lasttime | |
48 self._lasttime = time | |
49 | |
50 self._player.update(timedelta, keystate, self._camera) | |
51 | |
52 #update camera location | |
53 loc = self._player.location | |
54 exactloc = self._camera.getLocation().getExactLayerCoordinates() | |
55 exactloc.x += timedelta * 0.0005 | |
56 loc.setExactLayerCoordinates(exactloc) | |
57 self._camera.setLocation(loc) | |
58 | |
59 #update the list of projectiles | |
60 todelete = list() | |
61 for p in self._projectiles: | |
62 p.update(time) | |
63 if not p.running: | |
64 todelete.append(p) | |
65 for p in todelete: | |
66 self._projectiles.remove(p) | |
67 | |
68 #fire the currently selected gun | |
69 if keystate['SPACE']: | |
70 prjct = self._player.fire(time) | |
71 if prjct: | |
72 self._projectiles.append(prjct) | |
73 | |
74 player = property(_getPlayer) | |
75 |