I'm making a shooting game, how would I make the gun point towards the mouse cursor?
Here's part of my code:

y = 100
x = 100
screen = pygame.display.set_mode((800,600))
p = pygame.image.load("Person.png")
player = pygame.transform.scale(p, (34, 86))
pygame.key.set_repeat(1, 1)
mx, my = pygame.mouse.get_pos()
while True:
    screen.fill(white)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
    angle_to_mouse = math.degrees(math.atan2(y-mx, x-my))+180
    screen.blit(p, (x, y))
    pygame.display.flip()

I don't have any idea how to even start... Help?

Logically speaking, you are to rotate your Gun sprite to the direction of your mouse position.

I highly recommend you check out my 2D game framework PyDark. It's built on-top of PyGame and it makes developing 2D games easier. www.pydark.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.