【问题标题】:Enemy Arms y Pos Glitches On Attack Pygame How To Fix?敌人武器 y Pos 攻击 Pygame 如何修复?
【发布时间】:2021-05-09 09:21:05
【问题描述】:

VIDEO 当我的敌人碰撞箱与玩家 rect 发生碰撞时,y 位置似乎发生了变化>

所以首先这行代码检查 hit 是 True 还是 Not 如果它是 true 然后如果玩家与 launch1.rec 发生碰撞然后开始将我的老板手臂移向玩家


        if hitting:
            if playerman.rect.colliderect(launch1.rect):
                if arms1.x < playerman.x  - 170:
                    arms1.x += playerman.speed
                if arms1.x > playerman.x - 190:
                    arms1.x -= playerman.speed
                arms1.y = math.cos(math.radians(arms1.time)) * 95
                arms1.time += 1

如果玩家没有与 launc1 碰撞箱发生碰撞,则保持 Boss 武器浮动

                
        if not playerman.rect.colliderect(launch1.rect) and not attacks2 and not pausemove:
            arms1.y =  math.cos(math.radians(arms1.time)) * 95
            arms1.time += 1

接下来我检查了我的 hits2 是否为真,并且玩家与 Boss 武器碰撞箱发生碰撞以欺骗攻击,然后让 attack1 = True


        if hittings2:
            if playerman.rect.colliderect(arms1.sing1):
                 attack1 = True

如果我的attack1 为真,则将我的bossarm1 稍微高一点,如果它的分级机然后190 将其关闭并使attack2 为true,这将使我的bossarm 向下移动并同时转动hits2 和hittings

        if attack1:
            hittings2 = False
            arms1.y = math.cos(math.radians(arms1.time3)) * 95
            arms1.time3 += 1
            if arms1.time3 >= 190:
                attack1 = False
                arms1.time3 = 0
                attacks2 = True
                hittings2 = False
                hitting = False 

然后在这里我检查了attacks2是否为真并且它没有与collidtest3 rects底部碰撞然后继续将其放下

        if attacks2:
            if not arms1.rect.bottom > collidtest3.rect.bottom:
                arms1.y += math.cos(math.radians(arms1.time)) * 15
                arms1.time += 1
                if arms1.time >= 190:
                    arms1.time = 0

那么下面这两行代码将重新开始我的攻击

        if arms1.rect.colliderect(collidtest3.rect):
            pausemove = True
            attacks2 = False
            attack1 = False
        if pausemove:
            if attack1timer < 270:
                attack1timer += 1
                arms1.y -= 1
                hittings2 = False

            else:
                hitting = True
                hittings2 = True
                pausemove = False
                attack1timer = 0
                if attack1:
                    arms1.time = 0

所有移动敌人并攻击玩家的逻辑

        if hitting:
            if playerman.rect.colliderect(launch1.rect):
                if arms1.x < playerman.x  - 170:
                    arms1.x += playerman.speed
                if arms1.x > playerman.x - 190:
                    arms1.x -= playerman.speed
                arms1.y = math.cos(math.radians(arms1.time)) * 95
                arms1.time += 1

                
        if not playerman.rect.colliderect(launch1.rect) and not attacks2 and not pausemove:
            arms1.y =  math.cos(math.radians(arms1.time)) * 95
            arms1.time += 1

        if hittings2:
            if playerman.rect.colliderect(arms1.sing1):
                 attack1 = True

            
        if attack1:
            hittings2 = False
            arms1.y = math.cos(math.radians(arms1.time3)) * 95
            arms1.time3 += 1
            if arms1.time3 >= 190:
                attack1 = False
                arms1.time3 = 0
                attacks2 = True
                hittings2 = False
                hitting = False 
                          
        if attacks2:
            if not arms1.rect.bottom > collidtest3.rect.bottom:
                arms1.y += math.cos(math.radians(arms1.time)) * 15
                arms1.time += 1
                if arms1.time >= 190:
                    arms1.time = 0
                
        if arms1.rect.colliderect(collidtest3.rect):
            pausemove = True
            attacks2 = False
            attack1 = False
            
        if pausemove:
            if attack1timer < 270:
                attack1timer += 1
                arms1.y -= 1
                hittings2 = False

            else:
                hitting = True
                hittings2 = True
                pausemove = False
                attack1timer = 0
                if attack1:
                    arms1.time = 0

【问题讨论】:

  • arms1.y += math.cos(math.radians(arms1.time)) * 15的原因是什么?这似乎不正确。

标签: python pygame


【解决方案1】:

很难说,因为你没有解释一切是什么。是挂在手臂上的绿色碎片吗?如果是这样,那么我认为问题就在这里,您将 arm1.y 移动 cos(arms1.time)。撞击似乎是在任何碰撞检查完成之前设置的,所以我不明白它是在哪里设置的。

    if hitting:
        if playerman.rect.colliderect(launch1.rect):
            if arms1.x < playerman.x  - 170:
                arms1.x += playerman.speed
            if arms1.x > playerman.x - 190:
                arms1.x -= playerman.speed
            arms1.y = math.cos(math.radians(arms1.time)) * 95
            arms1.time += 1

【讨论】:

    猜你喜欢
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2015-01-19
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多