neingeist
/
30shooter
Archived
1
0
Fork 0

score counter

master
neingeist 12 years ago
parent af23e757c3
commit 4cd344cec5

@ -16,6 +16,11 @@
position: absolute; position: absolute;
top: 10%; top: 10%;
} }
#herzles {
position:absolute;
top: 10%;
left: 10%;
}
#pewpew { #pewpew {
position:absolute; position:absolute;
top: 10%; top: 10%;
@ -31,6 +36,7 @@
<div id="enemy">3</div> <div id="enemy">3</div>
<div id="player">&lt;</div> <div id="player">&lt;</div>
<div id="pewpew"></div> <div id="pewpew"></div>
<div id="herzles"></div>
</body> </body>
</html> </html>

@ -4,6 +4,7 @@ player_pos = [0.5 * window.innerWidth, 0.9 * window.innerHeight];
enemy_pos = [0.5 * window.innerWidth, 0.1 * window.innerHeight]; enemy_pos = [0.5 * window.innerWidth, 0.1 * window.innerHeight];
new_enemy_pos = [enemy_pos[0], enemy_pos[1]]; new_enemy_pos = [enemy_pos[0], enemy_pos[1]];
pewpew = 0; pewpew = 0;
herzles = 0;
document.onkeydown = onKeyDown; document.onkeydown = onKeyDown;
@ -23,7 +24,7 @@ function onKeyDown(e) {
shoots = []; shoots = [];
function shoot(pos) { function shoot(pos) {
shoots[shoots.length] = [pos[0], pos[1]]; shoots[shoots.length] = [pos[0], pos[1], false];
// pewpew = 5; // pewpew = 5;
} }
@ -54,6 +55,10 @@ function detectCollisions() {
var shootdiv = document.getElementById('shoot' + i); var shootdiv = document.getElementById('shoot' + i);
if (shootdiv && isCollided(shootdiv, enemydiv)) { if (shootdiv && isCollided(shootdiv, enemydiv)) {
pewpew = 5; pewpew = 5;
if (!shoots[i][2]) {
herzles++;
shoots[i][2] = true; // hit once
}
} }
} }
} }
@ -96,6 +101,12 @@ function render() {
pewpewdiv.innerHTML = ""; pewpewdiv.innerHTML = "";
} }
// herzles
var herzlesdiv = document.getElementById("herzles");
if (herzles > 0) {
herzlesdiv.innerHTML = herzles + " &lt;3";
}
// render player // render player
var playerdiv = document.getElementById("player"); var playerdiv = document.getElementById("player");
playerdiv.style.left = (player_pos[0] playerdiv.style.left = (player_pos[0]