Python 跳跃在人与地面之间创造了一段距离

Python 跳跃在人与地面之间创造了一段距离,python,pygame,Python,Pygame,完整代码: 导入全局 导入pygame 导入操作系统 操作系统环境['SDL\u视频窗口位置]=%d,%d%(100,40) 班长(pygame.sprite.sprite): #只需随机拍摄图像,即可在变换比例后获得高度和宽度,以便稍后进行裁剪(请参见第23/36行) idle_images_list=glob.glob(r“C:\Users\aviro\Desktop\מחים\python projects\platform game\animation\fighter\PNG\PNG S

完整代码:

导入全局
导入pygame
导入操作系统
操作系统环境['SDL\u视频窗口位置]=%d,%d%(100,40)
班长(pygame.sprite.sprite):
#只需随机拍摄图像,即可在变换比例后获得高度和宽度,以便稍后进行裁剪(请参见第23/36行)
idle_images_list=glob.glob(r“C:\Users\aviro\Desktop\מחים\python projects\platform game\animation\fighter\PNG\PNG Sequences\Firing”+“\*”)
随机\u image=pygame.image.load(空闲\u图像\u列表[0])
新建\u img\u width=int(随机图像。获取\u width()/2.5)
new\u img\u height=int(random\u image.get\u height()/2.5)
裁剪后的随机图像=随机图像。地下((70,35,新图像宽度-125,新图像高度-45))
#能够使用所需的图像索引
#获取空闲动画列表
右\u空闲\u列表=[]
左\u空闲\u列表=[]
对于空闲图像列表中的图像:
img=pygame.image.load(图像)
wid=img.get_width()
hei=img.get_height()
img=pygame.transform.scale(img,(int(wid/2.5),int(hei/2.5)))
img=img.地下((70,35,新img_宽度-125,新img_高度-45))
右\u空闲\u列表。追加(img)
左\u idle\u list.append(pygame.transform.flip(img,True,False))
#获取运动动画列表
walk_animation_list=glob.glob(r“C:\Users\aviro\Desktop\מחים\python projects\platform game\animation\fighter\PNG\PNG Sequences\Run firming”+“\*”)
向右行走列表=[]
向左行走列表=[]
对于“漫游动画”列表中的文件:#设置动画列表
img=pygame.image.load(文件)
wid=img.get_width()
hei=img.get_height()
img=pygame.transform.scale(img,(int(wid/2.5),int(hei/2.5))#chaging scale
img=img.地下((70,35,新img_宽度-125,新img_高度-45))
右行走列表。附加(img)
walk_left_list.append(pygame.transform.flip(img,True,False))#镜像列表
定义初始(self,x,y,):
超级(人,自我).\uuuuu init\uuuuuuuu()
self.walk\u left\u list=Man.walk\u left\u list
self.walk\u right\u list=Man.walk\u right\u list
self.width=Man.new\u img\u width
self.height=Man.new\u img\u height
self.hitbox=(x+55,y+35,self.width-125,self.height-45)#这些数字没有什么特别之处,只是反复尝试而已
self.rect=Man.random\u-image\u-after\u-crop.get\u-rect()
self.rect.x=x
自校正y=y
def game_redraw():#在主循环末尾打印内容
全球权利
全球左派
屏幕。blit(背景图像,(0,0))
如果正确:
blit(man.walk\u right\u list[frame\u count//3],(man.rect.x,man.rect.y))
左埃利夫:
blit(man.walk\u left\u list[frame\u count//3],(man.rect.x,man.rect.y))
其他:
如果最后一个动作==“正确”:
blit(man.right\u idle\u list[frame\u count//13],(man.rect.x,man.rect.y))
如果最后一个动作==“左”:
blit(man.left\u idle\u list[frame\u count//13],(man.rect.x,man.rect.y))
否则:#只是第一步
blit(man.right\u idle\u list[frame\u count//13],(man.rect.x,man.rect.y))
pygame.draw.rect(屏幕,红色,man.rect,4)
pygame.display.flip()
右=假
左=假
def输入_过程(关键):
全球权利
全球左派
全球最后行动
全球人
全局帧计数
全球跳转
全球负
全局跳转计数
#
如果是跳转:
如果跳转计数>=-10:#检查是否跳转
如果跳转计数<0:
负=-1
man.rect.y-=(跳跃计数**2)*负*0.5
跳转计数-=1
其他:
负=1
是_jump=False吗
#
如果键[pygame.K_RIGHT]和man.rect.RIGHT+速度0:
如果正确:
帧计数=0
右=假
左=真
最后一个动作=“左”
man.rect.x-=速度
#
如果不是跳转:
如果键[pygame.K_UP]:
跳转计数=10
是真的吗
w=1728
h=972
pygame.init()
红色=(255,0,0)
images\u folder=r'C:\Users\aviro\Desktop\python projects\platform game\images'+'\'
bg_image=images_文件夹+“background.png”#设置背景图像
地面高度=h-143#图像地面的高度
人=人(200,地面高度)
man.rect.bottom=地面高度
clock=pygame.time.clock()
刷新率=54
速度=5
右=假
左=假
帧计数=0
完成=错误
最后一个动作=“”
#跳伞
是_jump=False吗
跳转计数=10
负=1
#
screen=pygame.display.set_模式((w,h))
bg_image=pygame.image.load(bg_image.convert()#只能在设置surface后进行转换。
#主回路
虽然没有完成:
如果帧计数>=51:
帧计数=0
对于pygame.event.get()中的事件:
如果events.type==pygame.QUIT:
完成=真
key=pygame.key.get_pressed()
输入过程(关键)
游戏重画()
帧计数+=1
时钟滴答声(刷新率)
我正在尝试使用pygame模块创建一个简单的射击平台游戏。除了跳跃,一切都很好。见第88行。运动员像x^2抛物线一样跳跃。我在终点加了*0.5,让球员跳得更慢、更低,但当我这么做的时候,就是这样

跳跃前:

跳跃后:


看第二张图片。地板和运动员之间有一段距离。当我删除*0.5时,一切正常。为什么?

如果编辑在撰写问题时提供了需求反馈,请不要通过玩弄系统来回避这些需求。这些要求是为了帮助你,而不是让它变得更加困难