我正在用小行星之类的控件制作游戏,向上箭头用于加速,向右箭头顺时针旋转,向左箭头逆时针旋转,例如,如果我想减速,我需要将船旋转 180\xc2\xb0 并加速。\我能够旋转,为此我画了两个向量(速度和航向)。\n我正在尝试用向量实现这种类型的运动,但也许我不应该这样做?\n所以这就是我的想法。
\n\nimport pygame\nimport sys\nfrom pygame.locals import * # pygame.locals.QUIT --> QUIT\n# Vector2\nvec = pygame.math.Vector2\n\n# initialize pygame\npygame.init()\nFPS = 60 # frames per second\nfps_clock = pygame.time.Clock()\n# set up the window\nWIDTH = 800\nHEIGHT = 800\nDISPLAY = pygame.display.set_mode((WIDTH, HEIGHT))\npygame.display.set_caption(\'VECTOR_2\')\nFONT = pygame.font.Font(None, 24)\n# RGB colors\nRED = (255, 0, 0)\nGREEN = (0, 255, 0)\nBLUE = (0, 0, 255)\nWHITE = (255, 255, 255)\nBLACK = (0, 0, 0)\n\nMAX_SPEED = 9\n\n\nclass Player(pygame.sprite.Sprite):\n def __init__(self):\n pygame.sprite.Sprite.__init__(self)\n # set ship image\n self.image = pygame.Surface((70, 50), pygame.SRCALPHA)\n pygame.draw.polygon(self.image, (50, …Run Code Online (Sandbox Code Playgroud)