Python 向下滚动传送我的玩家pygame

Python 向下滚动传送我的玩家pygame,python,pygame,Python,Pygame,我有一个问题,每当我有我的滚动向上和向下为我的球员,我在高地上,然后跳下来与我的球员,这将故障我的碰撞逻辑。我不知道它为什么这么做 她的视频就是一个例子: 正如你们所看到的,我在高地上,当我因为某种原因跳下来时,我到处都会出故障 我的向上/向下滚动是这样做的,当我的播放器y为50时,它应该向上滚动我的播放器,当我的播放器为550时,它应该随着我的播放器的下降速度向下滚动我的播放器,但是,每当我的主循环中有这个代码时,它就会导致我的可碰撞矩形出现故障,即使我对所有边进行了碰撞以停止播放器 碰撞是玩

我有一个问题,每当我有我的滚动向上和向下为我的球员,我在高地上,然后跳下来与我的球员,这将故障我的碰撞逻辑。我不知道它为什么这么做

她的视频就是一个例子:

正如你们所看到的,我在高地上,当我因为某种原因跳下来时,我到处都会出故障

我的向上/向下滚动是这样做的,当我的播放器
y
为50时,它应该向上滚动我的播放器,当我的播放器为550时,它应该随着我的播放器的下降速度向下滚动我的播放器,但是,每当我的主循环中有这个代码时,它就会导致我的可碰撞矩形出现故障,即使我对所有边进行了碰撞以停止播放器

碰撞是玩家将要碰撞的矩形

if playerman.y > 550:
    for obj in object_list:
        obj.y -= playerman.fall
    for shot in shots:
        shot.y -= playerman.fall
    
    for collid in collids:
        collid.y -= playerman.fall
    tall11.y -= playerman.fall



if playerman.y < 50:
    for obj in object_list:
        obj.y += playerman.speed

    for shot in shots:
        shot.y += playerman.speed
    
    for collid in collids:
        collid.y += playerman.speed

    tall11.y += playerman.speed
如果playerman.y>550:
对于对象列表中的obj:
对象y-=playerman.fall
对于镜头中的镜头:
shot.y-=playerman.fall
对于碰撞中的碰撞:
collid.y-=playerman.fall
tall11.y-=playerman.fall
如果玩家y<50:
对于对象列表中的obj:
对象y+=玩家速度
对于镜头中的镜头:
shot.y+=playerman.speed
对于碰撞中的碰撞:
碰撞y+=玩家速度
tall11.y+=玩家速度
我的碰撞分为上下左右两部分

    platform_rect_list = [p.rect for p in collids]
    player_rect = playerman.get_rect()
    player_rect.topleft = (px, py)


        
    playerman.y = py
    if player_rect.collidelist(platform_rect_list) < 0:
        playerman.x = px
        
    move_right = keys[pygame.K_d]
    move_left = keys[pygame.K_a]
    if move_right:
        for obj in object_list:
            obj.x -= playerman.speed
        for shot in shots:
            shot.x -= playerman.speed
        
        for collid in collids:
            collid.x -= playerman.speed

        tall11.x -= playerman.speed

        
    if move_left:
        for obj in object_list:
            obj.x += playerman.speed


        for shot in shots:
            shot.x += playerman.speed
        for collid in collids:
            collid.x += playerman.speed

        tall11.x += playerman.speed



    platform_rect_list = [p.get_rect() for p in collids] # get_rect()
    player_rect = playerman.get_rect()
    player_rect.topleft = (px, py)

    playerman.y = py
    cI = player_rect.collidelist(platform_rect_list)
    if cI >= 0:
        # undo movement of platforms dependent on the direction and intersection distance
        dx = 0
        if move_right: 
            dx = platform_rect_list[cI].left - player_rect.right
        if move_left:
            dx = platform_rect_list[cI].right - player_rect.left
        for collid in collids:
            collid.x -= dx
            collid.get_rect()
        base1.x -= dx
        base2.x -= dx
        base3.x -= dx
        base4.x -= dx
        base5.x -= dx
        base6.x -= dx
        crate1.x -= dx
        base44.x -= dx
        end1.x -= dx
        base45.x -= dx
        stopmove1.x -= dx
        text_show_collision.x -= dx
        text1.x -= dx
        rop1.x -= dx
        text22.x -= dx
        text_show_collision2.x -= dx
        portal1.x -= dx
        base46.x -= dx
        tall11.x -= dx

        for shot in shots:
            shot.x -= dx



    if not playerman.isJump:  
        playerman.y += playerman.fall
        playerman.fall += 0.5
        playerman.isJump = False


    # For player to get on top of platform
        collide = False
        for collid in collids:
            if playerman.get_rect().colliderect(collid.rect):
                collide = True
                playerman.isJump = False
                playerman.JumpCount = 10
                right = True
                left = True
                playerman.y = collid.rect.top - playerman.height
                if playerman.rect.right > collid.rect.left and playerman.rect.left < collid.rect.left - playerman.width:
                    playerman.x = collid.rect.left - playerman.width
                if playerman.rect.left < collid.rect.right and playerman.rect.right > collid.rect.right + playerman.width:
                    playerman.x = collid.rect.right

                if playerman.direction == "jump":
                    playerman.direction = "Idle"
                    
                if playerman.direction == "jump2":
                    playerman.direction = "leftid"

                        



        if collide:
            playerman.isJump = False
            playerman.fall = 1
            

        # Player jumping
        if collide:
            if keys[pygame.K_SPACE]:
                playerman.isJump = True
                right = False
                left = False
            playerman.fall = 0

    ##  playerman.isJump = False  <--  omit this line.  already False
        # What will happen when player jumps
    else:

        collideBottom = False
        for collid in collids:
            if (playerman.get_rect().colliderect(collid.rect) and 
                playerman.y + playerman.height > collid.rect.bottom):
                
                collideBottom = True
                playerman.y = collid.rect.bottom
                break

        if not collideBottom and playerman.JumpCount >= 0:    
            playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount))*0.3
            playerman.JumpCount -= 1
            if playerman.direction == "right" or playerman.direction == "Idle":
                playerman.direction = "jump"

            if playerman.direction == "left" or playerman.direction == "leftid":
                playerman.direction = "jump2"




        else:
            playerman.isJump = False
            playerman.JumpCount = 10


    # redrawing the window
    redraw()

    # updating the game
    pygame.display.update()
# quiting the game
pygame.quit()

platform\u rect\u list=[p.rect表示碰撞中的p]
player\u rect=playerman.get\u rect()
player_rect.topleft=(px,py)
playerman.y=py
如果玩家列表(平台列表)小于0:
playerman.x=px
向右移动=键[pygame.K\u d]
向左移动=键[pygame.K_a]
如果向右移动(u):
对于对象列表中的obj:
obj.x-=玩家速度
对于镜头中的镜头:
shot.x-=playerman.speed
对于碰撞中的碰撞:
碰撞.x-=playerman.speed
tall11.x-=玩家速度
如果向左移动,请执行以下操作:
对于对象列表中的obj:
obj.x+=玩家速度
对于镜头中的镜头:
shot.x+=playerman.speed
对于碰撞中的碰撞:
碰撞x+=玩家速度
tall11.x+=玩家速度
platform_rect_list=[p.get_rect()表示碰撞中的p]#get_rect()
player\u rect=playerman.get\u rect()
player_rect.topleft=(px,py)
playerman.y=py
cI=玩家列表(平台列表)
如果cI>=0:
#根据方向和相交距离撤消平台的移动
dx=0
如果向右移动(u):
dx=平台列表[cI]。左-玩家列表。右
如果向左移动,请执行以下操作:
dx=平台列表[cI]。右-玩家列表。左
对于碰撞中的碰撞:
碰撞x-=dx
collid.get_rect()
base1.x-=dx
base2.x-=dx
base3.x-=dx
base4.x-=dx
base5.x-=dx
base6.x-=dx
板条箱1.x-=dx
base44.x-=dx
end1.x-=dx
base45.x-=dx
stopmove1.x-=dx
文本显示冲突。x-=dx
text1.x-=dx
rop1.x-=dx
text22.x-=dx
文本显示冲突2.x-=dx
portal1.x-=dx
base46.x-=dx
tall11.x-=dx
对于镜头中的镜头:
shot.x-=dx
如果不是playerman.isJump:
playerman.y+=playerman.fall
playerman.fall+=0.5
playerman.isJump=False
#让玩家登上平台的顶端
碰撞=错误
对于碰撞中的碰撞:
如果playerman.get_rect().collide rect(collid.rect):
碰撞=真
playerman.isJump=False
playerman.JumpCount=10
右=真
左=真
playerman.y=collid.rect.top-playerman.height
如果playerman.rect.right>collid.rect.left和playerman.rect.leftcollid.rect.right+playerman.width:
playerman.x=collid.rect.right
如果playerman.direction==“跳跃”:
playerman.direction=“空闲”
如果playerman.direction==“jump2”:
playerman.direction=“leftid”
如果发生碰撞:
playerman.isJump=False
playerman.fall=1
#运动员跳跃
如果发生碰撞:
如果键[pygame.K_SPACE]:
playerman.isJump=True
右=假
左=假
playerman.fall=0
##playerman.isJump=False collid.rect.bottom):
碰撞底部=真
playerman.y=collid.rect.bottom
打破
如果未碰撞底部和playerman.JumpCount>=0:
playerman.y-=(playerman.JumpCount*abs(playerman.JumpCount))*0.3
playerman.JumpCount-=1
如果playerman.direction==“right”或playerman.direction==“Idle”:
playerman.direction=“跳跃”
如果playerman.direction==“left”或playerman.direction==“leftid”:
playerman.direction=“jump2”
其他:
playerman.isJump=False
playerman.JumpCount=10
#重新绘制窗口
重画
#更新游戏
pygame.display.update()
#退出游戏
pygame.quit()
你们可以用矩形来运行和测试它,并没有图像,它的工作原理和在天空的平台上跳下来一样,你们会因为某种原因开始闪烁,即使碰撞对双方都有效


既然要滚动,也需要滚动播放器。要避免浮点精度问题,请使用