我正在尝试制作一个平台游戏,我对如何编码它感到困惑,因此无论你持有向上箭头多久,它只会导致y更改一次更改,直到你放开并压制它。(会有是双跳,但我还没有到达那里。我也没有得到引力。)这是我的代码:
import pygame
import time
import random
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
car_width = 64
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Platformer')
clock = pygame.time.Clock()
game_loop():
score = 0
x = (display_width * 0.45)
y = (display_height * 0.8)
y_change = -5
x_change = 0
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -5
elif event.key == pygame.K_RIGHT:
x_change = 5
elif event.key == pygame.K_UP:
y_change = 25
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_change = 0
gameloop()
pygame.quit()
quit()
有人可以帮忙吗?