更新时间:2023-12-01 16:09:46
这应该可行
if pressed[pygame.K_UP] and y > 0: y -= 5
if pressed[pygame.K_DOWN] and y < 600 - 60: y += 5
if pressed[pygame.K_LEFT] and x > 0: x -= 5
if pressed[pygame.K_RIGHT] and x < 800 - 60: x += 5
其中 600 和 800 是屏幕尺寸,60 是矩形的尺寸
Where 600 and 800 is the screen size and 60 the size of your rectangle