def follow(self): if self.target() is None: return to_target = Vector2.get_normal(self.target().position - self.position) self.acceleration = to_target * self.homing_speed
def shoot(self): # Direction to target dirToTarget = Vector2.get_normal(self.target.position - self.position) # Create a bullet bullet = Particle() bullet.tag = "enemy bullet" bullet.position.x = self.position.x bullet.position.y = self.position.y bullet.velocity = dirToTarget * self.firing_speed bullet.boundingBox = Rect(self.position.to_tuple(), (5, 5)) bullet.color = (0, 255, 0) bullet.set_life(2.0) self.all_game_objects.append(bullet)
def fire_bullet(): # Direction to mouse mouseX, mouseY = pygame.mouse.get_pos() mousePos = Vector2(mouseX + camera.boundingBox.x, mouseY+camera.boundingBox.y) dirToMouse = Vector2.get_normal(mousePos - player.position) # Create a bullet bullet = Particle() bullet.tag = "player bullet" bullet.position.x = player.position.x bullet.position.y = player.position.y bullet.velocity = dirToMouse * 800.0 bullet.boundingBox = Rect(player.position.to_tuple(), (5, 5)) bullet.color = (255, 150, 255) bullet.set_life(1.3) all_game_objects.append(bullet) channel = mixer.find_channel(True) channel.queue(laser_shot_sfx)
def shoot(): if player is None: return # get pos returns a tuple (mx, my) mouse_tuple = pygame.mouse.get_pos() mouse_pos = Vector2(mouse_tuple[0], mouse_tuple[1]) # direction pointing at the mouse from the player to_mouse = Vector2.get_normal(mouse_pos - player.position) vel = to_mouse * 400.0 b = Bullet(500, player.position, vel) b.color = (255, 150, 80) b.graphicsBounds.radius = 5 b.collider.radius = 5 bullets.append(b) laser_shot_sfx.play()