1'''A straight-flying projectile capable of damaging the player.''' 2 3import pygame 4import os 5 6from pygame.locals import * 7 8from locals import * 9 10import data 11 12from object import DynamicObject 13from sound import play_sound 14from animation import Animation 15 16class Projectile(DynamicObject): 17 18 def __init__(self, screen, x, y, dx, dy, damage = 5, set = "energy"): 19 DynamicObject.__init__(self, screen, x, y, -1, False, False) 20 self.animations["default"] = Animation(set, "flying") 21 self.animations["dying"] = Animation(set, "dying") 22 self.image = self.animations[self.current_animation].update_and_get_image() 23 self.rect = self.image.get_rect() 24 self.dx = dx 25 self.dy = dy 26 self.saveddx = None 27 self.damage = damage 28 self.itemclass = "projectile" 29 return 30 31 def update(self, level = None): 32 DynamicObject.update(self, level) 33 34 if self.dx == 0 and self.dy == 0 and self.saveddx != None: #Restores values saved on flipping 35 self.dx = self.saveddx 36 self.dy = self.saveddy 37 self.saveddx = None 38 39 if level.ground_check(self.x - 1, self.y - 1) or level.ground_check(self.x + 1, self.y + 1): #Simplified collision detection 40 self.die() 41 self.dx = 0 42 self.dy = 0 43 return 44 45 def flip(self, flip_direction = CLOCKWISE): 46 if flip_direction == CLOCKWISE: 47 self.saveddx = -self.dy 48 self.saveddy = self.dx 49 else: 50 self.saveddx = self.dy 51 self.saveddy = -self.dx 52 DynamicObject.flip(self, flip_direction) 53 return