~pytower-heros/pytower/main

« back to all changes in this revision

Viewing changes to pyTower/Bullet.py

  • Committer: Bastian Kennel
  • Date: 2008-12-01 18:22:21 UTC
  • Revision ID: bastian@simpsus-20081201182221-zyh6rfvu22hsed35
added docstringWizard comment stubs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# pytower - a python library to build "Tower Defence" style games
 
4
# Copyright (C) 2008  Bastian Kennel, Wolfgang Steitz
 
5
 
 
6
# This program is free software; you can redistribute it and/or
 
7
# modify it under the terms of the GNU General Public License
 
8
# as published by the Free Software Foundation; either version 2
 
9
# of the License, or (at your option) any later version.
 
10
 
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
 
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 
1
20
from Sprites import RabbytSprite
2
21
import math,os
3
22
import rabbyt
185
204
            self.die()
186
205
 
187
206
    def arrival_on_target(self, dt=0):
 
207
        """
 
208
        unschedules the seeking and calls the super method
 
209
        """
188
210
        clock.unschedule(self.seek)
189
211
        super(SeekingBullet, self).arrival_on_target(self)
190
212
 
191
213
class AirBullet(Bullet):
 
214
    """
 
215
    A targeted Bullet that has a tail animation and a headed picture
 
216
    """
192
217
 
193
218
    name = "AirBullet"
194
219
    rocket = "rocket.png"
197
222
    tail_distance = 10
198
223
 
199
224
    def __init__(self, tower):
 
225
        """
 
226
        @type tower: L{Tower}
 
227
        @param tower: The L{Tower} which shot the bullet
 
228
        """
200
229
        super(AirBullet, self).__init__(tower, img = tower.game.loader.image(self.rocket))
201
230
        self.tail = RabbytSprite(self.tower.game.loader.image(self.tail_img))
202
231
        self.setSpeed(100)
203
232
 
204
233
    def arrival_on_target(self, dt=0):
 
234
        """
 
235
        calls the super method and removes the tail
 
236
        """
205
237
        super(AirBullet, self).arrival_on_target(dt)
206
238
        self.tower.game.remove_item(self.tail)
207
239
 
208
240
    def _adjust_tail(self):
 
241
        """
 
242
        FIXME
 
243
        """
209
244
        sinus       = math.sin(self.rot/180.*math.pi)
210
245
        cosinus     = math.cos(self.rot/180.*math.pi)
211
246
        x_diff = sinus * self.tail_distance
215
250
        #print "angle: ", self.rot, " | X: ", x_diff, " | Y: ", y_diff
216
251
 
217
252
    def fire(self):
 
253
        """
 
254
        calls the super method and rotates to the target,
 
255
        fades in the tail and adds it to the game items
 
256
        """
218
257
        super(AirBullet, self).fire()
219
258
        self.rotate_to(self.target.xy)
220
259
        self.tail.alpha = rabbyt.lerp(start=0, end=1, dt=self.tail_time, extend="reverse")
222
261
        self.tower.game.add_item(self.tail,"other")
223
262
 
224
263
    def rotate_to(self, point):
 
264
        """
 
265
        rotates to point
 
266
        @type point: a 2 tuple of integers
 
267
        @param point: the point to rotate to
 
268
        """
225
269
        self.logger.debug("rotating from " + str(self.xy) + " to " + str(point))
226
270
        # the sinus of our angle to the point is gegenkathete / hypothenuse
227
271
        hypo    = math.hypot(abs(self.x - point[0]), abs(self.y - point[1]))
254
298
 
255
299
 
256
300
class SlowingBullet(Bullet):
 
301
    """
 
302
    A Bullet that does nothing special as the tower does the slow
 
303
    """
257
304
 
258
305
    name = "SlowingBullet"
259
306
    img = os.path.join(path,"pyTower/art/slowing_bullet.png")
260
307
 
261
308
    def __init__(self, tower):
 
309
        """
 
310
        FIXME
 
311
        @param tower:
 
312
        @type tower:
 
313
        """
262
314
        super(SlowingBullet, self).__init__(tower, SlowingBullet.img)
263
315
        self.setSpeed(150)
264
316
 
265
317
 
266
318
 
267
319
class SplashBullet(SeekingBullet):
 
320
    """
 
321
    A Bullet that damages all targets within a range of its impact
 
322
    dependant of the exakt distance from the bullet to the creep
 
323
    """
268
324
 
269
325
    name = "SplashBullet"
270
326
    splash_image = None
271
327
 
272
328
    def __init__(self, tower):
 
329
        """
 
330
        @type tower: L{Tower}
 
331
        @param tower: The L{Tower} that shot the bullet
 
332
        """
273
333
        super(SplashBullet, self).__init__(tower)
274
334
        self.splash_image = tower.game.loader.image("splash_range.png")
275
335
        self.faktor = tower.splash_radius / (self.splash_image.width/2.0)
279
339
        self.show_sprite.xy = self.attrgetter("xy")
280
340
 
281
341
    def arrival_on_target(self, dt=0):
 
342
        """
 
343
        damages all creeps in the towers splash_radius with a damage
 
344
        that is dependant on the distance to the creep
 
345
        """
282
346
        if self.alive:
283
347
            self.logger.debug(str(self) + " arrived at destination")
284
348
            range = self.tower.splash_radius
295
359
            self.logger.debug("Dead Bullet arrived at destination")
296
360
 
297
361
    def show_splash_damage(self, range):
 
362
        """
 
363
        plays an animation showing the area the bullet does damage in
 
364
        """
298
365
        self.tower.game.add_item(self.show_sprite, "other")
299
366
        self.show_sprite.scale = rabbyt.lerp(start=0, end=self.faktor, dt=self.show_duration/2.0, extend="reverse")
300
367
        self.tower.game.clock.schedule_once(self.unshow_splash_damage, self.show_duration)
301
368
 
302
369
    def unshow_splash_damage(self, dt=0):
 
370
        """
 
371
        removes the L{show_splash_damage} animation
 
372
        """
303
373
        self.tower.game.remove_item(self.show_sprite)
304
374
 
305
375