【问题标题】:pygame collisions y axis not workingpygame碰撞y轴不起作用
【发布时间】:2014-12-04 10:06:05
【问题描述】:

我正在制作一个自上而下的生存游戏。我的碰撞有问题:

我让玩家与长凳发生碰撞,问题是,x 轴碰撞有效,但 y 轴碰撞甚至检测不到。

if playerx + playerw > 268 and playerx < 368 and playery + playerh > 392 and playery < 442:
    if playerx + playerw > 268 and playerx + playerw < 275:
        playerx -= 5
    if playerx > 360 and playerx < 368:
        playerx += 5
    if playery > 430 and playery < 441:
        playery += 5
    if playery + playerh > 386 and playery + playerh < 392:
        playery -= 5

代码很明显,playerx = 玩家 x 坐标,playy = 玩家 y 坐标,,playerw = 玩家宽度,,playerh = 玩家 h,,268、368、392 和 442 是板凳的左上角和下角正确的坐标。

再一次,我可以左右碰撞,但不能上下碰撞,有什么解决办法吗?

编辑:

修复了一半,底部,左侧和右侧的碰撞工作,而不是顶部。

【问题讨论】:

    标签: python pygame collision-detection collision


    【解决方案1】:

    尝试将第一行中的392 更改为386。您设置了错误的限制,因此检查被忽略。

    if playerx + playerw > 268 and playerx < 368 and playery + playerh > 386 and playery < 442:
    

    【讨论】:

      猜你喜欢
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多