问题描述
VIDEO 每当我的敌人碰撞箱与玩家碰撞时,y 位置似乎发生了变化,我不知道为什么它会发生变化,而且看起来又乱又乱,有什么办法可以解决这个问题吗?
所以首先这行代码检查击中是否为真,如果为真,然后玩家是否与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 是否为 true 并且玩家与 Boss 的武器碰撞箱碰撞以欺骗攻击,然后使 attack1 = True
if hittings2:
if playerman.rect.colliderect(arms1.sing1):
attack1 = True
如果我的attack1是真的,那么把我的boss arm1移高一点,如果它的grader然后190把它关掉并使attack2真,这将使我的boss手臂向下移动并同时转动hits2和hits
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
解决方法
很难说,因为你还没有解释一切是什么。垂在手臂上的绿色部分是?如果是这样,那么我认为问题就在这里,您通过 cos(arms1.time) 移动 arm1.y。碰撞似乎是在任何碰撞检查完成之前设置的,所以我不明白它是在哪里设置的。
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