0

过去一周我一直忙于制作游戏,但遇到了问题。我想做的是一个迷宫类型的游戏,你必须找到自己的出路。将会有一个动态灯光系统添加到这里,但稍后。现在,我遇到了播放器和墙壁碰撞的问题。这是编码:

if(back.hitTestPoint(plr.x + leftBumpPoint.x, plr.y + leftBumpPoint.y, true)){
leftBumping = true;
} else {
leftBumping = false;
}
if(back.hitTestPoint(plr.x + rightBumpPoint.x, plr.y + rightBumpPoint.y, true)){
rightBumping = true;
} else {
rightBumping = false;
}
if(back.hitTestPoint(plr.x + upBumpPoint.x, plr.y + upBumpPoint.y, true)){
upBumping = true;
} else {
upBumping = false;
}
if(back.hitTestPoint(plr.x + downBumpPoint.x, plr.y + downBumpPoint.y, true)){
downBumping = true;
} else {
downBumping = false;
}
if(leftBumping){
    if(xSpeed < 0){
        xSpeed *= -0.5;
    }
}
if(rightBumping){
    if(xSpeed > 0){
        xSpeed *= -0.5;
    }
}
if(upBumping){
    if(ySpeed < 0){
        ySpeed *= -0.5;
    }
}
if(downBumping){
    if(ySpeed > 0){
        ySpeed *= -0.5;
    }
}
if(Math.abs(xSpeed) < 0.5){
    xSpeed = 0;
}
if(xSpeed > maxSpeedConstant){
    xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){
    xSpeed = (maxSpeedConstant * -1);
}

所以,我遇到的问题是,当我的球员撞到墙壁时,他并没有停下来。相反,他只是减速到极慢的速度。我希望播放器完全停止。谁能帮我这个?PS。“back”是墙壁的实例名称,“plr”是玩家的名称。

4

0 回答 0