def __init__(self, x, y, speed, damage, angle, homing_shots) -> pygame.sprite.Sprite: pygame.sprite.Sprite.__init__(self) self.move_speed = ml.normalize_target_fps(float(speed)) self.damage = damage self.current_angle = ml.normalize_angle(angle) self.angle_r = math.radians(angle) self.turning_rate = ml.normalize_target_fps(3.5) self.homing = homing_shots # Set up image, rect, and mask if self.homing: self.image = ml.get_bullet_image('homing') else: self.image = ml.get_bullet_image('player') self.width = self.image.get_width() self.height = self.image.get_height() self.original_image = self.image # self.image = pygame.transform.rotate(self.image, angle) self.x = x self.y = y self.rect = pygame.Rect(0, 0, self.width, self.height) self.rect.center = self.x, self.y self.mask = pygame.mask.from_surface(self.image) # Add sprite to group self.add(ml.player_bullet_group)
def __init__(self, bullet_data, angle) -> pygame.sprite.Sprite: pygame.sprite.Sprite.__init__(self) self.infinite_explosion = bullet_data.infinite_explosion self.original_bullet_data = bullet_data self.despawn_range = 200 self.original_parent = bullet_data.original_parent if bullet_data.random_speed != (0, 0): a, b = bullet_data.random_speed self.move_speed = ml.normalize_target_fps(random.uniform(a, b)) else: self.move_speed = bullet_data.speed self.damage = bullet_data.damage self.angle = angle # normalized by FiringData self.angle_r = math.radians(angle) if bullet_data.random_duration == (0, 0): self.duration = bullet_data.duration else: a, b = bullet_data.random_duration self.duration = random.uniform(a, b) self.homing_shots_active = bullet_data.homing self.turning_rate = bullet_data.turning_rate if bullet_data.exploding: self.exploding = True self.exploding_list = bullet_data.exploding[:] self.exploding_bullet_data, self.exploding_firing_data = self.exploding_list[ 0] if not self.infinite_explosion: del self.exploding_list[0] else: self.exploding = False self.spawn_time = ml.time() self.diag_move_x = self.move_speed * math.cos(math.radians(self.angle)) self.diag_move_y = self.move_speed * math.sin(math.radians(self.angle)) # Set up image, rect, and mask if bullet_data.homing: self.image = ml.get_bullet_image('homing') elif bullet_data.exploding: self.image = ml.get_bullet_image('exploding') else: self.image = ml.get_bullet_image('enemy') self.rect = pygame.Rect(0, 0, self.image.get_width(), self.image.get_height()) if bullet_data.coords: self.x, self.y = bullet_data.coords else: self.x, self.y = bullet_data.parent.rect.center self.spawn_point = self.x, self.y self.spiral = bullet_data.spiral self.radial_growth = bullet_data.radial_growth self.radius = 0 self.rect.center = self.x, self.y self.mask = pygame.mask.from_surface(self.image, 250) self.mask_rect = self.mask.get_bounding_rects()[ 0] # Set in get_mask_rect() # Add to group self.add(ml.enemy_bullet_group)