过去一周我一直忙于制作游戏,但我遇到了一个问题。我想要做的是一个迷宫型游戏,你必须找到出路。将会有一个动态光系统添加到此,但稍后。现在,我遇到了玩家和墙壁碰撞的问题。这是编码:
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”是玩家的名称。