diff --git a/game.html b/game.html index a980be1..78bafb6 100644 --- a/game.html +++ b/game.html @@ -39,7 +39,8 @@ - + + diff --git a/scripts/enemy.js b/scripts/enemy.js index f21b1e6..13119e2 100644 --- a/scripts/enemy.js +++ b/scripts/enemy.js @@ -1,10 +1,12 @@ /* enemy spawning logic */ var aliens = []; +var bombs = []; function spawnEnemy() { var alien = document.createElement("div"); alien.className = "alien"; alien.id = "alien"; + alien.style.zIndex = "2" while (true) { alien.style.left = Math.floor(Math.random() * document.body.offsetWidth) + "px"; if (document.elementFromPoint(alien.offsetLeft, alien.offsetTop).classList.contains("alien") == false) { @@ -16,11 +18,28 @@ function spawnEnemy() { } function spawnBomb() { - var alien = aliens[0]; + var alien = aliens[Math.floor(Math.random() * aliens.length)]; var bomb = document.createElement("div"); bomb.className = "bomb"; bomb.style.left = "28px"; bomb.style.top = "70px"; - bomb.style.zIndex = "-1"; - alien.appendChild(bomb); + bomb.style.zIndex = "1"; + bomb.style.display = "absolute"; + alien.appendChild(bomb); + bombLogic = setInterval(fall, 100); + bombs.push([bomb, bombLogic]); } + +function fall() { + var bomb = bombs[Math.floor(Math.random() * bombs.length)]; + bomb[0].style.top = (bomb[0].offsetTop + 10) + "px"; + + for (let element of bombs) { + if (document.elementFromPoint(element[0].offsetLeft, element[0].offsetTop).classList.contains("sky") != true) { + if(Math.floor(Math.random() * 4) == 3) { + clearInterval(element[1]); + element[0].className = "explosion"; + } + } + } +} \ No newline at end of file diff --git a/scripts/projectile.js b/scripts/projectile.js index f2e4835..4a0d746 100644 --- a/scripts/projectile.js +++ b/scripts/projectile.js @@ -1 +1,2 @@ -/* logic for bombs */ \ No newline at end of file +/* logic for bombs */ +