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)
def phase1(self): self.move_speed = 2 # After y is lined up, turn toward player and starting moving on the y axis if self.moving_x and \ abs(self.x - ml.player.rect.centerx) <= \ self.move_speed + float(ml.get_upgrade_values('Movement Speed')): self.moving_x = False self.moving_y = True _ = self.shoot(-999, self.circle_bd, self.circle_fd) # After x is lined up, turn toward player and starting moving on the x axis if self.moving_y and \ abs(self.y - ml.player.rect.centery) <= \ self.move_speed + float(ml.get_upgrade_values('Movement Speed')): self.moving_x = True self.moving_y = False _ = self.shoot(-999, self.circle_bd, self.circle_fd) # Move until self.x lines up with player's x if self.rect.centerx != ml.player.rect.centerx and self.moving_x: self.x, self.y, self.current_angle = ml.move_point( self, (ml.player.rect.centerx, self.rect.centery), self.move_speed, 0, 360) else: self.moving_x = False self.moving_y = True # Move until self.y lines up with player's y if self.rect.centery != ml.player.rect.centery and self.moving_y: self.x, self.y, self.current_angle = ml.move_point( self, (self.rect.centerx, ml.player.rect.centery), self.move_speed, 0, 360) else: self.moving_x = True self.moving_y = False
def move(self): distance = ml.distance_to_point(self.rect.center, ml.player.rect.center) if distance < self.homing_distance: angle = ml.angle_to_point(self.rect.center, ml.player.rect.center) self.x, self.y, _ = ml.move_point(self, ml.player.rect.center, self.homing_speed, angle, 5) elif self.moving_from_spawn: if self.x == self.target_point[0] and self.y == self.target_point[1]: self.moving_from_spawn = False else: self.x, self.y, _ = ml.move_point(self, self.target_point, self.from_spawn_speed, 0, 360) else: self.y += self.falling_speed
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)
def move(self): """If a turning rate is defined, the enemy will home on the player. Otherwise, it will move in a straight line at its current angle.""" if self.turning_rate: self.x, self.y, self.current_angle = \ ml.move_point(self, ml.player.rect.center, self.move_speed, self.current_angle, self.turning_rate) else: self.x += self.move_speed * math.cos( math.radians(self.current_angle)) self.y -= self.move_speed * math.sin( math.radians(self.current_angle))
def phase1(self): angle = 270 # ml.angle_to_point(self.rect.center, ml.player.rect.center) self.x, self.y, _ = ml.move_point(self, ml.player.rect.center, 1, 0, 360) self.phase1fd.angle = angle self.phase1timer1 = self.shoot(self.phase1timer1, self.phase1bd, self.phase1fd) self.phase1fd.angle = angle + 180 self.phase1timer2 = self.shoot(self.phase1timer2, self.phase1bd, self.phase1fd) self.phase1fd.angle = angle + 90 self.phase1timer3 = self.shoot(self.phase1timer3, self.phase1bd, self.phase1fd) self.phase1fd.angle = angle - 90 self.phase1timer4 = self.shoot(self.phase1timer4, self.phase1bd, self.phase1fd)
def move(self): if self.homing_shots_active: self.x, self.y, self.angle = ml.move_point(self, ml.player.rect.center, self.move_speed, self.angle, self.turning_rate) # Spiral shots elif self.spiral: self.x = self.spawn_point[0] + self.radius * math.cos( math.radians(self.angle)) self.y = self.spawn_point[1] + self.radius * math.sin( math.radians(self.angle)) self.radius += self.radial_growth self.angle += self.turning_rate # Normal shots else: self.x += self.diag_move_x self.y -= self.diag_move_y
def move(self): # Homing shots if ml.enemy_group.sprites() and self.homing: closest_enemy = ml.closest_sprite_in_group(self, ml.enemy_group) if closest_enemy: self.x, self.y, self.current_angle = ml.move_point( self, closest_enemy.rect.center, self.move_speed, self.current_angle, self.turning_rate) else: self.x += self.move_speed * math.cos( math.radians(self.current_angle)) self.y -= self.move_speed * math.sin( math.radians(self.current_angle)) # Non-homing shots else: self.x += self.move_speed * math.cos( math.radians(self.current_angle)) self.y -= self.move_speed * math.sin( math.radians(self.current_angle))
def phase3(self): self.turning_rate = ml.normalize_target_fps(10) # Match the player's speed self.move_speed = ml.normalize_target_fps( float(ml.get_upgrade_values('Movement Speed')) - 1) # Keep the boss positioned above the player above_player = (ml.player.rect.centerx, ml.player.rect.centery - 350) self.x, self.y, self.movement_angle = ml.move_point( self, above_player, self.move_speed, self.movement_angle, self.turning_rate) # Keep boss on screen if self.rect.centery < 0: self.y = 0 # Face the player self.current_angle = ml.angle_to_point(self.rect.center, ml.player.rect.center) # Shoot self.phase2_bd = BulletData(self, coords=self.rect.center, speed=7) self.phase2_timer = self.shoot(self.phase2_timer, self.phase2_bd, self.phase2_fd) self.phase2spread_timer = self.shoot(self.phase2spread_timer, self.phase2spread_bd, self.phase2spread_fd) # Left arc self.phase2arc_bd.coords = self.rect.midleft self.phase2arc_fd.angle = ml.burst_angles(20, 180, 10)[self.phase2arc_counter] self.phase2arc_timer, self.phase2arc_counter = \ self.shoot(self.phase2arc_timer, self.phase2arc_bd, self.phase2arc_fd, self.phase2arc_counter) # Right arc self.phase2arc_bd.coords = self.rect.midright self.phase2arc_fd.angle = ml.burst_angles(20, 0, -10)[self.phase2arc2_counter] self.phase2arc2_timer, self.phase2arc2_counter = \ self.shoot(self.phase2arc2_timer, self.phase2arc_bd, self.phase2arc_fd, self.phase2arc2_counter)
def phase2(self): # Mirror player movement rotation_rate = 15 if not self.current_angle % rotation_rate: self.current_angle -= self.current_angle % rotation_rate mirror_point = ml.player.rect.centerx * -1 + ml.window_width, \ ml.player.rect.centery * -1 + ml.window_height self.x, self.y, _ = ml.move_point(self, mirror_point, 20, 0, 360) # Rotate if player moves above/below if self.y > ml.player.rect.centery: if self.current_angle != 90 and self.x > ml.player.rect.centerx: self.current_angle -= rotation_rate elif self.current_angle != 90 and self.x < ml.player.rect.centerx: self.current_angle += rotation_rate else: if self.current_angle != 270 and self.x > ml.player.rect.centerx: self.current_angle += rotation_rate elif self.current_angle != 270 and self.x < ml.player.rect.centerx: self.current_angle -= rotation_rate # Shoot self.phase1homing_timer = self.shoot(self.phase1homing_timer, self.phase1homing_bd, self.phase1homing_fd) bullet_speed = 7 distance = abs(ml.player.rect.centery - self.rect.centery) duration_f = distance / bullet_speed duration_s = duration_f / ml.normalize_target_fps(60) self.phase1_bd = BulletData(self, speed=bullet_speed, duration=duration_s, exploding=self.phase1explode) self.phase1_fd = FiringData(firing_speed=2, angle=self.current_angle) self.phase1_timer = self.shoot(self.phase1_timer, self.phase1_bd, self.phase1_fd)
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))