我正在尝试用 python 制作恐龙游戏(比如 chrome 中的离线恐龙游戏)。我想让恐龙在按下空格键时跳跃,但当我按下它时,不仅恐龙的形象被欺骗了,而且它也不会回来。import pygameimport timepygame.init()displayWidth = 700displayHeight = 350gameDisplay = pygame.display.set_mode((displayWidth,displayHeight))pygame.display.set_caption("Dino-Run")black = (0,0,0)white = (255,255,255)clock = pygame.time.Clock()dinoimg = pygame.image.load("dino.png")def dino(x,y): gameDisplay.blit(dinoimg,(x,y))def gameloop(): gameExit = False x = (displayWidth * 0.005) y = (displayHeight * 0.75) y_change = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: y_change = -5 if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: y_change = 0 y += y_change dino(x,y) pygame.display.update() clock.tick(60)有人可以告诉我如何防止恐龙在每次按下空间时欺骗并让恐龙回到地面。
添加回答
举报
0/150
提交
取消