From 5c6cd33f393b65e05ff883244d99f07a76b01ce0 Mon Sep 17 00:00:00 2001
From: Joshua Perry <45966243+jpez-development@users.noreply.github.com>
Date: Thu, 28 Apr 2022 20:56:09 +0100
Subject: [PATCH] added bomb and alien spawn logic
---
game.html | 2 +-
scripts/enemy.js | 27 ++++++++++++++++++++++++++-
scripts/launch.js | 1 +
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/game.html b/game.html
index 3867a85..a980be1 100644
--- a/game.html
+++ b/game.html
@@ -5,6 +5,7 @@
+
@@ -39,7 +40,6 @@
-
diff --git a/scripts/enemy.js b/scripts/enemy.js
index 20a547d..f21b1e6 100644
--- a/scripts/enemy.js
+++ b/scripts/enemy.js
@@ -1 +1,26 @@
-/* enemy spawning logic */
\ No newline at end of file
+/* enemy spawning logic */
+var aliens = [];
+
+function spawnEnemy() {
+ var alien = document.createElement("div");
+ alien.className = "alien";
+ alien.id = "alien";
+ while (true) {
+ alien.style.left = Math.floor(Math.random() * document.body.offsetWidth) + "px";
+ if (document.elementFromPoint(alien.offsetLeft, alien.offsetTop).classList.contains("alien") == false) {
+ document.body.appendChild(alien);
+ aliens.push(alien);
+ break;
+ }
+ }
+}
+
+function spawnBomb() {
+ var alien = aliens[0];
+ var bomb = document.createElement("div");
+ bomb.className = "bomb";
+ bomb.style.left = "28px";
+ bomb.style.top = "70px";
+ bomb.style.zIndex = "-1";
+ alien.appendChild(bomb);
+}
diff --git a/scripts/launch.js b/scripts/launch.js
index 7b6a70e..abdf398 100644
--- a/scripts/launch.js
+++ b/scripts/launch.js
@@ -19,5 +19,6 @@ function load() {
function startGame() {
showDisplay("block");
document.getElementById("start").style.display = "none";
+ document.getElementsByClassName("weapon")[0].style.display = "none";
}
document.addEventListener("DOMContentLoaded", load);