Итак, я сейчас работаю над игрой в качестве школьного проекта для курса по программированию, и я столкнулся с проблемой, когда игрок не может d ie «дотронуться» до стен, расположенных наверху, и Дно, Левая и Правая стены работает, хотя. Вот код для стен:
class Wall{
constructor(x, y, w, h, c){
this.x = x;
this.y = y;
this.width = w;
this.height = h;
this.color = c;
}
draw(ctx){
ctx.fillStyle = this.color;
ctx.fillRect(this.x, this.y, this.width, this.height);
}
}
var Wall1 = new Wall(0,0, 3, 850, "cyan");
var Wall2 = new Wall(600, 0, 3, 850, "cyan");
var Wall3 = new Wall(0, 425, 600, 3, "cyan");
function collision(ctx){
//Spelare 1
if(NotP1.x < Wall1.x + Wall1.width && NotP1.x > Wall1.x){
NotP1.x = NotP2.x;
return alert("Player 1 died, Player 2 Wins");
}
else if(NotP1.x > Wall2.x + Wall2.width && NotP1.x > Wall2.x){
NotP1.x = NotP2.x;
return alert("Player 1 died, Player 2 Wins");
}
else if(NotP1.x > Wall3.y + Wall3.height && NotP1.x > Wall3.y){
NotP1.x = NotP2.x;
return alert("Player 299 died, Player 2 Wins");
}
//Spelare 2
if(NotP2.x < Wall1.x + Wall1.width && NotP2.x > Wall1.x){
NotP2.x = NotP1.x;
return alert("Player 2 died, Player 1 Wins");
}
else if(NotP2.x > Wall2.x + Wall2.width && NotP2.x > Wall2.x){
NotP2.x = NotP1.x;
return alert("Player 2 died, Player 1 Wins");
}
Wall3.draw(ctx);
}