annotate demos/shooter/scripts/powerups.py @ 697:ecaa4d98f05f tip

Abstracted the GUI code and refactored the GUIChan-specific code into its own module. * Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring. * GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass. * The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class. * The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged. * Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 18 Jun 2011 00:28:40 -1000
parents 16ceb3228324
children
rev   line source
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # ####################################################################
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 489
diff changeset
4 # Copyright (C) 2005-2010 by the FIFE team
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 489
diff changeset
5 # http://www.fifengine.net
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # This file is part of FIFE.
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 #
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # FIFE is free software; you can redistribute it and/or
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # License as published by the Free Software Foundation; either
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 #
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # This library is distributed in the hope that it will be useful,
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # Lesser General Public License for more details.
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 #
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # License along with this library; if not, write to the
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # Free Software Foundation, Inc.,
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # ####################################################################
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 from fife import fife
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 from scripts.ships.shipbase import SpaceObject
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 from scripts.weapons import *
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 class PowerUp(SpaceObject):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 def __init__(self, scene, powerupName, instance, findInstance=True):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 super(PowerUp, self).__init__(scene, powerupName, findInstance)
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 self.instance = instance
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 self._type = SHTR_POWERUP
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 self.width = 0.025
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 self.height = 0.025
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 def applyPowerUp(self, ship):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 self.destroy()
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 self._scene.queueObjectForRemoval(self)
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 class CannonSpread5PU(PowerUp):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 def __init__(self, scene, powerupName, instance, findInstance=True):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 super(CannonSpread5PU, self).__init__(scene, powerupName, instance, findInstance)
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 self._dir = 0
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 self._time = 1500
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 self._velocity.x = -0.25
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 self._velocity.y = 0
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
50
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 491
diff changeset
51 self._pickupclip = self._scene.soundmanager.createSoundEmitter("sounds/pickup.ogg")
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 def applyPowerUp(self, ship):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 ship.weapon = CannonSpread5(self._scene, ship, 300)
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 491
diff changeset
55 self._pickupclip.play()
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self.destroy()
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self._scene.queueObjectForRemoval(self)
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 def update(self):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 if self._dir == 1:
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 self._velocity.y = -0.25
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 elif self._dir == 0:
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 self._velocity.y = 0.25
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 if self._time >= 3000:
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 if self._dir == 1:
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 self._dir = 0
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 elif self._dir == 0:
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 self._dir = 1
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 self._time = 0
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 self._time += self._scene.timedelta
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 super(CannonSpread5PU, self).update()
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 class ExtraLifePU(PowerUp):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 def __init__(self, scene, powerupName, instance, findInstance=True):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 super(ExtraLifePU, self).__init__(scene, powerupName, instance, findInstance)
489
0324a3533988 Updated the Shooter demo credits.txt file and added the LICENSE file for all media included in the demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
80
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 491
diff changeset
81 self._pickupclip = self._scene.soundmanager.createSoundEmitter("sounds/pickup.ogg")
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 def applyPowerUp(self, ship):
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 ship.lives += 1
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 491
diff changeset
85 self._pickupclip.play()
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 self.destroy()
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 self._scene.queueObjectForRemoval(self)
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 489
diff changeset
88