Hello, I have been playing around with a script. It is just a start of something like a really lame version of the street fighter layout. I am having trouble with figuring out how to get the character to move the way I want. I have mapped the WSAD keys. Well just the D key does anything and all it does now is what will be a special move kick that I will later change the key combo. I also mapped the N key to a kick. The really hard thing I just can't seem to ge right is just plane movement from left to right. I will also have to flip the character's image when he changes direction. you can check out what I have going at http://srisservice.com/funprojects/index.html
I had the code working a little better thatn it is now but I been trying to tweek it so much I messed something up. Anyway here is the code that I have

<!DOCTYPE html>
<html>
<head>
 <script type="text/javascript">
   var userWidth = window.screen.width;
function powerRight() {
var pp = document.getElementById("x");
var lft = parseInt(pp.style.left);
var tim = setTimeout("powerRight()",20);  // 20 controls the speed
lft = lft+20;  // move by 20 pixels
pp.style.left = lft+"px";
if (lft > userWidth) {  // left edge of image past the right edge of screen
pp.style.left = 10;  // back to the left
clearTimeout(tim);
}
}
function powerLeft() {
var pp = document.getElementById("x");
var lft = parseInt(pp.style.left);
var tim = setTimeout("powerRight()",20);  // 20 controls the speed
lft = lft-20;  // move by 20 pixels
pp.style.left = lft+"px";
if (lft < userWidth) {  // left edge of image past the right edge of screen
pp.style.left = 10;  // back to the left
clearTimeout(tim);
}
}
function highKick() {
document.images[0].src='samKick1.png';
}

   </script>
<!DOCTYPE html>
<script type="text/javascript">
document.onkeydown = function(event) {
    var key_press = String.fromCharCode(event.keyCode);
    var key_code = event.keyCode;

    if(key_press == "W") {
        alert("Put script to run for the W key here");  
    } else if(key_press == "A") {
        powerLeft();
    } else if(key_press == "S") {
        alert("Put script to run for the S key here");
    } else if(key_press == "D") {
        powerRight();
    } else if(key_press == "N") {
        highKick();
    }
}
document.onkeyup = function (event) {
    var key_press = String.fromCharCode(event.keyCode);
    if(key_press == "N") {
    document.images[0].src='samKick2.png';
    }
}
</script>

<link rel="icon" href="../images/logo.ico" type="image/x-icon" />
<title>KickButt</title>
<link rel="stylesheet" type="text/css" href="cool.css" />
<link rel="shortcut icon" href="../images/logo.ico " type="image/x-icon" />
</head>
<body >
<img id="x" style="position:relative;top:160px; left:1px;"   height="389" width="275" src="samKick2.png" alt="GoldenChild" />
</body>
</html>

I am not looking to just get someone to do this for me this is just a fun learning project I am doing for me and my son. Thanks

I know this is pretty fracking lame but come on how else am I supposed to learn. Maybe I do not know how to ask for help or maybe I should have put this in games development thread but this is just JavaScript and some CSS.

The A button (moving left) works for me. Try reviewing lines 8 and 19. I know very little about JavaScript, but I thought I'd give it a look. Lines 8 and 19 are identical, even though they don't seem like they should be
Surely
var lft = parseInt(pp.style.left);
isn't meant for both directions?
Hope I helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.