View Full Version : Controlling a game with keys

05-31-2004, 02:57 PM
I'm trying to create a game, which reacts on user keypresses. So far, when the user presses a, the man arms himself with a weapon, and h to hide the weapon, and f to fire.

What i'm after is for the user to press d or u (down or up) and for the image to move down or up.

ive tried...

function showText(e) {

if (e.keyCode) keycode=e.keyCode;
else keycode=e.which;
ch = String.fromCharCode(keycode);
all = ch;

if (all == 'a') {

if (all == 'd') {
document.getElementById("man").style.top -= 15;}

if (all == 'f') {

if (all == 'h') {

if (all == 'u') {
document.getElementById("man").style.top += 15;}

to no avail, he wont go up nor down.

I'll attach the whole file

thanks in advance

Willy Duitt
06-01-2004, 03:05 AM
Look here (http://www.codingforums.com/showthread.php?t=38980).