Mercurial > fife-parpg
annotate demos/shooter/scripts/ships/enemies.py @ 475:afde89c1d50b
Switched to a damage system. Collisions with objects now cause 1 damage to the player.
When the boss switches weapons it now waits for the weapons firerate value in time to pass before it fires its first burst with the new weapon.
Fixed a little problem with the high score dialog as it operates in modal mode. It now waits for the entire frame to be complete before displaying the dialog box.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 21 Apr 2010 18:20:13 +0000 |
parents | 10aff123c62c |
children | 6b33d80b468b |
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 # #################################################################### |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2009 by the FIFE team |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.de |
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 * |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 from scripts.common.helpers import Rect |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
27 from scripts.weapons import * |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
462
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
460
diff
changeset
|
30 class EnemyActionListener(ShipActionListener): |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
460
diff
changeset
|
31 def __init__(self, ship): |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
32 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
|
33 |
c4f745a566d6
Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
460
diff
changeset
|
34 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
|
35 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
|
36 |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
472
diff
changeset
|
37 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
42 def onInstanceActionFinished(self, instance, action): |
474
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
472
diff
changeset
|
43 super(BossActionListener, self).onInstanceActionFinished(instance, action) |
10aff123c62c
Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
472
diff
changeset
|
44 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
45 if action.getId() == 'explode': |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
46 self._ship.endLevel() |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
47 |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
48 |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 class Saucer1(Ship): |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
50 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
|
51 super(Saucer1, self).__init__(scene, name, findInstance) |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
52 self._instance = instance |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 self._dir = 0 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 self._time = 500 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
55 self.width = 0.2 |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 self.height = 0.075 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 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
|
58 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
59 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
|
60 self.weapon.projectilevelocity = 0.4 |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
61 |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
62 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
|
63 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
64 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
|
65 self.scorevalue = 50 |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
67 def update(self): |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 if self._dir == 1: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
69 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
|
70 elif self._dir == 0: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
71 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
|
72 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 if self._time >= 1000: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 if self._dir == 1: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 self._dir = 0 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 elif self._dir == 0: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self._dir = 1 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 self._time = 0 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
81 self._time += self._scene.timedelta |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
83 super(Saucer1, self).update() |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
84 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
85 self.fire(fife.DoublePoint(-1,0)) |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
86 |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 class Saucer2(Ship): |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
89 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
|
90 super(Saucer2, self).__init__(scene, name, findInstance) |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
91 self._instance = instance |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 self._dir = 0 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 self._time = 1000 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 self.width = 0.2 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 self.height = 0.2 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 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
|
97 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
98 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
|
99 self.weapon.projectilevelocity = 0.4 |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
100 |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
101 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
|
102 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
103 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
|
104 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
|
105 |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
106 def applyHit(self, hp): |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
107 self.flash(1) |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
108 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
|
109 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
110 def update(self): |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 if self._dir == 1: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
112 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
|
113 elif self._dir == 0: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
114 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
|
115 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 if self._time >= 2000: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 if self._dir == 1: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 self._dir = 0 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 elif self._dir == 0: |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 self._dir = 1 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 self._time = 0 |
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
124 self._time += self._scene.timedelta |
452
f07d779362da
Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
126 super(Saucer2, self).update() |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
127 |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
128 self.fire(fife.DoublePoint(-1,0)) |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
129 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
130 class DiagSaucer(Ship): |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
131 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
|
132 super(DiagSaucer, self).__init__(scene, name, findInstance) |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
133 self._instance = instance |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
134 self.width = 0.2 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
135 self.height = 0.075 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
136 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
137 if direction == 0: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
138 self._ythrust = 0.25 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
139 else: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
140 self._ythrust = -0.25 |
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 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
|
143 self.weapon.projectilevelocity = 0.4 |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
144 |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
145 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
|
146 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
147 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
|
148 self.scorevalue = 50 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
149 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
150 def update(self): |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
151 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
|
152 super(DiagSaucer, self).update() |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
153 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
154 self.fire(fife.DoublePoint(-1,0)) |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
155 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
156 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
157 class Streaker(Ship): |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
158 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
|
159 super(Streaker, self).__init__(scene, name, findInstance) |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
160 self._instance = instance |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
161 self.width = 0.2 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
162 self.height = 0.2 |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
163 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
164 self._maxvelocity = 2.0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
165 |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
166 self.weapon = FireBall(self._scene, self, 2000) |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
167 self.weapon.projectilevelocity = 0.25 |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
168 |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
462
diff
changeset
|
169 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
|
170 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
171 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
|
172 self.scorevalue = 150 |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
173 |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
174 def applyHit(self, hp): |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
175 self.flash(1) |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
470
diff
changeset
|
176 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
|
177 |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
178 def update(self): |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
179 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
|
180 super(Streaker, self).update() |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
181 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
182 playerloc = self._scene.player.location.getExactLayerCoordinates() |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
183 enemyloc = self.location.getExactLayerCoordinates() |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
184 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
185 playerloc.x -= enemyloc.x |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
186 playerloc.y -= enemyloc.y |
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 self.fire(fife.DoublePoint(playerloc.x,playerloc.y)) |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
189 |
467
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
190 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
191 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
|
192 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
|
193 super(Boss, self).__init__(scene, name, findInstance) |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
194 self._instance = instance |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
195 self.width = 0.85 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
196 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
|
197 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
198 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
|
199 |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
200 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
|
201 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
|
202 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
203 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
|
204 |
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
|
205 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
|
206 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
|
207 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
208 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
|
209 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
|
210 |
4d0aa75a82f1
Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
211 def update(self): |
470
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
212 super(Boss, self).update() |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
213 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
214 playerloc = self._scene.player.location.getExactLayerCoordinates() |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
215 bossloc = self.location.getExactLayerCoordinates() |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
216 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
217 playerloc.x -= bossloc.x |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
218 playerloc.y -= bossloc.y |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
219 |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
220 self.fire(fife.DoublePoint(playerloc.x,playerloc.y)) |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
221 |
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 def applyHit(self, hp): |
3b04e921c93d
Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
467
diff
changeset
|
224 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
|
225 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
|
226 |
3164715a0621
Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 |
3164715a0621
Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
471
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 |