From 79639e8a26b20a7243d458633666626a9071c3f1 Mon Sep 17 00:00:00 2001 From: neingeist Date: Tue, 14 Aug 2012 20:41:20 +0200 Subject: [PATCH] movable player --- herzle.html | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/herzle.html b/herzle.html index 5e8adfc..243c07e 100644 --- a/herzle.html +++ b/herzle.html @@ -20,14 +20,56 @@ t = -Math.PI/2; } - setTimeout("timed()", 100); + // setTimeout("timed()", 100); + } + + player_pos = 0; + + document.onkeydown = onKeyDown; + + function onKeyDown(e) { + e = e || window.event; + + var player = document.getElementById("player"); + + if (e.keyCode == '37') { // left + player_pos -= 10; + player.style.left = player_pos; + } + if (e.keyCode == '39') { // right + player_pos += 10; + player.style.left = player_pos; + } + if (e.keyCode == '32') { // space = fire + var pewpew = document.getElementById("pewpew"); + pewpew.innerHTML = "pew! pew!"; + } } + + - - <3 + + <3 + < +