【发布时间】:2019-04-19 02:27:44
【问题描述】:
我最近开始使用 python 并决定使用 pygame 创建一个游戏,其中基本上有方块掉落,你必须越过它们。 您可以使用左右键移动,但如果按住它们没有任何反应,我不知道为什么,因为在我的代码中,我相信我在 114 和 122 之间的行中涵盖了这一点。
虽然不是游戏结束:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
x = player_pos[0]
y = player_pos[1]
keys = pygame.key.get_pressed() # Check if a key is pressed
if keys[pygame.K_LEFT] and x != 0:
x -= 25
print("move left")
if keys[pygame.K_RIGHT] and x != 750:
print("move right")
x += 25
player_pos = [x, y]
draw_enemies(enemy_list)
pygame.draw.rect(screen, RED, (player_pos[0], player_pos[1], player_size, player_size))
clock.tick(30)
pygame.display.update()
我希望可以在按下左右按钮时移动,但我不能我只能在按下然后释放时移动。
【问题讨论】: