annotate demos/shooter/scripts/ships/enemies.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 2851e232a113
children
rev   line source
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
f07d779362da Added different enemy types which behave differently.
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
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # This file is part of FIFE.
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 #
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # FIFE is free software; you can redistribute it and/or
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # License as published by the Free Software Foundation; either
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 #
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # This library is distributed in the hope that it will be useful,
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # Lesser General Public License for more details.
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 #
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # License along with this library; if not, write to the
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # Free Software Foundation, Inc.,
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # ####################################################################
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 from fife import fife
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
25 from scripts.ships.shipbase import *
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
26 from scripts.common.baseobject import *
622
c0c3f64bfc2d * Templatized Rect to extend it's functionality beyond integers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
27 from fife.fife import FloatRect as Rect
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
28 from scripts.weapons import *
647
f2b3512d0e60 * hope this fixes the bug in the shooter demo that causes a crash after killing the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 622
diff changeset
29 from fife.extensions import fife_timer
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
32 class EnemyActionListener(ShipActionListener):
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
33 def __init__(self, ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
34 super(EnemyActionListener, self).__init__(ship)
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
35
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
36 def onInstanceActionFinished(self, instance, action):
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
37 super(EnemyActionListener, self).onInstanceActionFinished(instance, action)
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
38
474
10aff123c62c Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 472
diff changeset
39
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
40 class BossActionListener(ShipActionListener):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
41 def __init__(self, ship):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
42 super(BossActionListener, self).__init__(ship)
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
43
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
44 def onInstanceActionFinished(self, instance, action):
474
10aff123c62c Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 472
diff changeset
45 super(BossActionListener, self).onInstanceActionFinished(instance, action)
10aff123c62c Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 472
diff changeset
46
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
47 if action.getId() == 'explode':
651
2851e232a113 * Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 647
diff changeset
48 self.delayed = fife_timer.delayCall(5000,self._ship.endLevel())
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
49
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
50
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 class Saucer1(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
52 def __init__(self, scene, name, instance, findInstance=True):
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
53 super(Saucer1, self).__init__(scene, name, findInstance)
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
54 self.instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
55 self._type = SHTR_ENEMYSHIP
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self._time = 500
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
58 self.width = 0.2
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 self.height = 0.075
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 self.velocity.x = -0.5
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
61
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
62 self.weapon = Cannon(self._scene, self, 1000)
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
63 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
64
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
65 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
66
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
67 self.hitpoints = 1
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
68 self.scorevalue = 50
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
70 def update(self):
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 if self._dir == 1:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
72 self.applyThrust(fife.DoublePoint(0,-0.5))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 elif self._dir == 0:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
74 self.applyThrust(fife.DoublePoint(0,0.5))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 if self._time >= 1000:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 if self._dir == 1:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 elif self._dir == 0:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 self._dir = 1
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 self._time = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
84 self._time += self._scene.timedelta
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
86 super(Saucer1, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
87
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
88 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
89
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 class Saucer2(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
92 def __init__(self, scene, name, instance, findInstance=True):
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
93 super(Saucer2, self).__init__(scene, name, findInstance)
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
94 self.instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
95 self._type = SHTR_ENEMYSHIP
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 self._time = 1000
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 self.width = 0.2
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 self.height = 0.2
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 self.velocity.x = -0.1
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
101
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
102 self.weapon = Cannon(self._scene, self, 2000)
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
103 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
104
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
105 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
106
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
107 self.hitpoints = 2
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
108 self.scorevalue = 100
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
109
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
110 def applyHit(self, hp):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
111 self.flash(1)
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
112 super(Saucer2, self).applyHit(hp)
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
113
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
114 def update(self):
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 if self._dir == 1:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
116 self.applyThrust(fife.DoublePoint(0,-0.25))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 elif self._dir == 0:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
118 self.applyThrust(fife.DoublePoint(0,0.25))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 if self._time >= 2000:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 if self._dir == 1:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 elif self._dir == 0:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 self._dir = 1
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 self._time = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
128 self._time += self._scene.timedelta
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
130 super(Saucer2, self).update()
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
131
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
132 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
133
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
134 class DiagSaucer(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
135 def __init__(self, scene, name, direction, instance, findInstance=True):
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
136 super(DiagSaucer, self).__init__(scene, name, findInstance)
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
137 self.instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
138 self._type = SHTR_ENEMYSHIP
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
139 self.width = 0.2
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
140 self.height = 0.075
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
141
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
142 if direction == 0:
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
143 self._ythrust = 0.25
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
144 else:
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
145 self._ythrust = -0.25
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
146
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
147 self.weapon = Cannon(self._scene, self, 2000)
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
148 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
149
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
150 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
151
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
152 self.hitpoints = 1
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
153 self.scorevalue = 50
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
154
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
155 def update(self):
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
156 self.applyThrust(fife.DoublePoint(-0.25,self._ythrust))
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
157 super(DiagSaucer, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
158
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
159 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
160
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
161
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
162 class Streaker(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
163 def __init__(self, scene, name, instance, findInstance=True):
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
164 super(Streaker, self).__init__(scene, name, findInstance)
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
165 self.instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
166 self._type = SHTR_ENEMYSHIP
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
167 self.width = 0.2
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
168 self.height = 0.2
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
169
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
170 self._maxvelocity = 2.0
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
171
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
172 self.weapon = FireBall(self._scene, self, 2000)
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
173 self.weapon.projectilevelocity = 0.25
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
174
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
175 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
176
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
177 self.hitpoints = 2
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
178 self.scorevalue = 150
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
179
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
180 def applyHit(self, hp):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
181 self.flash(1)
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
182 super(Streaker, self).applyHit(hp)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
183
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
184 def update(self):
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
185 self.applyThrust(fife.DoublePoint(-0.40,0))
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
186 super(Streaker, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
187
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
188 playerloc = self._scene.player.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
189 enemyloc = self.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
190
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
191 playerloc.x -= enemyloc.x
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
192 playerloc.y -= enemyloc.y
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
193
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
194 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
195
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
196
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
197 class Boss(Ship):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
198 def __init__(self, scene, name, instance, findInstance=True):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
199 super(Boss, self).__init__(scene, name, findInstance)
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
200 self.instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
201 self._type = SHTR_LASTBOSS
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
202 self.width = 0.85
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
203 self.height = 0.25
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
204
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
205 self._maxvelocity = 2.0
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
206
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
207 self.weapon = FireBall(self._scene, self, 1000)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
208 self.weapon.projectilevelocity = 0.5
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
209
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
210 self._actionlistener = BossActionListener(self)
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
211
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
212 self.hitpoints = 30
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
213 self.scorevalue = 1000
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
214
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
215 self._explodclip = self._scene.soundmanager.createSoundEmitter("sounds/bossexplode.ogg")
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
216
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
217 def endLevel(self):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
218 self._scene.endLevel()
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
219
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
220 def update(self):
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
221 super(Boss, self).update()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
222
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
223 playerloc = self._scene.player.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
224 bossloc = self.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
225
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
226 playerloc.x -= bossloc.x
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
227 playerloc.y -= bossloc.y
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
228
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
229 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
230
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
231
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
232 def applyHit(self, hp):
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
233 self.flash(2)
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
234 super(Boss, self).applyHit(hp)
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
235
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
236 if self.hitpoints == 20:
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
237 self.weapon = FireBallBurst(self._scene, self, 2000, 100, 10)
475
afde89c1d50b Switched to a damage system. Collisions with objects now cause 1 damage to the player.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 474
diff changeset
238 self.weapon.lastfired = self._scene.time
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
239
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
240 elif self.hitpoints == 10:
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
241 self.weapon = FireBallSpread(self._scene, self, 2000)
475
afde89c1d50b Switched to a damage system. Collisions with objects now cause 1 damage to the player.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 474
diff changeset
242 self.weapon.lastfired = self._scene.time
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
243