home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Aventura / CheeseHunt.swf / scripts / DefineSprite_239 / frame_1 / DoAction.as < prev   
Encoding:
Text File  |  2005-08-04  |  2.6 KB  |  122 lines

  1. function hitPlatforms()
  2. {
  3.    var i;
  4.    var y;
  5.    var x;
  6.    i = 0;
  7.    while(i < _root.maxPlatforms)
  8.    {
  9.       platform = eval("_root.platform" + i);
  10.       y = _Y + vertical;
  11.       x = _X + horizontal;
  12.       if(_Y < platform._y && y >= platform._y && platform.hitTest(x,platform._y) == true)
  13.       {
  14.          _Y = platform._y;
  15.          falling = false;
  16.          vertical = 0;
  17.          return undefined;
  18.       }
  19.       i++;
  20.    }
  21.    platform = null;
  22.    return undefined;
  23. }
  24. function render()
  25. {
  26.    var x;
  27.    var y;
  28.    x = y = 0;
  29.    if(Math.abs(horizontal) < Math.abs(x))
  30.    {
  31.       horizontal = x;
  32.    }
  33.    else
  34.    {
  35.       horizontal *= friction;
  36.       if(Math.abs(horizontal) < 1)
  37.       {
  38.          horizontal = 0;
  39.       }
  40.    }
  41.    if(vertical == 0 && _root.hero.hitTest(_root.mushroom) && _root.hero._y == 285.25 || vertical == 0 && _root.hero.hitTest(_root.mushroom2) && _root.hero._y == 285.25 || vertical == 0 && _root.hero.hitTest(_root.mushroom3) && _root.hero._y == 285.25)
  42.    {
  43.       _root.hero._y -= 100;
  44.       vertical = vforce * -1;
  45.       horizontal += platform.velocity;
  46.       platform = null;
  47.       rising = true;
  48.       if(_root.direction == 0)
  49.       {
  50.          gotoAndStop(4);
  51.       }
  52.       else
  53.       {
  54.          gotoAndStop(5);
  55.       }
  56.    }
  57.    if(vertical == 0 && Key.isDown(38) == true and _root.alive == "yes" || vertical == 0 && Key.isDown(32) == true and _root.alive == "yes")
  58.    {
  59.       vertical = vforce * -1;
  60.       horizontal += platform.velocity;
  61.       platform = null;
  62.       rising = true;
  63.       if(_root.direction == 0)
  64.       {
  65.          gotoAndStop(4);
  66.       }
  67.       else
  68.       {
  69.          gotoAndStop(5);
  70.       }
  71.       jump.start();
  72.       jump.setVolume(100);
  73.    }
  74.    if(rising == true)
  75.    {
  76.       vertical *= gravity;
  77.       if(Math.abs(vertical) < 1)
  78.       {
  79.          vertical = Math.abs(vertical);
  80.          falling = true;
  81.          rising = false;
  82.          if(_root.direction == 0)
  83.          {
  84.             gotoAndStop(3);
  85.          }
  86.          else
  87.          {
  88.             gotoAndStop(2);
  89.          }
  90.       }
  91.    }
  92.    if(falling == true)
  93.    {
  94.       vertical += accel;
  95.       hitPlatforms();
  96.    }
  97.    lastX = _X;
  98.    lastY = _Y;
  99.    _Y = _Y + vertical;
  100.    _X = _X + horizontal + platform.velocity;
  101.    if(platform != null && platform.hitTest(_X,platform._y,true) == false)
  102.    {
  103.       vertical = 2;
  104.       falling = true;
  105.    }
  106. }
  107. vforce = 120;
  108. hforce = 10;
  109. horizontal = 0;
  110. vertical = 5;
  111. friction = 0.8;
  112. gravity = 0.5;
  113. accel = 1.5;
  114. rising = false;
  115. falling = true;
  116. lastX = _X;
  117. lastY = _Y;
  118. platform = null;
  119. jump = new sound();
  120. jump.attachSound("jump");
  121. stop();
  122.