2
I only posted the JS, I think it’s enough, I’m still new to JS and programming so I know almost nothing of the commands, I want to compare the position of the balls and the area they appear so that they do not "be born" one inside the other, with what I can do this comparison inside the if?
function addBola () {
var bola = document.createElement("div");
bola.setAttribute("class", "bola");
var p1 = Math.floor(Math.random() * 1000);
var p2 = Math.floor(Math.random() * 500);
var corBolinha = Math.floor(Math.random() * 999);
bola.setAttribute("style", "left:" + p1 + "px; top:" + p2 +
"px; background-color: #" + corBolinha);
bola.setAttribute("onmousedown", "estourar(this)");
if(/*comparação vai aqui!!!*/) {
return false;
}else {
document.body.appendChild(bola);
}
}
function estourar(elemento) {
document.body.removeChild(elemento)
document.getElementById("placar").innerHTML++;
}
function errar(missed) {
document.getElementById("missClick").innerHTML++;
}
function iniciar() {
document.getElementById("placar").innerHTML = 0;
document.getElementById("missClick").innerHTML = 0;
setInterval(addBola, 600);
}
what are the dimensions of the ball? width, height or radius?
– vik
Div is 50px by 50px Radius 25 to let the div round
– Ricardo Gava