简体   繁体   English

Pygame 走向旋转

[英]Pygame walk towards rotation

i'm trying to make a circle go towards the way its looking, when i put 0 it goes towards 0 but when i put 90 for some reason it goes towards like 200 or something我正在尝试按照它的外观做一个圆圈 go,当我把 0 放到 0 时,但是当我出于某种原因把 90 放到 200 之类的东西时

import pygame
import math
import random
from random import randint

pygame.init()



screen = pygame.display.set_mode([500, 500])
""""""


def rad_to_offset(radians, offset): 
    x = math.cos(radians) * offset
    y = math.sin(radians) * offset
    return [x, y]


X = 250
Y = 250

""""""
clock = pygame.time.Clock()

running = True
while running:

     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             running = False

     """ if i put 90 it doesnt go towards 90 """
     xy = rad_to_offset(90, 1)
     X += xy[0]
     Y += xy[1]
     print(X, Y)
     screen.fill((255, 255, 255))

     pygame.draw.circle(screen, (0, 0, 255), (X, Y), 20)

     pygame.display.flip()

pygame.quit()

The unit of the angle in the trigonometric functions is Radian but not Degree .三角函数中角度的单位是Radian而不是Degree Use math.radians to convert from degrees to radians:使用math.radians将度数转换为弧度:

def rad_to_offset(degrees, offset): 
    x = math.cos(math.radians(degrees)) * offset
    y = math.sin(math.radians(degrees)) * offset
    return [x, y]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM