Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def phase2(self):
        # Move boss and shoot
        self.x, self.y, _ = ml.move_point(self, ml.player.rect.center, 0.7, 0,
                                          360)
        self.phase2timer = self.shoot(self.phase2timer, self.phase2bd,
                                      self.phase2fd)

        # Control minion
        self.minion1.x, self.minion1.y, self.minion1.current_angle =\
            ml.move_point(self.minion1, ml.player.rect.center, 7,
                          self.minion1.current_angle, 0.8)
        self.minion1part.animate(angle_change=15)
        self.minion1part.x, self.minion1part.y = self.minion1.x, self.minion1.y
        self.phase2minion_timer = self.shoot(self.phase2minion_timer,
                                             self.phase2minionbd,
                                             self.phase2minionfd)
        # Bounce off walls
        if self.minion1.rect.left < 0:
            self.minion1.rect.left = 0
            self.minion1.x = self.minion1.rect.centerx
            self.minion1.current_angle = 180 - self.minion1.current_angle
        elif self.minion1.rect.right > ml.window_width:
            self.minion1.rect.right = ml.window_width
            self.minion1.x = self.minion1.rect.centerx
            self.minion1.current_angle = 180 - self.minion1.current_angle
        elif self.minion1.rect.top < 0:
            self.minion1.rect.top = 0
            self.minion1.y = self.minion1.rect.centery
            self.minion1.current_angle = 360 - self.minion1.current_angle
        elif self.minion1.rect.bottom > ml.window_height:
            self.minion1.rect.bottom = ml.window_height
            self.minion1.y = self.minion1.rect.centery
            self.minion1.current_angle = 360 - self.minion1.current_angle
        self.minion1.current_angle = ml.normalize_angle(
            self.minion1.current_angle)
Exemplo n.º 3
0
    def animate(self):
        start_rect_center = self.rect.center
        self.current_angle = ml.normalize_angle(self.current_angle)

        if ml.time() - self.phase_change_time < self.phase_change_delay:
            self.invincible = True
            self.image = pygame.transform.rotate(self.boss_invisible_image,
                                                 self.current_angle)
        else:
            self.invincible = False
            self.image = pygame.transform.rotate(self.image_original,
                                                 self.current_angle)

        self.rect = self.image.get_rect()
        self.rect.center = start_rect_center
Exemplo n.º 4
0
    def phase3(self):
        # Move boss in semicircle around player
        radius = 350
        self.circle_angle += self.circle_angle_change
        circle_x = ml.player.rect.centerx + radius * math.cos(
            math.radians(self.circle_angle))
        circle_y = ml.player.rect.centery - radius * math.sin(
            math.radians(self.circle_angle))
        target_point = circle_x, circle_y
        if not 30 < self.circle_angle < 150:
            self.circle_angle_change *= -1
        self.x, self.y, _ = ml.move_point(self, target_point, 20, 0, 360)

        # Boss shoot
        self.phase3fd.angle = self.circle_angle
        self.phase3timer = self.shoot(self.phase3timer, self.phase3bd,
                                      self.phase3fd)

        # Minion control
        self.minion2part.animate(angle_change=15)
        self.minion3part.animate(angle_change=15)
        self.minion_angle = ml.normalize_angle(self.minion_angle + 1)
        radius = 200
        circle_x = ml.player.rect.centerx + radius * math.cos(
            math.radians(self.minion_angle))
        circle_y = ml.player.rect.centery - radius * math.sin(
            math.radians(self.minion_angle))
        minion2_point = circle_x, circle_y
        angle = self.minion_angle + 180
        circle_x = ml.player.rect.centerx + radius * math.cos(
            math.radians(angle))
        circle_y = ml.player.rect.centery - radius * math.sin(
            math.radians(angle))
        minion3_point = circle_x, circle_y
        self.minion2.x, self.minion2.y, _ = ml.move_point(
            self.minion2, minion2_point, 20, 0, 360)
        self.minion3.x, self.minion3.y, _ = ml.move_point(
            self.minion3, minion3_point, 20, 0, 360)
        self.minion2part.move((self.minion2.x, self.minion2.y))
        self.minion3part.move((self.minion3.x, self.minion3.y))
        self.phase3miniontimer1 = self.shoot(self.phase3miniontimer1,
                                             self.phase3minionbd1,
                                             self.phase3minionfd)
        self.phase3miniontimer2 = self.shoot(self.phase3miniontimer2,
                                             self.phase3minionbd2,
                                             self.phase3minionfd)
Exemplo n.º 5
0
    def __init__(self,
                 x,
                 move_speed,
                 health,
                 collision_damage,
                 image_name,
                 turning_rate=0,
                 current_angle=270,
                 y=0,
                 boss=False,
                 name='') -> pygame.sprite.Sprite:
        pygame.sprite.Sprite.__init__(self)

        self.image_path = os.path.join('graphics', image_name)
        self.image = pygame.image.load(self.image_path).convert_alpha()
        self.image_original = self.image
        self.move_speed = move_speed
        self.turning_rate = turning_rate
        self.current_angle = ml.normalize_angle(current_angle)
        self.health = health
        self.max_health = health
        self.invincible = False
        self.collision_damage = collision_damage
        self.firing_timer = ml.time() - random.uniform(0, 2.0)
        self.spawn_time = ml.time()
        self.spawn_tick = ml.ticks
        self.is_boss = boss
        self.name = name
        self.phase = 1
        self.num_phases = None
        self.phase_change_time = ml.time()

        # Set up image, rect, and mask
        self.rect = self.image.get_rect()
        self.x = x
        self.y = y
        self.rect.center = x, self.y
        self.mask = pygame.mask.from_surface(self.image)

        # Add sprite to group
        self.add(ml.enemy_group)

        if self.is_boss:
            ml.update_boss_data(self.max_health, self.health, self.name)
Exemplo n.º 6
0
    def phase4(self):
        # Move boss in circle around center of window
        window_center = ml.window_width / 2, ml.window_height / 2
        radius = 200
        self.circle_angle += 0.5
        circle_x = ml.window_width / 2 + \
                   radius * math.cos(math.radians(self.circle_angle))
        circle_y = ml.window_height / 2 + \
                   radius * math.sin(math.radians(self.circle_angle))
        target_point = circle_x, circle_y
        self.x, self.y, _ = ml.move_point(self, target_point, 999, 0, 360)
        # Laser
        self.laser.change_image(image=ml.get_laser_image(
            ml.angle_to_point(self.rect.center, window_center)))
        self.laser.move(window_center)
        if ml.time() - self.phase_change_time > self.phase_change_delay + 2:
            self.collide_parts()

        # Minions
        self.minion1part.animate(angle_change=15)
        self.minion2part.animate(angle_change=15)
        self.minion3part.animate(angle_change=15)
        # minion3
        self.minion3.x, self.minion3.y, _ = ml.move_point(
            self.minion3, ml.player.rect.center, 1, 0, 360)
        self.phase1fd.angle = 0
        self.phase1timer1 = self.shoot(self.phase1timer1, self.phase1bd,
                                       self.phase1fd)
        self.phase1fd.angle = 180
        self.phase1timer2 = self.shoot(self.phase1timer2, self.phase1bd,
                                       self.phase1fd)
        self.phase1fd.angle = 90
        self.phase1timer3 = self.shoot(self.phase1timer3, self.phase1bd,
                                       self.phase1fd)
        self.phase1fd.angle = 270
        self.phase1timer4 = self.shoot(self.phase1timer4, self.phase1bd,
                                       self.phase1fd)
        # minion1
        self.minion1.x, self.minion1.y, self.minion1.current_angle = \
            ml.move_point(self.minion1, ml.player.rect.center, 5,
                          self.minion1.current_angle, 0.5)
        self.phase2minion_timer = self.shoot(self.phase2minion_timer,
                                             self.phase2minionbd,
                                             self.phase2minionfd)
        # Bounce off walls
        if self.minion1.rect.left < 0:
            self.minion1.rect.left = 0
            self.minion1.x = self.minion1.rect.centerx
            self.minion1.current_angle = 180 - self.minion1.current_angle
        elif self.minion1.rect.right > ml.window_width:
            self.minion1.rect.right = ml.window_width
            self.minion1.x = self.minion1.rect.centerx
            self.minion1.current_angle = 180 - self.minion1.current_angle
        elif self.minion1.rect.top < 0:
            self.minion1.rect.top = 0
            self.minion1.y = self.minion1.rect.centery
            self.minion1.current_angle = 360 - self.minion1.current_angle
        elif self.minion1.rect.bottom > ml.window_height:
            self.minion1.rect.bottom = ml.window_height
            self.minion1.y = self.minion1.rect.centery
            self.minion1.current_angle = 360 - self.minion1.current_angle
        self.minion1.current_angle = ml.normalize_angle(
            self.minion1.current_angle)
        # minion2
        self.minion_angle = ml.normalize_angle(self.minion_angle + 1)
        radius = 250
        circle_x = ml.player.rect.centerx + radius * math.cos(
            math.radians(self.minion_angle))
        circle_y = ml.player.rect.centery - radius * math.sin(
            math.radians(self.minion_angle))
        minion2_point = circle_x, circle_y
        self.minion2.x, self.minion2.y, _ = ml.move_point(
            self.minion2, minion2_point, 20, 0, 360)
        self.minion2part.move((self.minion2.x, self.minion2.y))
        self.phase3miniontimer1 = self.shoot(self.phase3miniontimer1,
                                             self.phase3minionbd1,
                                             self.phase3minionfd)
        # Move parts
        self.minion1part.move((self.minion1.x, self.minion1.y))
        self.minion2part.move((self.minion2.x, self.minion2.y))
        self.minion3part.move((self.minion3.x, self.minion3.y))