comparison demos/shooter/scripts/ships/enemies.py @ 467:4d0aa75a82f1

Added damage so some enemies take more than one hit to destroy. Added the boss at the end of the level. For some reason the high score dialog box that appears after the level is completed causes a crash. Still looking into this one.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 14 Apr 2010 16:22:36 +0000
parents ac0f62a07a3e
children 3b04e921c93d
comparison
equal deleted inserted replaced
466:716d44ba42df 467:4d0aa75a82f1
33 33
34 def onInstanceActionFinished(self, instance, action): 34 def onInstanceActionFinished(self, instance, action):
35 if action.getId() == 'explode': 35 if action.getId() == 'explode':
36 self._ship.removeFromScene() 36 self._ship.removeFromScene()
37 37
38 class BossActionListener(ShipActionListener):
39 def __init__(self, ship):
40 super(BossActionListener, self).__init__(ship)
41
42 def onInstanceActionFinished(self, instance, action):
43 if action.getId() == 'explode':
44 self._ship.removeFromScene()
45 self._ship.endLevel()
46
38 class Saucer1(Ship): 47 class Saucer1(Ship):
39 def __init__(self, scene, name, instance, findInstance=True): 48 def __init__(self, scene, name, instance, findInstance=True):
40 super(Saucer1, self).__init__(scene, name, findInstance) 49 super(Saucer1, self).__init__(scene, name, findInstance)
41 self._instance = instance 50 self._instance = instance
42 self._dir = 0 51 self._dir = 0
47 56
48 self.weapon = Cannon(self._scene, self, 1000) 57 self.weapon = Cannon(self._scene, self, 1000)
49 self.weapon.projectilevelocity = 0.4 58 self.weapon.projectilevelocity = 0.4
50 59
51 self._actionlistener = EnemyActionListener(self) 60 self._actionlistener = EnemyActionListener(self)
61
62 self.hitpoints = 1
63 self.scorevalue = 50
52 64
53 def update(self): 65 def update(self):
54 if self._dir == 1: 66 if self._dir == 1:
55 self.applyThrust(fife.DoublePoint(0,-0.5)) 67 self.applyThrust(fife.DoublePoint(0,-0.5))
56 elif self._dir == 0: 68 elif self._dir == 0:
80 92
81 self.weapon = Cannon(self._scene, self, 2000) 93 self.weapon = Cannon(self._scene, self, 2000)
82 self.weapon.projectilevelocity = 0.4 94 self.weapon.projectilevelocity = 0.4
83 95
84 self._actionlistener = EnemyActionListener(self) 96 self._actionlistener = EnemyActionListener(self)
97
98 self.hitpoints = 2
99 self.scorevalue = 100
100
85 101
86 def update(self): 102 def update(self):
87 if self._dir == 1: 103 if self._dir == 1:
88 self.applyThrust(fife.DoublePoint(0,-0.25)) 104 self.applyThrust(fife.DoublePoint(0,-0.25))
89 elif self._dir == 0: 105 elif self._dir == 0:
115 131
116 self.weapon = Cannon(self._scene, self, 2000) 132 self.weapon = Cannon(self._scene, self, 2000)
117 self.weapon.projectilevelocity = 0.4 133 self.weapon.projectilevelocity = 0.4
118 134
119 self._actionlistener = EnemyActionListener(self) 135 self._actionlistener = EnemyActionListener(self)
136
137 self.hitpoints = 1
138 self.scorevalue = 50
120 139
121 def update(self): 140 def update(self):
122 self.applyThrust(fife.DoublePoint(-0.25,self._ythrust)) 141 self.applyThrust(fife.DoublePoint(-0.25,self._ythrust))
123 super(DiagSaucer, self).update() 142 super(DiagSaucer, self).update()
124 143
133 152
134 self.weapon = Cannon(self._scene, self, 2000) 153 self.weapon = Cannon(self._scene, self, 2000)
135 self.weapon.projectilevelocity = 1.0 154 self.weapon.projectilevelocity = 1.0
136 155
137 self._actionlistener = EnemyActionListener(self) 156 self._actionlistener = EnemyActionListener(self)
138 157
158 self.hitpoints = 2
159 self.scorevalue = 150
160
139 def update(self): 161 def update(self):
140 self.applyThrust(fife.DoublePoint(-0.40,0)) 162 self.applyThrust(fife.DoublePoint(-0.40,0))
141 super(Streaker, self).update() 163 super(Streaker, self).update()
164
165 class Boss(Ship):
166 def __init__(self, scene, name, instance, findInstance=True):
167 super(Boss, self).__init__(scene, name, findInstance)
168 self._instance = instance
169 self.width = 0.2
170 self.height = 0.2
171
172 self._maxvelocity = 2.0
173
174 self.weapon = Cannon(self._scene, self, 1000)
175 self.weapon.projectilevelocity = 0.5
176
177 self._actionlistener = BossActionListener(self)
178
179 self.hitpoints = 20
180 self.scorevalue = 1000
181
182 def endLevel(self):
183 self._scene.endLevel()
184
185 def update(self):
186 super(Boss, self).update()