嗨,我一直在关注Tim的pygame。但是我已经达到了编码跳跃的地步。我理解代码,但不明白为什么一旦达到jumpCount = -10我的计算机就不会考虑else语句 这是完整的理解代码,但这是从“ if not isJump”开始的部分:
x = 50
y = 50
width = 40
height = 60
vel = 5
isJump = False
jumpCount = 10
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > vel:
x -= vel
if keys[pygame.K_RIGHT] and x < 500 - (width + vel):
x += vel
if not isJump:
if keys[pygame.K_UP] and y > vel:
y -= vel
if keys[pygame.K_DOWN] and y < 500 - (height + vel):
y += vel
if keys[pygame.K_SPACE]:
所以我的问题确实在这里。
isJump = True
else:
if isJump >= -10:
neg = 1
if jumpCount < 0:
neg = -1
y -= ((jumpCount ** 2) * neg) * 0.5
jumpCount -= 1
else:
isJump = False
jumpCount = 10
window.fill((0, 0, 0))
pygame.draw.rect(window, (255, 0, 0), (x, round(y), width, height))
pygame.display.update()
pygame.quit()