Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Controlling a game with keys

    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...
    Code:
    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
    Attached Files Attached Files

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •