Author Topic: I need Java Script Help  (Read 1370 times)

Offline formula1

  • Almost Regular
  • ***
  • Posts: 243
I need Java Script Help
« on: July 31, 2009, 06:40:05 PM »
I don't know where to put this,
But its my personal opinion that coding is an art....

here it goes

[spoilers:2ukxporg]var updown = 0;
var leftright = 0;
var ground = 0;
var reft = 1;
var i, imgs, pic;

function init(){
  var guy = document.getElementById("guy");
  imgs=["stand.png", "standleft.png", "jump.png", "jumpleft.png", "walk.png", "walkleft.png", "finishjump.png", "finishleft.png"];
  var preload = new Array();
  for(i=0; i<imgs.length; i++) {
    preload= new Image();
    preload.src = imgs;
  }
  i = 0;
  document.onkeydown=keyDown;
  document.onkeyup=keyUp;
  setTimeout("movesprite(updown,leftright)", 50);
}

function movesprite(hori, vert){
  var game = document.getElementById("game");
  var yvel = 0;
  x = parseInt(guy.style.left);
  y = parseInt(guy.style.top);
  if (ground = 0) {
    yvel += 3;
    if (hori = 1) { x += 1; right(1); reft = 1; }
    if (hori = -1) { x += -1; left(1); reft = 0; }
    if (hori = 0) { stand(1); }
  }else {
    if (hori = 1) { x += 3; right(0); reft = 1; }
    if (hori = -1) { x += -3; left(0); reft = 0; }
    if (hori = 0) { stand(0); }
    if (vert = 1) { yvel += -15; jump(); }
  }
  checkBounds();
  guy.style.left = x + "px";
  guy.style.top = y + "px";
}

function checkBounds(){
  if (x >= parseInt(game.style.width) + parseInt(game.style.left))
    {x = parseInt(game.style.width) + parseInt(game.style.left);}
  if (x <= parseInt(game.style.left))
    {x = parseInt(game.style.left);}
  if (y + yvel >= parseInt(game.style.height) + parseInt(game.style.top))
    {y = parseInt(game.style.height) + parseInt(game.style.top); ground = 1;}
  else {ground = 0; y += yvel;}
}

function jump(){
  if (reft = 1) {guy.src = imgs[2];}
  else {guy.src = imgs[3];}
}

function left(ground){
  if (ground = 1) {
    if (guy.src = imgs[1]) {guy.src = imgs[5];}
    else {guy.src = imgs[1];}
  }else {guy.src = imgs[7];}
}

function right(ground){
  if (ground = 1) {
    if (guy.src = imgs[0]) {guy.src = imgs[4];}
    else {guy.src = imgs[0];}
  }else {guy.src = imgs[6];}
}

function stand(ground){
  if (ground = 1) {
    if (reft = 1) {guy.src = imgs[0];}
    else {reft = imgs[1];}
  }else {
    if (reft = 1) {guy.src = imgs[6];}
    else {guy.src = imgs[7];}
  }
}
   
function keyDown(e){
  if (e.keyCode == 37) {leftright = -1;} /*left*/
  if (e.keyCode == 38) {updown = 1;} /*up*/
  if (e.keyCode == 39) {leftright = 1;} /*right*/
  /* if(e.keyCode == 40) is down */
}
   
function keyUp(e){
  if (e.keyCode == 37)
    {leftright = 0;}
  if (e.keyCode == 38)
    {updown = 0;}
  if (e.keyCode == 39)
    {leftright = 0;}
}[/spoilers:2ukxporg]


to me this looks solid....
but for some reason its not loading...
I'm pressure I've got my img id and my div id right.... so what could be the problem?

no pressure in answering here, I'm going to ask around other websites also...
I want the wisest things to happen
If you like stuff. That stuff will always exsist.... IN YOUR MIND! OH SHNAP! UNLESS U FORGETZ IT! OR SHNAP! maybe...
Destryers Inc