我正在为一个学校项目开发一款陆地模拟游戏,而我拥有的跳跃代码不起作用。当我运行代码时,除非我移到侧面,否则角色会不断跳跃,但是当我按下空格键(实际的跳跃按钮时,角色会永久停止跳跃。
elif man.isJump != False:
if keys[pygame.K_SPACE]:
man.isJump = True
man.right = False
man.left = False
man.walkCount = 0
else:
if man.jumpCount >= -10:
# neg variable determines which way our character is moving positive 1 up, negative 1 down
neg = 1
if man.jumpCount < 0:
neg = -1
# move our character by the number of pixels
# using the product (**) of 10 which is count and halfing the value
# if positive then moving up, negative moving down
man.y -= (man.jumpCount ** 2) * 0.5 * neg
man.jumpCount -= 1
else:
man.isJump = False
man.jumpCount = 10
答案 0 :(得分:0)
[...]运行代码时,角色不断跳动[...]
您必须评估男人是否没有跳跃,然后按 SPACE 来开始跳跃。在其他情况下,可以执行跳转:
if man.isJump == False:
if keys[pygame.K_SPACE]:
man.isJump = True # <------ start jump
man.right = False
man.left = False
man.walkCount = 0
else
if man.jumpCount >= -10 and : # <----- is jumping?
# neg variable determines which way our character is moving positive 1 up,
# negative 1 down
neg = 1
if man.jumpCount < 0:
neg = -1
# move our character by the number of pixels
# using the product (**) of 10 which is count and halfing the value
# if positive then moving up, negative moving down
man.y -= (man.jumpCount ** 2) * 0.5 * neg
man.jumpCount -= 1
else:
man.isJump = False # <------ end jump
man.jumpCount = 10