Skip to main content
 首页 » 编程设计

python 将度数转换为 x 的变化和 y 的变化

2025年05月04日9arxive

我正在使用 pygame 在 python 中制作蛇游戏,为了移动角色,我有一个整数,它是它应该移动的角度度数。有什么办法可以让 x 和 y 的变化根据度数移动它?例如:func(90) # [0, 5] 或 func(0) # [5, 0]

请您参考如下方法:

import math 
 
speed = 5 
angle = math.radians(90)    # Remember to convert to radians! 
change = [speed * math.cos(angle), speed * math.sin(angle)]