home *** CD-ROM | disk | FTP | other *** search
/ Fraggle Rock Season 1 Bonus CD / Fraggle Rock Season 1 Bonus CD.iso / pc / Game / Game.swf / scripts / DefineSprite_219_wembley / frame_1 / DoAction.as
Encoding:
Text File  |  2005-06-24  |  7.9 KB  |  347 lines

  1. function go()
  2. {
  3.    this.action = bounce;
  4. }
  5. function bounce()
  6. {
  7.    accelerate();
  8.    move();
  9.    bouncercollide();
  10.    munchcollide();
  11.    bounds();
  12.    checksplash();
  13. }
  14. function bounds()
  15. {
  16.    if(_X + RIGHTFUDGE >= _root.RIGHTWALL)
  17.    {
  18.       _X = _X - (_X + RIGHTFUDGE - _root.RIGHTWALL);
  19.       vx = - vx;
  20.    }
  21.    if(_X + LEFTFUDGE <= _root.LEFTWALL)
  22.    {
  23.       _X = _X + (_root.LEFTWALL - (_X + LEFTFUDGE));
  24.       vx = - vx;
  25.    }
  26.    if(_Y + TOPFUDGE <= _root.CEILING)
  27.    {
  28.       _Y = _Y + (_root.CEILING - (_Y + TOPFUDGE));
  29.       vy = 0;
  30.       vx = 0;
  31.       this.action = feather;
  32.    }
  33. }
  34. function accelerate()
  35. {
  36.    vyi = vy + a * dt;
  37.    dy = (vy + vyi) * 0.5 * dt * speed_multiplier;
  38.    if(Math.abs(dy) > MAXDIST)
  39.    {
  40.       dy = MAXDIST * (dy <= 0 ? -1 : 1);
  41.       vyi = Math.abs(vyi) <= Math.abs(vy) ? vyi : vy;
  42.    }
  43.    if(vyi >= 0 && vy <= 0 && _currentframe != frame_fall)
  44.    {
  45.       this.gotoAndPlay(frame_startfall);
  46.    }
  47. }
  48. function move()
  49. {
  50.    _Y = _Y + dy;
  51.    _X = _X + (vx * dt * speed_multiplier + (_root.bouncer._x - (_X + FOOTX + 5)) * _root.BINDI);
  52.    vy = vyi;
  53. }
  54. function feather()
  55. {
  56.    accelerate();
  57.    if(dy > max_dy)
  58.    {
  59.       dy = max_dy;
  60.       vyi = Math.abs(vyi) <= Math.abs(vy) ? vyi : vy;
  61.    }
  62.    move();
  63.    bouncercollide();
  64.    bounds();
  65.    checksplash();
  66. }
  67. function bouncercollide()
  68. {
  69.    if(_Y + FOOTY >= _root.BOUNCERZONE && vy > 0 && _root.bouncer.hitzone.hitTest(_X + FOOTX,_Y + FOOTY - TINA,true))
  70.    {
  71.       var _loc3_ = Math.max(-1,Math.min(1,3 * (_X + FOOTX + 5 - _root.bouncer._x) / _root.bouncer._width));
  72.       vx = (- _loc3_) * side_fling;
  73.       vy = (- vy) * (1 - Math.abs(_loc3_) * middlepower) * damping - bounce_amount;
  74.       _root.bouncer.bounce();
  75.       this.gotoAndPlay(this.frame_bounce);
  76.       this.bouncecounter = 14;
  77.       this.action = bouncer;
  78.    }
  79. }
  80. function bouncer()
  81. {
  82.    this.play();
  83.    if(this.bouncecounter < 13 && this._currentframe >= this.frame_bouncebottom)
  84.    {
  85.       this.action = bounce;
  86.    }
  87.    else if(this.bouncecounter < 0)
  88.    {
  89.       this.action = bounce;
  90.    }
  91.    this.bouncecounter = this.bouncecounter - 1;
  92. }
  93. function powerup(p)
  94. {
  95.    if(p < P_MULTIMUNCH)
  96.    {
  97.       return undefined;
  98.    }
  99.    this.ptime = PFRAMES;
  100.    this.power = Math.max(this.power,p);
  101.    _root.game.stopsound("s_synth");
  102.    _root.game.stopsound("s_drumloop");
  103.    _root.game.playsoundloop(this.power != P_MULTIMUNCH ? "s_synth" : "s_drumloop");
  104. }
  105. function munchcollide()
  106. {
  107.    if(!_root.maze.hitTest(_X + MOUTHX,_Y + MOUTHY,false))
  108.    {
  109.       return false;
  110.    }
  111.    var _loc9_ = 0;
  112.    while(_loc9_ < _root.maze.brickclipno)
  113.    {
  114.       var _loc5_ = _root.maze["brick" + _loc9_];
  115.       if(_loc5_._alpha == 100 && !_loc5_.falling && _loc5_.hitTest(_X + MOUTHX,_Y + MOUTHY,false) && vy <= 0)
  116.       {
  117.          var _loc7_ = _loc5_.myi;
  118.          var _loc6_ = _loc5_.myj;
  119.          if(this.power == P_MULTIMUNCH)
  120.          {
  121.             var _loc8_ = undefined;
  122.             var _loc4_ = -1;
  123.             while(_loc4_ <= 1)
  124.             {
  125.                var _loc3_ = -1;
  126.                while(_loc3_ <= 1)
  127.                {
  128.                   if(_root.maze.hasbrick(_loc4_ + _loc7_,_loc3_ + _loc6_))
  129.                   {
  130.                      _loc8_ = _root.maze.brickat(_loc4_ + _loc7_,_loc3_ + _loc6_);
  131.                      _loc8_.eaten(this);
  132.                   }
  133.                   _loc3_ = _loc3_ + 1;
  134.                }
  135.                _loc4_ = _loc4_ + 1;
  136.             }
  137.          }
  138.          else
  139.          {
  140.             _loc5_.eaten(this);
  141.          }
  142.          _root.game.playsound("s_chomp");
  143.          _root.maze.hang();
  144.          this.gotoAndPlay(this.frame_eat);
  145.          this.munchcounter = 14;
  146.          this.action = munch;
  147.          if(this.power != P_ZIG)
  148.          {
  149.             vy = - vy;
  150.             vx = 0;
  151.          }
  152.          break;
  153.       }
  154.       _loc9_ = _loc9_ + 1;
  155.    }
  156. }
  157. function munch()
  158. {
  159.    this.play();
  160.    if(this.power == P_ZIG)
  161.    {
  162.       this.action = bounce;
  163.    }
  164.    if(this.munchcounter < 13 && this._currentframe >= this.frame_eatrelease)
  165.    {
  166.       this.action = feather;
  167.    }
  168.    else if(this.munchcounter < 0)
  169.    {
  170.       this.action = feather;
  171.    }
  172.    this.munchcounter = this.munchcounter - 1;
  173. }
  174. function jumpon()
  175. {
  176.    _X = _root.jumpfrom._x - LEFTFUDGE;
  177.    _Y = _root.jumpfrom._y;
  178.    vx = 180;
  179.    vy = -180;
  180.    this.jumpontime = 0;
  181.    this.action = jumpingon;
  182. }
  183. function jumpingon()
  184. {
  185.    accelerate();
  186.    move();
  187.    if(vy > 0.5)
  188.    {
  189.       var _loc4_ = 23;
  190.       var _loc3_ = this.jumpontime++ / _loc4_;
  191.       this.jumpontime = Math.min(_loc4_,this.jumpontime);
  192.       vx = (1 - _loc3_) * vx + _loc3_ * (invscaling * 0.1 * (_root.bouncer._x - (this._x + FOOTX + 5)));
  193.    }
  194.    bouncercollide();
  195.    checksplash();
  196. }
  197. function jumpeasy()
  198. {
  199.    this.jumpeasytime = 0;
  200.    this.action = jumpingeasy;
  201.    this.vy = 0;
  202. }
  203. function jumpingeasy()
  204. {
  205.    accelerate();
  206.    if(dy > max_dy)
  207.    {
  208.       dy = max_dy;
  209.       vyi = vy;
  210.    }
  211.    move();
  212.    var _loc3_ = 33;
  213.    var _loc4_ = this.jumpeasytime++ / _loc3_;
  214.    this.jumpeasytime = Math.min(_loc3_,this.jumpeasytime);
  215.    vx = (1 - _loc4_) * this.vx + _loc4_ * (invscaling * 0.05 * (_root.bouncer._x - (this._x + FOOTX + 5)));
  216.    bouncercollideeasy();
  217.    checksplash();
  218. }
  219. function bouncercollideeasy()
  220. {
  221.    if(_Y + FOOTY >= _root.BOUNCERZONE && vy > 0 && _root.bouncer.hitzone.hitTest(_X + FOOTX,_Y + FOOTY - TINA,true))
  222.    {
  223.       var _loc3_ = Math.max(-1,Math.min(1,3 * (_X + FOOTX + 5 - _root.bouncer._x) / _root.bouncer._width));
  224.       vx = 0;
  225.       vy = -222;
  226.       _root.bouncer.bounce();
  227.       this.gotoAndPlay(this.frame_bounce);
  228.       this.bouncecounter = 14;
  229.       this.action = bouncereasy;
  230.    }
  231. }
  232. function bouncereasy()
  233. {
  234.    this.play();
  235.    if(this.bouncecounter < 13 && this._currentframe >= this.frame_bouncebottom)
  236.    {
  237.       this.action = jumpingeasy;
  238.    }
  239.    else if(this.bouncecounter < 0)
  240.    {
  241.       this.action = jumpingeasy;
  242.    }
  243.    this.bouncecounter = this.bouncecounter - 1;
  244. }
  245. function splash()
  246. {
  247.    move();
  248.    _root.game.playsound("s_splash");
  249.    _root.game.fragglesplash(this);
  250.    this.action = swimaway;
  251. }
  252. function swimaway()
  253. {
  254.    this.removeMovieClip();
  255. }
  256. function checksplash()
  257. {
  258.    if(_Y + BOTTOMFUDGE >= _root.bouncer._y + 20)
  259.    {
  260.       _Y = _root.bouncer._y + 20 - BOTTOMFUDGE;
  261.       this.action = splash;
  262.    }
  263. }
  264. function gameoverf()
  265. {
  266.    _root.game.stopsound("s_synth");
  267.    _root.game.stopsound("s_drumloop");
  268.    this.action = fall;
  269. }
  270. function fall()
  271. {
  272.    accelerate();
  273.    move();
  274.    bounds();
  275.    checksplash();
  276. }
  277. frame_fall = 2;
  278. frame_bounce = 3;
  279. frame_bouncebottom = 6;
  280. frame_fly = 11;
  281. frame_eat = 12;
  282. frame_eatrelease = 18;
  283. frame_startfall = 23;
  284. speed_multiplier = 1.5;
  285. vx = 0.5 * this._height;
  286. vy = 0;
  287. a = 2.5 * _height;
  288. subframes = 2;
  289. dt = 1 / (20 * subframes);
  290. max_dy = 0.1 * this._height;
  291. damping = 0.9;
  292. middlepower = 0.4;
  293. bounce_amount = 1 * this._height;
  294. side_fling = 3 * this._width;
  295. w = _width / 2;
  296. h = _height / 2;
  297. TOPFUDGE = 10;
  298. BOTTOMFUDGE = _height - 5;
  299. LEFTFUDGE = 23;
  300. RIGHTFUDGE = 58;
  301. CENTERFUDGE = 40;
  302. FOOTY = 80;
  303. FOOTX = w;
  304. TINA = 3;
  305. MOUTHY = 23;
  306. MOUTHX = 38;
  307. this.jumpon();
  308. P_NONE = _root.P_NONE;
  309. P_HI = _root.P_HI;
  310. P_MULTIMUNCH = _root.P_MULTIMUNCH;
  311. P_ZIG = _root.P_ZIG;
  312. MAXDIST = _root.halfbrick * 4;
  313. invscaling = 1 / (speed_multiplier * dt);
  314. this.ptime = 0;
  315. this.power = 0;
  316. PFRAMES = 400;
  317. this.onEnterFrame = function()
  318. {
  319.    this.action();
  320.    this.action();
  321.    if(this.ptime > 0)
  322.    {
  323.       this.ptime = this.ptime - 1;
  324.    }
  325.    else
  326.    {
  327.       _root.game.stopsound("s_synth");
  328.       _root.game.stopsound("s_drumloop");
  329.       this.power = P_NONE;
  330.    }
  331.    if(this.breakstart)
  332.    {
  333.       this.jumpeasy();
  334.       this.breakstart = false;
  335.    }
  336.    if(this.breakdone)
  337.    {
  338.       this.go();
  339.       this.breakdone = false;
  340.    }
  341.    if(this.gameoverflag)
  342.    {
  343.       this.gameoverf();
  344.       this.gameoverflag = false;
  345.    }
  346. };
  347.