def __init__(self, pos, speed, kolom, baris): super().__init__() self.current_ship = 0 self._addAnimation([ Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["left"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["sleft"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["idle"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["sright"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["right"], 4, True) ]) self.start_pos = [pos[0], pos[1] - self.animations[0].frame_size[1]] self.rect = pygame.Rect( [pos[0], pos[1] - self.animations[0].frame_size[1]], self.animations[0].frame_size) self.pos = list(self.rect.topleft) self.speed = float(speed) # (vec[0], vec[1]) == (x, y) self.vec = (0.0, 0.0) self.bullet_list = [] self.health = 3
def __init__(self, pos): super().__init__() self.pos = pos self._addAnimation(Animation(BULLET_PATH, 1, False)) self.rect = pygame.Rect(pos, self.animations[0].frame_size) self.speed = BULLET_SPEED self.vec = [0, -1] self.scale(BULLET_SCALE)
def __init__(self, pos): super().__init__() self.pos = pos self._addAnimation(Animation(BONUS_PATH, 1, False)) self.scale(BONUS_SCALE) self.rect = pygame.Rect(pos, self.animations[0].frame_size) self.speed = 60 x = uniform(-0.5, 0.5) self.vec = [x, 1]
def __init__(self, pos, scale): super().__init__() self.pos = pos self._addAnimation(Animation(ASTEROID_PATH, 1, False)) self.scale(scale) self.rect = pygame.Rect(pos, self.animations[0].frame_size) self.speed = randint(100, 300) x = uniform(0.1, 0.5) if self.pos[0] < 400 else uniform(-0.5, -0.1) self.vec = [x, 1]
def upgrade_ship(self): if self.current_ship + 1 >= len(SHIP_ANIMATIONS_PATH): return self.current_ship += 1 new_animations = [ Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["left"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["sleft"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["idle"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["sright"], 4, True), Animation(SHIP_ANIMATIONS_PATH[self.current_ship]["right"], 4, True) ] self.animations = new_animations
def __init__(self, pos, scale): super().__init__() self.pos = pos self._addAnimation(Animation(EXPLOSION_PATH, 4, False)) self.scale(scale) self.rect = pygame.Rect(pos, self.animations[0].frame_size)
def __init__(self): super().__init__() self._addAnimation(Animation(HEART_PATH, 1, False)) self.scale(BONUS_SCALE) self.rect = pygame.Rect((0, 0), self.animations[0].frame_size)