I am trying to rotate an image around a point, ive got the code working, but it is turning from the center of the image but i want it to rotate on the bottom of my image:
Here is my code:
import pygame
import math
screen = pygame.display.set_mode((500,500))
run = True
player_x = 250
player_y = 250
correction_angle = 90
while run:
screen.fill((255,255,255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
run = False
#make the player move in every direction
key = pygame.key.get_pressed()
if key[pygame.K_a]:
player_x -= 1 / 5
if key[pygame.K_d]:
player_x += 1 / 5
if key[pygame.K_w]:
player_y -= 1 / 5
if key[pygame.K_s]:
player_y += 1 / 5
mx,my = pygame.mouse.get_pos()
player_rect = pygame.Rect(player_x ,player_y,50,50)
gun = pygame.image.load('gun.png').convert_alpha()
dx,dy = mx - player_x , my - player_y
angle = math.degrees(math.atan2(-dy,dx)) - correction_angle
rotate_image = pygame.transform.rotate(gun, angle)
rect = rotate_image.get_rect()
pos = (((500 - rect.width)/2),((500 - rect.height)/2))
pygame.draw.circle(screen, (0,255,0), ((500 - rect.width)/2,(500 - rect.height)/2),10)
screen.blit(rotate_image,pos)
pygame.display.update()
pass