diff --git a/img/exclaimation.png b/img/exclaimation.png index 41c93fa..e54b6b5 100644 Binary files a/img/exclaimation.png and b/img/exclaimation.png differ diff --git a/img/mushroom-01.png b/img/mushroom-01.png new file mode 100644 index 0000000..514e5b2 Binary files /dev/null and b/img/mushroom-01.png differ diff --git a/img/pip.png b/img/pip.png index 389bc52..f9e780d 100644 Binary files a/img/pip.png and b/img/pip.png differ diff --git a/img/pip_left.png b/img/pip_left.png index 2473da2..1746b4f 100644 Binary files a/img/pip_left.png and b/img/pip_left.png differ diff --git a/img/pip_right.png b/img/pip_right.png index c704c6b..512bf0e 100755 Binary files a/img/pip_right.png and b/img/pip_right.png differ diff --git a/img/pip_up.png b/img/pip_up.png index b86d7e1..26845fe 100644 Binary files a/img/pip_up.png and b/img/pip_up.png differ diff --git a/index.html b/index.html index 2a933f2..a0ddafc 100644 --- a/index.html +++ b/index.html @@ -31,5 +31,7 @@ + + \ No newline at end of file diff --git a/js/game.js b/js/game.js index 9496d74..159cb01 100644 --- a/js/game.js +++ b/js/game.js @@ -11,12 +11,12 @@ var pHeight = 30; var ghostS = 20; -var drawHitboxes = true; +var drawHitboxes = false; function startGame() { pip = new player(pWidth, pHeight, 0 + pWidth*2, canvasHeight - pHeight-30); ghost = new fairy(ghostS, ghostS, 50, 50, pip); - enemies.push( new zombie(30, 30, 100, 100) ); + enemies.push( new zombie(30, 30, 20, 100) ); //enemies.push( new enemy(ghostS, ghostS, 50, 50, pip, "ghost") ); //enemies.push( new enemy(ghostS, ghostS, 50, 50, enemies[0], "ghost") ); //enemies.push( new enemy(ghostS, ghostS, 50, 50, enemies[1], "ghost") ); @@ -50,6 +50,15 @@ var game = { this.keydown = function (e) { game.keys = (game.keys || []); game.keys[e.keyCode] = true; + + // Enable Hitboxes + if (game.keys && game.keys[66]) { + if(drawHitboxes == false) { + drawHitboxes = true; + } else { + drawHitboxes = false; + } + } }; this.keyup = function (e) { game.keys[e.keyCode] = false; @@ -115,16 +124,16 @@ function player(width, height, x, y) { } this.iframes -= 1; } + ctx.drawImage(img, this.x, this.y, this.width, this.height); if(drawHitboxes) { // T R B L // 0 1 2 3 let hitbox = this.hitbox(); ctx.fillStyle = 'blue'; + ctx.globalAlpha = 0.4; ctx.fillRect(hitbox[3], hitbox[0], hitbox[1]-this.x, hitbox[2]-this.y); } - - ctx.drawImage(img, this.x, this.y, this.width, this.height); ctx.globalAlpha = 1; } @@ -326,17 +335,19 @@ function zombie(width, height, x, y) { } else { img = document.getElementById(`right_zombie`); } + ctx.drawImage(img, this.x, this.y, this.width, this.height); if(drawHitboxes) { // T R B L // 0 1 2 3 + ctx.globalAlpha = 0.4; let hitbox = this.hitbox(); ctx.fillStyle = 'green'; ctx.fillRect(hitbox[3], hitbox[0], hitbox[1]-this.x, hitbox[2]-this.y); } + ctx.globalAlpha = 1; - ctx.drawImage(img, this.x, this.y, this.width, this.height); } this.move = function() { @@ -457,7 +468,10 @@ function sound(src) { } var collision = { + // T R B L + // 0 1 2 3 collide: function (el1, el2) { + // Every case where there isn't a collision possible return !( el1[0] > el2[2] || el1[1] < el2[3] || @@ -467,6 +481,7 @@ var collision = { }, inside: function (el1, el2) { + // Every condition to be inside of each other return ( ((el2[0] <= el1[0]) && (el1[0] <= el2[2])) && ((el2[0] <= el1[2]) && (el1[2] <= el2[2])) &&