碰撞不能在javascript中工作

时间:2016-06-14 04:51:33

标签: javascript collision-detection

您好我在使用此代码时遇到了一些问题:

ctx.fillRect(enemy.x,enemy.y,enemy.w,enemy.h);
if( player.x > enemy.x && player.x > 299 && player.x<301 && player.y > 270) {
    player.x--;
    player.x--;
    player.x--;
    player.x--;
    player.x--;
    player.x--;
    player.x--;
    console.log("touch");
} 
else if (player.x > enemy.x && player.y > 270&& player.x < 320) {
   player.x++;
   player.x++;
   player.x++;
   player.x++;
   player.x++;
   player.x++;
}

发生的事情是,当我从一侧触摸时,块越来越大,当我从另一侧触摸时,它会直接通过。我想要发生的是它在两侧停止并且块不会变大。我不想使用引擎。提前谢谢。

0 个答案:

没有答案