Move landscape up and down at the position of a bal?

(this is already posted on game/AI forum but here it is more effective i think:}
with the attachments:http://www.kirupa.com/forum/showthread.php?t=255187
)

Hey all,

I try to find the best way to program my game:

i have a doll or for the example swf a bal, and if it jumps up or move down the landscape (game envoirment) moves up or down…
dont judge the cleanness of the code its just made in 30 min just to show the example…


MC = MovieClip.prototype;
// JUMP VARS
MoveVars = {jumping:false, jump:12, jumpOrig:12, falling:false, jumpInt:null, dir:1, JP:function (mc) {
 this = mc;
 if (Key.isDown(Key.UP) && !this.jumping)
 {
  // als er nog niet gesprongen wordt!
  this.jumping = true;
 }
 if (this.jumping)
 {
  _root.bal.tog = null;
  this._y -= this.jump;
  this.jump -= .5;
  if (this.jump < 0)
  {
   this.falling = true;
  }
  if (_root.grond.hitTest(this._x, this._y, true) && this.falling)
  {
   _root.bal.tog = null;
   this.jump = this.jumpOrig;
   this.jumping = false;
   this.falling = false;
   clearInterval(this.jumpInt);
   this.jumpInt = null;
  }
 }
}, Move:function (mc) {
 this = mc;
 Y = this._y;
 speed = (this.jumping) ? 3 : 2;
 //
 if (this.dir == -1)
 {
  _root.grond._x -= (speed * this.dir);
 } else
 {
  _root.grond._x -= ((speed) * this.dir);
 }
 if (this.jumping == true)
 {
  return;
 }
 if (_root.grond.hitTest(this._x, this._y + 2, true))
 {
  this.tog = 1;
  for (i = 0; i < 1000; i++)
  {
   this._y--;
   if (!_root.grond.hitTest(this._x, this._y, true))
   {
    break;
    this.tog = null;
    return;
   }
  }
 } else if (!_root.grond.hitTest(this._x, this._y - 2, true))
 {
  for (i = 0; i < 1000; i++)
  {
   this.tog = 1;
   if (this._y >= 670)
   {
    this.tog = null;
   } else
   {
    this._y++;
   }
   if (_root.grond.hitTest(this._x, this._y, true))
   {
    break;
    this.tog = null;
    return;
   }
  }
 } else
 {
  this.tog = null;
 }
}};
MC.setjumpVars = function(mc) {
 for (i in _root.MoveVars)
 {
  mc* = _root.MoveVars*;
  //trace(i+" = "+this*)
 }
};
// set vars
bal.setjumpVars(bal);
var keyListener:Object = new Object();
keyListener.onKeyUp = function() {
 if (Key.getCode() == 39)
 {
  clearInterval(bal.MoveInt);
 }
 if (Key.getCode() == 37)
 {
  clearInterval(bal.MoveInt);
 }
 if (Key.getCode() == 37)
 {
  clearInterval(bal.MoveInt);
 }
};
keyListener.onKeyDown = function() {
 if (Key.getCode() == 38)
 {
  if (!bal.jumping)
  {
   //trace(bal.jumpIn)
   bal.jumping = true;
   bal.jumpInt = setInterval(bal.JP, 10, bal);
  }
 }
 if (Key.getCode() == 39)
 {
  bal.dir = 1;
  if (bal.MoveInt != null)
  {
   clearInterval(bal.MoveInt);
  }
  bal.MoveInt = setInterval(bal.Move, 10, bal);
 }
 if (Key.getCode() == 37)
 {
  bal.dir = -1;
  if (bal.MoveInt != null)
  {
   clearInterval(bal.MoveInt);
  }
  bal.MoveInt = setInterval(bal.Move, 10, bal);
 }
};
_root.grond.tog = 0;
_root.grond.onEnterFrame = function() {
 Y = _root.bal._y;
 X = _root.bal._x;
 if (_root.bal.tog == null)
 {
  this._y += ((680 - Y) - this._y) / 4;
  _root.bal.tog = 1;
 }
};
Key.addListener(keyListener);
 

take a look at the swf, move the keys LEFT , RIGTH or UP …

so the question is how can i move it up or down the best way the landscape on relative position of the bal?

Thanks all,

M