I am working on my first coding project made in pygame and I have an issue with the rotation of the player. I want to make the player point towards the center of its circular path, but it doesn’t work correctly and I don’t know why.
My code so far:
import pygame
import math
pygame.init()
w=1920
h=1040
win=pygame.display.set_mode((w,h))
pygame.display.set_caption("Quan")
clock = pygame.time.Clock()
a=0
b=0
k1=w/2
k2=h/2
x=k1+math.cos(a)*500
y=k2+math.sin(b)*500
angle_var=0.01
image=pygame.image.load('arrow.png')
image = pygame.transform.rotate(image, 180)
def walk():
win.blit(image,(x,y))
pygame.display.update()
run=True
while run:
clock.tick(60)
pygame.time.delay(10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_d]:
a+=angle_var
b-=angle_var
x=(k1+math.cos(a)*500)
y=(k2+math.sin(b)*500)
image = pygame.transform.rotate(image, angle_var)
if keys[pygame.K_a]:
a-=angle_var
b+=angle_var
x=k1+math.cos(a)*500
y=k2+math.sin(b)*500
image = pygame.transform.rotate(image, -1*angle_var)
walk()
win.fill((0,0,0))
pygame.quit()
I’m sorry if it’s a mess, its my first time coding in this.
Thank you
I tried to change the rotation, but it did not work properly.
New contributor
Tamás Zentai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.