comparison 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
comparison
equal deleted inserted replaced
469:5994e61cdebd 470:3b04e921c93d
41 41
42 def onInstanceActionFinished(self, instance, action): 42 def onInstanceActionFinished(self, instance, action):
43 if action.getId() == 'explode': 43 if action.getId() == 'explode':
44 self._ship.removeFromScene() 44 self._ship.removeFromScene()
45 self._ship.endLevel() 45 self._ship.endLevel()
46 46 elif action.getId() == 'flash':
47 if self._ship._flashnumber > 0:
48 self._ship.instance.act('flash', self._ship.instance.getFacingLocation())
49 self._ship._flashnumber -= 1
50 else:
51 self._ship._flashing = False
52
47 class Saucer1(Ship): 53 class Saucer1(Ship):
48 def __init__(self, scene, name, instance, findInstance=True): 54 def __init__(self, scene, name, instance, findInstance=True):
49 super(Saucer1, self).__init__(scene, name, findInstance) 55 super(Saucer1, self).__init__(scene, name, findInstance)
50 self._instance = instance 56 self._instance = instance
51 self._dir = 0 57 self._dir = 0
77 self._time = 0 83 self._time = 0
78 84
79 self._time += self._scene.timedelta 85 self._time += self._scene.timedelta
80 86
81 super(Saucer1, self).update() 87 super(Saucer1, self).update()
88
89 self.fire(fife.DoublePoint(-1,0))
90
82 91
83 class Saucer2(Ship): 92 class Saucer2(Ship):
84 def __init__(self, scene, name, instance, findInstance=True): 93 def __init__(self, scene, name, instance, findInstance=True):
85 super(Saucer2, self).__init__(scene, name, findInstance) 94 super(Saucer2, self).__init__(scene, name, findInstance)
86 self._instance = instance 95 self._instance = instance
115 124
116 self._time += self._scene.timedelta 125 self._time += self._scene.timedelta
117 126
118 super(Saucer2, self).update() 127 super(Saucer2, self).update()
119 128
129 self.fire(fife.DoublePoint(-1,0))
130
120 class DiagSaucer(Ship): 131 class DiagSaucer(Ship):
121 def __init__(self, scene, name, direction, instance, findInstance=True): 132 def __init__(self, scene, name, direction, instance, findInstance=True):
122 super(DiagSaucer, self).__init__(scene, name, findInstance) 133 super(DiagSaucer, self).__init__(scene, name, findInstance)
123 self._instance = instance 134 self._instance = instance
124 self.width = 0.2 135 self.width = 0.2
138 self.scorevalue = 50 149 self.scorevalue = 50
139 150
140 def update(self): 151 def update(self):
141 self.applyThrust(fife.DoublePoint(-0.25,self._ythrust)) 152 self.applyThrust(fife.DoublePoint(-0.25,self._ythrust))
142 super(DiagSaucer, self).update() 153 super(DiagSaucer, self).update()
154
155 self.fire(fife.DoublePoint(-1,0))
156
143 157
144 class Streaker(Ship): 158 class Streaker(Ship):
145 def __init__(self, scene, name, instance, findInstance=True): 159 def __init__(self, scene, name, instance, findInstance=True):
146 super(Streaker, self).__init__(scene, name, findInstance) 160 super(Streaker, self).__init__(scene, name, findInstance)
147 self._instance = instance 161 self._instance = instance
148 self.width = 0.2 162 self.width = 0.2
149 self.height = 0.2 163 self.height = 0.2
150 164
151 self._maxvelocity = 2.0 165 self._maxvelocity = 2.0
152 166
153 self.weapon = Cannon(self._scene, self, 2000) 167 self.weapon = FireBall(self._scene, self, 2000)
154 self.weapon.projectilevelocity = 1.0 168 self.weapon.projectilevelocity = 0.25
155 169
156 self._actionlistener = EnemyActionListener(self) 170 self._actionlistener = EnemyActionListener(self)
157 171
158 self.hitpoints = 2 172 self.hitpoints = 2
159 self.scorevalue = 150 173 self.scorevalue = 150
160 174
161 def update(self): 175 def update(self):
162 self.applyThrust(fife.DoublePoint(-0.40,0)) 176 self.applyThrust(fife.DoublePoint(-0.40,0))
163 super(Streaker, self).update() 177 super(Streaker, self).update()
178
179 playerloc = self._scene.player.location.getExactLayerCoordinates()
180 enemyloc = self.location.getExactLayerCoordinates()
181
182 playerloc.x -= enemyloc.x
183 playerloc.y -= enemyloc.y
184
185 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
186
164 187
165 class Boss(Ship): 188 class Boss(Ship):
166 def __init__(self, scene, name, instance, findInstance=True): 189 def __init__(self, scene, name, instance, findInstance=True):
167 super(Boss, self).__init__(scene, name, findInstance) 190 super(Boss, self).__init__(scene, name, findInstance)
168 self._instance = instance 191 self._instance = instance
169 self.width = 0.2 192 self.width = 0.85
170 self.height = 0.2 193 self.height = 0.25
171 194
172 self._maxvelocity = 2.0 195 self._maxvelocity = 2.0
173 196
174 self.weapon = Cannon(self._scene, self, 1000) 197 self.weapon = FireBall(self._scene, self, 1000)
175 self.weapon.projectilevelocity = 0.5 198 self.weapon.projectilevelocity = 0.5
176 199
177 self._actionlistener = BossActionListener(self) 200 self._actionlistener = BossActionListener(self)
178 201
179 self.hitpoints = 20 202 self.hitpoints = 20
182 def endLevel(self): 205 def endLevel(self):
183 self._scene.endLevel() 206 self._scene.endLevel()
184 207
185 def update(self): 208 def update(self):
186 super(Boss, self).update() 209 super(Boss, self).update()
210
211 playerloc = self._scene.player.location.getExactLayerCoordinates()
212 bossloc = self.location.getExactLayerCoordinates()
213
214 playerloc.x -= bossloc.x
215 playerloc.y -= bossloc.y
216
217 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
218
219
220 def applyHit(self, hp):
221 self.flash(2)
222 super(Boss, self).applyHit(hp)