...

View Full Version : Controlling a game with keys



bfsog
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') {
document.images[0].src='manfire.gif';}

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

if (all == 'f') {
document.images[0].src='manfiring.gif';}

if (all == 'h') {
document.images[0].src='man.gif';}

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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum