我認爲有一個更好的方法,然後重複每個人一遍又一遍的相同的過程?更好的方式來繼續而不是重複
和碰撞方法,碰撞方法只適用於中心到中心的碰撞,這是非常好的。
var ereset = function(){
//Attacker 1
att1.x = 0 + (Math.random() * (canvas.width - 64));
att1.y = -60 ;
//Attacker 2
att2.x = 0 + (Math.random() * (canvas.width - 64));
att2.y = -60 ;
//Attacker 3
att3.x = 0 + (Math.random() * (canvas.width - 64));
att3.y = -60 ;
//Attacker 4
att4.x = 0 + (Math.random() * (canvas.width - 64));
att4.y = -60 ;
//Attacker 5
att5.x = 0 + (Math.random() * (canvas.width - 64));
att5.y = -60 ;
}
if (
hero.x <= (att1.x + 20 || att1.x + 32)
&& att1.x <= (hero.x + 20 || att1.x + 32)
&& hero.y <= (att1.y + 20 || att1.y - 32)
&& att1.y <= (hero.y + 20 || att1.y - 32)
){
end();
} else if(
hero.x <= (att2.x + 20 || att2.x + 32)
&& att2.x <= (hero.x + 20 || att2.x + 32)
&& hero.y <= (att2.y + 20 || att2.y - 32)
&& att2.y <= (hero.y + 20 || att2.y - 32)
){
end();
}else if(
hero.x <= (att3.x + 20 || att3.x + 32)
&& att3.x <= (hero.x + 20 || att3.x + 32)
&& hero.y <= (att3.y + 20 || att3.y - 32)
&& att3.y <= (hero.y + 20 || att3.y - 32)
){
end();
}else if(
hero.x <= (att4.x + 20 || att4.x + 32)
&& att4.x <= (hero.x + 20 || att4.x + 32)
&& hero.y <= (att4.y + 20 || att4.y - 32)
&& att4.y <= (hero.y + 20 || att4.y - 32)
){
end();
}
};
做功能?將值傳遞給對象。 – epascarello
數組和循環? – Musa