Mercurial > fife-parpg
annotate demos/shooter/scripts/ships/shipbase.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 | 5ff83f209333 |
children |
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 # #################################################################### |
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:
483
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:
483
diff
changeset
|
5 # http://www.fifengine.net |
446
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 |
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
|
24 from math import sqrt |
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
|
25 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 from fife import fife |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
474
diff
changeset
|
27 from scripts.common.baseobject 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.weapons import Weapon |
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 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
31 class ShipActionListener(fife.InstanceActionListener): |
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:
483
diff
changeset
|
32 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
33 This class is an action listener that listens for instance actions |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
34 that are complete. It is used in this demo to specify what should happen |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
35 after the object has completed flashing or exploding. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
36 |
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:
483
diff
changeset
|
37 There should be an instance of this listener for every ship that you want |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
38 to be removed from the scene after exploding. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
39 """ |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
40 def __init__(self, ship): |
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:
483
diff
changeset
|
41 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
42 @param ship The ship that this actionlistener belongs to. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
43 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
44 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
45 fife.InstanceActionListener.__init__(self) |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
46 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
47 self._ship = ship |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
48 self._ship.instance.addActionListener(self) |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
49 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
50 def onInstanceActionFinished(self, instance, action): |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
51 if action.getId() == 'flash': |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
52 if self._ship._flashing and self._ship._flashnumber > 0: |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
53 self._ship.instance.act('flash', self._ship.instance.getFacingLocation()) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
54 self._ship._flashnumber -= 1 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
55 else: |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
56 self._ship._flashing = False |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
57 self._ship._flashnumber = 0 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
58 |
477
6b33d80b468b
Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
474
diff
changeset
|
59 if action.getId() == 'explode' and not self._ship.type == SHTR_PLAYER: |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
60 self._ship.removeFromScene() |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
61 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
62 class Ship(SpaceObject): |
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:
483
diff
changeset
|
63 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
64 Ship |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
65 |
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:
483
diff
changeset
|
66 This is the base ship object. The Player and Enemy ship classes inherit |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
67 this class. This class extends SpaceObject by allowing Weapons to |
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:
483
diff
changeset
|
68 be attached to the object as well as hit points. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
69 """ |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
70 def __init__(self, scene, name, findInstance=True): |
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:
483
diff
changeset
|
71 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
72 @param scene: A reference to the Scene |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
73 @type scene: L{Scene} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
74 @param name: The name of the ship |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
75 @type name: C{string} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
76 @param findInstance: True if the instance you are looking for is already loaded |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
77 False if you want to load the instance yourself |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
78 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
79 @type findInstance: C{boolean} |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
80 |
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:
483
diff
changeset
|
81 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
82 |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
83 super(Ship, self).__init__(scene, name, findInstance) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
84 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 self._weapon = None |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
86 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
87 self._flashnumber = 0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
88 self._flashing = False |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
89 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
90 self._hitpoints = 0 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
91 self._scorevalue = 0 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
92 |
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
|
93 self._hitclip = self._scene.soundmanager.createSoundEmitter("sounds/hit.ogg") |
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
|
94 self._explodclip = self._scene.soundmanager.createSoundEmitter("sounds/explode.ogg") |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
95 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 def _setWeapon(self, weapon): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 self._weapon = weapon |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
98 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
99 def _getWeapon(self): |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 return self._weapon |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
101 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
461
diff
changeset
|
102 def flash(self, number): |
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:
483
diff
changeset
|
103 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
104 Playes the flash animation (or action) the specified number of times |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
105 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
106 @param number: An integer specifying the number of times to play the flash animation |
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:
483
diff
changeset
|
107 """ |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
108 if self._running: |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
109 self._instance.act('flash', self._instance.getFacingLocation()) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
110 self._flashnumber = number |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
111 self._flashing = True |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
112 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
113 def fire(self, direction): |
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:
483
diff
changeset
|
114 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
115 Fires the current weapon in the specified direction |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
116 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
117 @param direction: A L{fife.DoublePoint()} specifying the direction to fire |
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:
483
diff
changeset
|
118 """ |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
119 if self._weapon and self._hitpoints > 0: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
120 return self._weapon.fire(direction) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
121 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 return None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
123 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
124 def applyHit(self, hp): |
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:
483
diff
changeset
|
125 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
126 Removes the specified number of hit points. Destroys the ship if necessary. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
127 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
128 @param hp: The number of hit points to remove from the ship. |
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:
483
diff
changeset
|
129 """ |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
130 self._hitpoints -= hp |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
131 if self._hitpoints <= 0: |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
132 self.destroy() |
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:
477
diff
changeset
|
133 else: |
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
|
134 self._hitclip.play() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
135 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
136 def destroy(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:
483
diff
changeset
|
137 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
138 Plays the explode animation (or action) |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
483
diff
changeset
|
139 """ |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
140 if self._running: |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
141 self._instance.act('explode', self._instance.getFacingLocation()) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
142 location = self.location.getExactLayerCoordinates() |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
143 self._explodclip.position = (location.x, location.y) |
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
|
144 self._explodclip.play() |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
145 super(Ship, self).destroy() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
146 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
147 def _getHitPoints(self): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
148 return self._hitpoints |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
149 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
150 def _setHitPoints(self, hp): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
151 self._hitpoints = hp |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
152 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
153 def _getScoreValue(self): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
154 return self._scorevalue |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
155 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
156 def _setScoreValue(self, value): |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
157 self._scorevalue = value |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
158 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 weapon = property(_getWeapon, _setWeapon) |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
160 hitpoints = property(_getHitPoints, _setHitPoints) |
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:
483
diff
changeset
|
161 scorevalue = property(_getScoreValue, _setScoreValue) |