added explosion logic
This commit is contained in:
parent
1548ffe121
commit
ff1a6af687
|
|
@ -12,6 +12,7 @@ function spawnEnemy() {
|
||||||
if (document.elementFromPoint(alien.offsetLeft, alien.offsetTop).classList.contains("alien") == false) {
|
if (document.elementFromPoint(alien.offsetLeft, alien.offsetTop).classList.contains("alien") == false) {
|
||||||
document.body.appendChild(alien);
|
document.body.appendChild(alien);
|
||||||
aliens.push(alien);
|
aliens.push(alien);
|
||||||
|
console.log("Alien Spawned")
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +29,7 @@ function spawnBomb() {
|
||||||
alien.appendChild(bomb);
|
alien.appendChild(bomb);
|
||||||
bombLogic = setInterval(fall, 100);
|
bombLogic = setInterval(fall, 100);
|
||||||
bombs.push([bomb, bombLogic]);
|
bombs.push([bomb, bombLogic]);
|
||||||
|
console.log("Bomb Spawned")
|
||||||
}
|
}
|
||||||
|
|
||||||
function fall() {
|
function fall() {
|
||||||
|
|
@ -39,6 +41,10 @@ function fall() {
|
||||||
if(Math.floor(Math.random() * 4) == 3) {
|
if(Math.floor(Math.random() * 4) == 3) {
|
||||||
clearInterval(element[1]);
|
clearInterval(element[1]);
|
||||||
element[0].className = "explosion";
|
element[0].className = "explosion";
|
||||||
|
console.log("Explosion" + bombs.length)
|
||||||
|
setTimeout(() => {element[0].remove()}, 3000);
|
||||||
|
bombs.splice(bombs.indexOf(element),1);
|
||||||
|
console.log("Bomb Despawned" + bombs.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue