0

This is my bullet class.

class Bullet(pygame.sprite.Sprite):
def __init__(self, pos_x, pos_y):
    super().__init__()
    self.image = pygame.Surface((16, 16))
    self.image.fill('green')
    self.rect = self.image.get_rect(center=(pos_x, pos_y))
    angle = math.atan2(pos_y-y, pos_x-x)
    self.dx = math.cos(angle)*10
    self.dy = math.sin(angle)*10
    self.x = x
    self.y = y

def update(self):
    self.x = self.x + self.dx
    self.y = self.y + self.dy
    self.rect.x = int(self.x)
    self.rect.y = int(self.y)

This is where I shoot the bullets

while True:
screen.fill('black')
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        exit()

    if event.type == pygame.MOUSEBUTTONDOWN:
        x, y = pygame.mouse.get_pos()
        b = Bullet(player.rect.centerx, player.rect.centery)
        bullet_group.add(b)

What can I do to make the bullet shoot the mouse instead of the player? I tried all I can think of and nothing worked.

ScythLVH
  • 1
  • 1

0 Answers0