added comments
This commit is contained in:
parent
004c9755ef
commit
988843eb55
|
|
@ -8,6 +8,7 @@ function setVars() {
|
||||||
|
|
||||||
document.onloadend = setVars;
|
document.onloadend = setVars;
|
||||||
|
|
||||||
|
/*Controls vertical movement*/
|
||||||
function verticalMovement(keyCode) {
|
function verticalMovement(keyCode) {
|
||||||
var playerLeft = player.offsetLeft;
|
var playerLeft = player.offsetLeft;
|
||||||
var playerTop = player.offsetTop;
|
var playerTop = player.offsetTop;
|
||||||
|
|
@ -33,6 +34,7 @@ function verticalMovement(keyCode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Controls horizontal movement*/
|
||||||
function horizontalMovement(keyCode) {
|
function horizontalMovement(keyCode) {
|
||||||
var playerLeft = player.offsetLeft;
|
var playerLeft = player.offsetLeft;
|
||||||
var playerTop = player.offsetTop;
|
var playerTop = player.offsetTop;
|
||||||
|
|
@ -58,6 +60,7 @@ function horizontalMovement(keyCode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Controls movement interval*/
|
||||||
function move() {
|
function move() {
|
||||||
if (currentKey == 0) {
|
if (currentKey == 0) {
|
||||||
verticalMovement(lastKey);
|
verticalMovement(lastKey);
|
||||||
|
|
@ -73,11 +76,13 @@ function move() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Gets triggered keystroke*/
|
||||||
function getKey(event) {
|
function getKey(event) {
|
||||||
lastKey = currentKey;
|
lastKey = currentKey;
|
||||||
currentKey = event.keyCode;
|
currentKey = event.keyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Identifies if no keys are pressed*/
|
||||||
function stop(event) {
|
function stop(event) {
|
||||||
if (currentKey == lastKey) {
|
if (currentKey == lastKey) {
|
||||||
currentKey = 0;
|
currentKey = 0;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
var aliens = [];
|
var aliens = [];
|
||||||
var bombs = [];
|
var bombs = [];
|
||||||
|
|
||||||
|
/*Spawns Enemies*/
|
||||||
function spawnEnemy() {
|
function spawnEnemy() {
|
||||||
var alien = document.createElement("div");
|
var alien = document.createElement("div");
|
||||||
alien.className = "alien";
|
alien.className = "alien";
|
||||||
|
|
@ -19,6 +20,7 @@ function spawnEnemy() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Spawns a bomb*/
|
||||||
function spawnBomb() {
|
function spawnBomb() {
|
||||||
var alien = aliens[Math.floor(Math.random() * aliens.length)];
|
var alien = aliens[Math.floor(Math.random() * aliens.length)];
|
||||||
var bomb = document.createElement("div");
|
var bomb = document.createElement("div");
|
||||||
|
|
@ -33,6 +35,7 @@ function spawnBomb() {
|
||||||
console.log("Bomb Spawned")
|
console.log("Bomb Spawned")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Makes a random bomb fall a set amount and explodes if colliding with the floor*/
|
||||||
function fall() {
|
function fall() {
|
||||||
var bomb = bombs[Math.floor(Math.random() * bombs.length)];
|
var bomb = bombs[Math.floor(Math.random() * bombs.length)];
|
||||||
bomb[0].style.top = (bomb[0].offsetTop + 10) + "px";
|
bomb[0].style.top = (bomb[0].offsetTop + 10) + "px";
|
||||||
|
|
@ -52,6 +55,7 @@ function fall() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Checks to see if player is colliding with exploded bomb*/
|
||||||
function checkExplosion() {
|
function checkExplosion() {
|
||||||
for (let element of document.getElementsByClassName("explosion")) {
|
for (let element of document.getElementsByClassName("explosion")) {
|
||||||
var elemRect = element.getBoundingClientRect();
|
var elemRect = element.getBoundingClientRect();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ function showDisplay(mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Registers interval functions and trigger functions*/
|
||||||
function load() {
|
function load() {
|
||||||
document.addEventListener("keydown", getKey)
|
document.addEventListener("keydown", getKey)
|
||||||
document.addEventListener("keyup", stop)
|
document.addEventListener("keyup", stop)
|
||||||
|
|
@ -16,6 +17,7 @@ function load() {
|
||||||
document.getElementById("start").style.display = "block";
|
document.getElementById("start").style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Starts game functionality*/
|
||||||
function startGame() {
|
function startGame() {
|
||||||
showDisplay("block");
|
showDisplay("block");
|
||||||
document.getElementById("start").style.display = "none";
|
document.getElementById("start").style.display = "none";
|
||||||
|
|
@ -23,4 +25,5 @@ function startGame() {
|
||||||
setInterval(spawnEnemy, 2500);
|
setInterval(spawnEnemy, 2500);
|
||||||
setInterval(checkExplosion, 10);
|
setInterval(checkExplosion, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", load);
|
document.addEventListener("DOMContentLoaded", load);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue