HTML5キャンバスでゲームをプログラミングしています。ラインが自分のラインまたは対戦相手のラインのいずれかのポイントに接触すると、そのラインは移動を停止します。私が書いた関数は以下のとおりです。
function hasPoints(x, y) {
for (var i = 0; i < points.length; i++) {
if (Math.abs(points[i][0] - x) < 2 && Math.abs(points[i][1] - y) < 2) {
return true;
break;
}
}
return false;
}
//check if this point crosses other players' points
if (hasPoints(p1.x,p1.y) || canPlay==false) {
clearLoop();
}else{
context.fillStyle = "green";
context.fillRect(p1.x,p1.y, 5,5);
addPoints(p1.x,p1.y);
sendMyPoints();
loopTimer = setTimeout('drawLine()', 50);
}
ほとんどの場合機能します。しかし、いくつかの特別な場合(下の写真でわかるように)、それは単にfalseを返すことができません。
誰かが私がこの機能を改善して完璧に機能するように手助けしてくれませんか?