[英]Jumping in Pygame
我试图在pygame中制作像几何破折号的游戏。 除了跳跃部分,我已完成所有工作。 我需要它,以便当角色在方块上时,他可以跳起来,但不能在空中半跳。 现在我有了它,以便角色可以在地面上跳跃,但是一旦角色触摸在一组积木上跳跃,他就会开始上下反弹,并且在滑到积木上时不能跳跃。 有人可以帮忙吗?
onblock = False
for i in squares_list:
if player_rect.bottom <= 560 and player_rect.colliderect(i):
onblock = True
player_rect.bottom = i.top + 1
if player_rect.collidepoint((i.topleft[0], i.topleft[1]+1)):
print ('Game Over')
if event.type == KEYDOWN: # if space is pressed the character jumps
if event.key == K_SPACE:
print(onblock)
if onblock or player_rect.bottom == screen.get_rect().bottom : # prevents double jumps
vel_y = -20 # Makes the character jump up
player_rect.y -= 1
if onblock:
gravity = 0
vel_y = 0
current_angle = 0
else:
gravity = 1
vel_y += gravity
onblock = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.