From ccccc7c5dc48b5c031ca80521df7075f755eec96 Mon Sep 17 00:00:00 2001 From: WildZero Date: Wed, 26 Jun 2013 23:07:33 +0400 Subject: [PATCH] add player health --- css/app.css | 16 +++++++++++----- index.html | 7 ++++++- js/app.js | 21 ++++++++++++++++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/css/app.css b/css/app.css index 049b6a5..b395a62 100644 --- a/css/app.css +++ b/css/app.css @@ -18,21 +18,27 @@ canvas { .wrapper { width: 512px; margin: 0 auto; - margin-top: 2em; + margin-top: 0em; } #instructions { - float: left; font-family: sans-serif; color: #757575; } - -#score { +#health{ + float: left; + color: white; + font-size: 2em; +} +#score{ float: right; color: white; font-size: 2em; } - +.params{ + height:40px; + width:100%; +} .key { color: #aaffdd; } diff --git a/index.html b/index.html index 9f56735..d00e0ec 100644 --- a/index.html +++ b/index.html @@ -27,8 +27,13 @@

GAME OVER

shoot with space +
+ +
Health:
+
+
+ -
diff --git a/js/app.js b/js/app.js index 818cd13..2d6b351 100644 --- a/js/app.js +++ b/js/app.js @@ -52,6 +52,7 @@ resources.onReady(init); // Game state var player = { + health: 100, pos: [0, 0], sprite: new Sprite('img/sprites.png', [0, 0], [39, 39], 16, [0, 1]) }; @@ -67,6 +68,7 @@ var terrainPattern; var score = 0; var scoreEl = document.getElementById('score'); +var healtEl = document.getElementById('health-value'); // Speed in pixels per second var playerSpeed = 200; @@ -94,6 +96,7 @@ function update(dt) { checkCollisions(); scoreEl.innerHTML = score; + healtEl.innerHTML = player.health; }; function handleInput(dt) { @@ -233,7 +236,23 @@ function checkCollisions() { } if(boxCollides(pos, size, player.pos, player.sprite.size)) { - gameOver(); + if (player.health == 0){ + gameOver(); + }else{ + player.health -= 10 + enemies.splice(i, 1); + i--; + explosions.push({ + pos: pos, + sprite: new Sprite('img/sprites.png', + [0, 117], + [39, 39], + 16, + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], + null, + true) + }); + } } } }