annotate demos/shooter/scripts/ships/enemies.py @ 470:3b04e921c93d

Added the fireball projectile. Added a new ship images for the boss. Some enemies now shoot directly at the player.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 14 Apr 2010 19:15:27 +0000
parents 4d0aa75a82f1
children 7a79dc2a0592
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):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
35 if action.getId() == 'explode':
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
36 self._ship.removeFromScene()
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
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):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
43 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
44 self._ship.removeFromScene()
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
45 self._ship.endLevel()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
46 elif action.getId() == 'flash':
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
47 if self._ship._flashnumber > 0:
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
48 self._ship.instance.act('flash', self._ship.instance.getFacingLocation())
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
49 self._ship._flashnumber -= 1
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
50 else:
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
51 self._ship._flashing = False
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
52
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 class Saucer1(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
54 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
55 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
56 self._instance = instance
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 self._time = 500
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
59 self.width = 0.2
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 self.height = 0.075
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 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
62
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
63 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
64 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
65
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
66 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
67
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.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
69 self.scorevalue = 50
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
71 def update(self):
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 if self._dir == 1:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
73 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
74 elif self._dir == 0:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
75 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
76
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 if self._time >= 1000:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 if self._dir == 1:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 elif self._dir == 0:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 self._dir = 1
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 self._time = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
85 self._time += self._scene.timedelta
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
87 super(Saucer1, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
88
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
89 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
90
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 class Saucer2(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
93 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
94 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
95 self._instance = instance
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
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
111 def update(self):
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 if self._dir == 1:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
113 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
114 elif self._dir == 0:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
115 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
116
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 if self._time >= 2000:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 if self._dir == 1:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 elif self._dir == 0:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 self._dir = 1
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 self._time = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
125 self._time += self._scene.timedelta
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
127 super(Saucer2, self).update()
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
128
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
129 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
130
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
131 class DiagSaucer(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
132 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
133 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
134 self._instance = instance
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
135 self.width = 0.2
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
136 self.height = 0.075
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
137
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
138 if direction == 0:
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
139 self._ythrust = 0.25
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
140 else:
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
141 self._ythrust = -0.25
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
142
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
143 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
144 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
145
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
146 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
147
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.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
149 self.scorevalue = 50
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
150
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
151 def update(self):
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
152 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
153 super(DiagSaucer, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
154
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
155 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
156
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
157
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
158 class Streaker(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
159 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
160 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
161 self._instance = instance
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
162 self.width = 0.2
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
163 self.height = 0.2
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
164
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
165 self._maxvelocity = 2.0
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
166
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
167 self.weapon = FireBall(self._scene, self, 2000)
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
168 self.weapon.projectilevelocity = 0.25
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
169
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
170 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
171
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.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
173 self.scorevalue = 150
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
174
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
175 def update(self):
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
176 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
177 super(Streaker, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
178
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
179 playerloc = self._scene.player.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
180 enemyloc = self.location.getExactLayerCoordinates()
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.x -= enemyloc.x
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
183 playerloc.y -= enemyloc.y
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 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
186
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
187
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
188 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
189 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
190 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
191 self._instance = instance
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
192 self.width = 0.85
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
193 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
194
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
195 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
196
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
197 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
198 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
199
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
200 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
201
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
202 self.hitpoints = 20
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.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
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 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
206 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
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 update(self):
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
209 super(Boss, self).update()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
210
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
211 playerloc = self._scene.player.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
212 bossloc = self.location.getExactLayerCoordinates()
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.x -= bossloc.x
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
215 playerloc.y -= bossloc.y
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 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
218
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 def applyHit(self, hp):
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
221 self.flash(2)
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
222 super(Boss, self).applyHit(hp)