Pyy轴不工作

2024-09-28 05:21:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个自上而下的生存游戏。碰撞问题:

我让玩家和板凳碰撞,问题是,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=players x coords,playery=players y coords,playerw=players width,playerh=players h,268、368、392和442是板凳上的左下右坐标。你知道吗

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

编辑:

修正了一半,底部、左侧和右侧碰撞有效,而不是顶部。你知道吗


Tags: and代码游戏编辑ifcoordswidthplayers
1条回答
网友
1楼 · 发布于 2024-09-28 05:21:21

尝试将第一行中的392更改为386。你设置了错误的限制,所以支票被忽略了。你知道吗

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

相关问题 更多 >

    热门问题