我创建了一个游戏,用户应该可以按空格按钮跳转(在一定时间后会上升然后向下)但是当它运行时,它会自动更新以显示最终位置,不是实际的跳跃本身。我试过pygame.time.wait()。但是,我仍然面临同样的问题。任何建议将不胜感激!
xcoor=(0)the leader of the group of blocks
ycoor=(550)
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
ycoor = 500
ycoor = 550
pygame.draw.rect(gameDisplay, purple,[xcoor,ycoor,50,50])
答案 0 :(得分:0)
你必须设置变量ie。 jump = True
并在每个循环中增加ycoor
,直到获得500。
或多或少喜欢这个
xcoor = 0 #the leader of the group of blocks
ycoor = 550
jump = False
fall = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if not fall:
jump = True
if jump:
ycoor += 5
if ycoor >= 500:
ycoor = 500
jump = False
fall = True
if fall:
ycoor -= 5
if ycoor <= 0:
ycoor = 0
fall = False
pygame.draw.rect(gameDisplay, purple,[xcoor,ycoor,50,50])