home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / bossbash.swf / scripts / DefineSprite_574_game_mario / frame_2 / DoAction.as
Encoding:
Text File  |  2007-09-28  |  16.3 KB  |  613 lines

  1. this.grav = 2;
  2. this.dude.Yvel = 0;
  3. this.dude.Xvel = 0;
  4. this.bubcount = 0;
  5. this.opencount = 0;
  6. this.dude.chargecount = 0;
  7. this.vegcount = 500;
  8. this.vegarray = new Array();
  9. this.allarray = new Array();
  10. this.dude.blink = false;
  11. this.dude.blinkcount = 0;
  12. this.dude.floatcount = 0;
  13. this.hitcount = 0;
  14. tim0 = 5370;
  15. this.hp = 2;
  16. this.createEmptyMovieClip("bubs",100);
  17. d = this.dude.attachMovie("bomtoons_dude" + this.whichdude,"guts",0);
  18. d._xscale = 90;
  19. d._yscale = d._xscale;
  20. if(this.whichdude == 0)
  21. {
  22.    this.speed = 2.2;
  23.    this.maxjump = 13.8;
  24.    this.friction = 0.8;
  25. }
  26. if(this.whichdude == 1)
  27. {
  28.    this.speed = 2.1;
  29.    this.maxjump = 12;
  30.    this.friction = 0.89;
  31. }
  32. if(this.whichdude == 2)
  33. {
  34.    this.speed = 2;
  35.    this.maxjump = 15;
  36.    this.friction = 0.75;
  37. }
  38. this.bubeffect = function(who)
  39. {
  40.    this.bubs.bubeffect._x = who._x;
  41.    this.bubs.bubeffect._y = who._y;
  42. };
  43. this.physics = function(who)
  44. {
  45.    if(who.dead != true && this.won != true)
  46.    {
  47.       if(this.wart.guts.hitarea.hitTest(who) && who.blinking != true && who.inv != true)
  48.       {
  49.          this.hp -= 1;
  50.          who.Xvel *= -1.5;
  51.          who.Yvel = -10;
  52.          who.blink = true;
  53.          who.inv = true;
  54.       }
  55.       if(this.bg._y < -650)
  56.       {
  57.          this.life.gotoAndStop("empty");
  58.          who.dead = true;
  59.       }
  60.       if(who.hitTest(this.bg2.as) && this.bg2.as._visible != false)
  61.       {
  62.          this.bg2.as._visible = false;
  63.          this.bubs.attachMovie("bomtoons_bubeffect","bubeffect",555);
  64.          f = this.bubs.attachMovie("as","as",430);
  65.          f._x = who._x - this.bubs._x - 50;
  66.          f._y = who._y - this.bubs._y;
  67.          f.id = 999;
  68.          f.onEnterFrame = function()
  69.          {
  70.             this._parent._parent.veggie(this);
  71.             this._parent._parent.bubeffect(this);
  72.          };
  73.       }
  74.       if(who.blink == true && who.beenshrunk != true)
  75.       {
  76.          who.blinkcount += 1;
  77.          if(who.blinkcount < 5)
  78.          {
  79.             who._yscale -= (who._yscale - 50) / 3;
  80.             who.shrinking = true;
  81.             this.bg._y += 1;
  82.             if(this.yorby != true)
  83.             {
  84.                this.shrink.start();
  85.                this.yorby = true;
  86.             }
  87.          }
  88.          else
  89.          {
  90.             who.blink = false;
  91.             who.blinkcount = 0;
  92.             who.shrinking = false;
  93.             who.beenshrunk = true;
  94.             who.inv = true;
  95.             who.invcount = 0;
  96.             this.yorby = false;
  97.          }
  98.       }
  99.       if(who.inv == true)
  100.       {
  101.          who.invcount += 1;
  102.          if(who._alpha < 100)
  103.          {
  104.             who._alpha = 100;
  105.          }
  106.          else
  107.          {
  108.             who._alpha = 0;
  109.          }
  110.          if(who.invcount > 90)
  111.          {
  112.             who.inv = false;
  113.             who._alpha = 100;
  114.          }
  115.       }
  116.       if(this.hp == 1)
  117.       {
  118.          this.life.gotoAndStop("half");
  119.          if(who.shrinking == false)
  120.          {
  121.             if(who.beensmall != true)
  122.             {
  123.                who.attachMovie("bomtoons_dudesmall" + this.whichdude,"guts",0);
  124.                who.beensmall = true;
  125.                if(who._xscale > 0)
  126.                {
  127.                   who._xscale = 100;
  128.                }
  129.                else
  130.                {
  131.                   who._xscale = -100;
  132.                }
  133.                who._yscale = 100;
  134.             }
  135.          }
  136.       }
  137.       if(this.hp == 0)
  138.       {
  139.          this.life.gotoAndStop("empty");
  140.          who.dead = true;
  141.       }
  142.       this.bg._y -= who.Yvel;
  143.       this.bg._x -= who.Xvel;
  144.       who.Xvel *= this.friction;
  145.       who.nexty = who._y + who.Yvel * 1.8;
  146.       who.midy = who._y - who._height / 2;
  147.       who.topy = who._y - who._height + 15;
  148.       who.edgex = who._x + who._width / 2 * (who._xscale / 100) + who.Xvel;
  149.       if(this.bg.hitTest(who._x,who.nexty,true))
  150.       {
  151.          if(who.Yvel > 0)
  152.          {
  153.             who.Yvel -= who.Yvel;
  154.          }
  155.          if(who.jumping == true && !Key.isDown(38))
  156.          {
  157.             who.jumping = false;
  158.             who.superjump = false;
  159.             who.floatcount = 0;
  160.             who.floatpressed = false;
  161.          }
  162.       }
  163.       else if(this.whichdude != 2)
  164.       {
  165.          if(who.Yvel < 10)
  166.          {
  167.             who.Yvel += this.grav / 2;
  168.          }
  169.       }
  170.       else
  171.       {
  172.          if(who.jumping == true)
  173.          {
  174.             if(Key.isDown(38) && who.Yvel > -1 && who.floatcount < 50)
  175.             {
  176.                who.floatpressed = true;
  177.                who.Yvel = 0;
  178.                who.floating = true;
  179.                if(who.holding != true)
  180.                {
  181.                   who.guts.gotoAndStop("jump");
  182.                }
  183.                else
  184.                {
  185.                   who.guts.gotoAndStop("jumphold");
  186.                }
  187.                who.floatcount += 1;
  188.             }
  189.             if(!Key.isDown(38) || who.floatcount >= 50)
  190.             {
  191.                who.floating = false;
  192.                if(who.floatpressed == true)
  193.                {
  194.                   who.floatcount = 50;
  195.                }
  196.             }
  197.          }
  198.          if(who.Yvel < 10 && who.floating != true)
  199.          {
  200.             who.Yvel += this.grav / 2;
  201.          }
  202.       }
  203.       if(this.bg.hitTest(who.edgex,who.topy,true) || this.bg.hitTest(who.edgex,who.nexty,true) and who.jumping == true)
  204.       {
  205.          var _loc4_ = Math.abs(who.Xvel);
  206.          if(_loc4_ > 3.5)
  207.          {
  208.             who.Xvel *= -0.8;
  209.             this.bg._x -= who.Xvel;
  210.          }
  211.          else if(who.superjump != true)
  212.          {
  213.             who.Xvel = 0;
  214.             if(Key.isDown(37) || Key.isDown(39))
  215.             {
  216.                if(who._xscale > 0)
  217.                {
  218.                   who.pushingright = true;
  219.                }
  220.                else
  221.                {
  222.                   who.pushingleft = true;
  223.                }
  224.             }
  225.             else
  226.             {
  227.                who.pushingleft = false;
  228.                who.pushingright = false;
  229.             }
  230.          }
  231.       }
  232.       else
  233.       {
  234.          who.pushingleft = false;
  235.          who.pushingright = false;
  236.       }
  237.       if(this.bg.hitTest(who._x,who.topy,true))
  238.       {
  239.          who.Yvel = Math.abs(who.Yvel) + 4;
  240.          who.pushingleft = false;
  241.          who.pushingright = false;
  242.       }
  243.       this.bg2._x = this.bg._x;
  244.       this.bg2._y = this.bg._y;
  245.       this.wart._x = this.bg._x;
  246.       this.wart._y = this.bg._y;
  247.       this.bubs._x = this.bg._x;
  248.       this.bubs._y = this.bg._y;
  249.       if(who.jumping == true)
  250.       {
  251.          if(who.Yvel < 0)
  252.          {
  253.             if(who.holding != true)
  254.             {
  255.                who.guts.gotoAndStop("jump");
  256.             }
  257.             else
  258.             {
  259.                who.guts.gotoAndStop("jumphold");
  260.             }
  261.          }
  262.          else if(who.floating != true)
  263.          {
  264.             if(who.holding != true)
  265.             {
  266.                who.guts.gotoAndStop("run");
  267.             }
  268.             else
  269.             {
  270.                who.guts.gotoAndStop("runhold");
  271.             }
  272.          }
  273.       }
  274.    }
  275.    if(who.dead == true)
  276.    {
  277.       if(this.killplayed != true)
  278.       {
  279.          stopAllSounds();
  280.          this.lose.start();
  281.          g = this.attachMovie("theend" + this.whichdude,"theend",879);
  282.          g._x = who._x;
  283.          g._y = who._y;
  284.          g.Yvel = -25;
  285.          this.nosound = true;
  286.          g.onEnterFrame = function()
  287.          {
  288.             this._y += this.Yvel;
  289.             this.Yvel += 1.5;
  290.             if(this._y > 450)
  291.             {
  292.                trace("gameover");
  293.                _root.lose();
  294.                delete this.onEnterFrame;
  295.                this.unloadMovie();
  296.                this.removeMovieClip();
  297.             }
  298.          };
  299.          this.killplayed = true;
  300.       }
  301.       delete who.onEnterFrame;
  302.       who.unloadMovie();
  303.       who.removeMovieClip();
  304.    }
  305. };
  306. this.veggie = function(who)
  307. {
  308.    if(who._y > Stage.height - this.bg._y && this.dude.jumping != true)
  309.    {
  310.       if(who.thrown == true)
  311.       {
  312.          this.vegarray = new Array();
  313.       }
  314.       if(who.id == 999)
  315.       {
  316.          this.bg2.as._visible = true;
  317.          this.bubs.bubeffect.unloadMovie();
  318.          this.bubs.bubeffect.removeMovieClip();
  319.       }
  320.       who.removeMovieClip();
  321.    }
  322.    if(this.dude.hitTest(who._x + this.bg._x,who._y + this.bg._y,true) && this.dude.holding != true && who.thrown != true)
  323.    {
  324.       who.grabbed = true;
  325.       this.dude.holding = true;
  326.       this.dude.storedheight = this.dude._height;
  327.    }
  328.    else if(who.grabbed != true)
  329.    {
  330.       who._x += who.Xvel;
  331.       who._y += who.Yvel;
  332.       who.Xvel *= 0.93;
  333.       who.Yvel += 0.7;
  334.    }
  335.    if(who.grabbed == true)
  336.    {
  337.       if(this.dude.ducking == true)
  338.       {
  339.          who._y = this.dude._y - this.bg._y - 50;
  340.          who._x = this.dude._x - this.bg._x + this.dude.Xvel;
  341.       }
  342.       else
  343.       {
  344.          who._x = this.dude._x - this.bg._x + this.dude.Xvel;
  345.          who._y = this.dude._y - this.dude._height + 20 - this.bg._y;
  346.          who._xscale = this.dude._xscale;
  347.          if(this.dude.charged == true)
  348.          {
  349.             who._y = this.dude._y - this.dude.storedheight + 20 - this.bg._y + this.dude.Yvel;
  350.          }
  351.       }
  352.       if(Key.isDown(32))
  353.       {
  354.          this.thro.start();
  355.          this.vegarray.push("veg" + who.id);
  356.          who.Xvel = this.dude.Xvel * 2;
  357.          if(who.Xvel < 10 && who._xscale > 0)
  358.          {
  359.             who.Xvel = 10;
  360.          }
  361.          if(who.Xvel > -10 && who._xscale < 0)
  362.          {
  363.             who.Xvel = -10;
  364.          }
  365.          who._x += who.Xvel;
  366.          who.Yvel = (Math.abs(this.dude.Xvel) + 2) * -0.5;
  367.          this.dude.holding = false;
  368.          who.thrown = true;
  369.          who.grabbed = false;
  370.       }
  371.       if(this.dude.dead == true)
  372.       {
  373.          who.Yvel = this.grav;
  374.          this.dude.holding = false;
  375.          who.thrown = true;
  376.          who.grabbed = false;
  377.       }
  378.    }
  379. };
  380. this.ai = function(who)
  381. {
  382.    if(who._x < 1750 and who.goback != true && who.shooting != true)
  383.    {
  384.       who._x += 2;
  385.       if(who._x >= 1750)
  386.       {
  387.          who.goback = true;
  388.       }
  389.    }
  390.    if(who.goback == true && who.shooting != true)
  391.    {
  392.       if(who._x > 1600)
  393.       {
  394.          who._x -= 2;
  395.          if(who._x <= 1600)
  396.          {
  397.             who.goback = false;
  398.          }
  399.       }
  400.    }
  401.    if(who.shooting == true)
  402.    {
  403.       if(this.bubcount == 1)
  404.       {
  405.          var _loc3_ = random(6);
  406.          var _loc4_ = "bomtoons_veg" + _loc3_;
  407.          v = this.bubs.attachMovie(_loc4_,"veg" + _loc3_,this.vegcount);
  408.          v._x = 1260;
  409.          v._y = 350;
  410.          v.onEnterFrame = function()
  411.          {
  412.             this._parent._parent.veggie(this);
  413.          };
  414.          v.Xvel = -10;
  415.          v.Yvel = -5;
  416.          v.id = _loc3_;
  417.          this.allarray[v.id] = "veg" + v.id;
  418.          this.vegcount += 1;
  419.       }
  420.       if(this.bubcount < 12)
  421.       {
  422.          this.bubcount += 1;
  423.       }
  424.       else
  425.       {
  426.          this.opencount += 1;
  427.          if(this.opencount > 25 && who.playhit != true)
  428.          {
  429.             who.shooting = false;
  430.             this.bubcount = 0;
  431.             this.opencount = 0;
  432.             who.playhit = false;
  433.             who.gotoAndStop("walk");
  434.          }
  435.       }
  436.       if(this.bubcount < 12 && this.bubcount > 6)
  437.       {
  438.          who.gotoAndStop("shoot");
  439.          b = this.bubs.attachMovie("bombub","bub" + this.bubcount,this.bubcount);
  440.          b._x = who._parent._x + who._x - 35 - this.bg2._x;
  441.          b._y = who._parent._y + who._y - 115 - this.bg2._y;
  442.          b.Xvel = 120 / this.bubcount * -1 - random(this.bubcount * 2.5);
  443.          b.Yvel = -15 - random(3);
  444.       }
  445.    }
  446. };
  447. this.shootbubbles = function(who)
  448. {
  449.    if(who.shooting != true)
  450.    {
  451.       who.shooting = true;
  452.    }
  453. };
  454. setInterval(this.shootbubbles,7000,this.wart.guts);
  455. this.onEnterFrame = function()
  456. {
  457.    if(this.won != true && !this.dude.dead && !this.nosound)
  458.    {
  459.       if(tim0 > 0)
  460.       {
  461.          tim0 -= 1;
  462.       }
  463.       this.physics(this.dude);
  464.       this.ai(this.wart.guts);
  465.       if(Key.isDown(39) && !Key.isDown(40) && this.dude.pushingright != true)
  466.       {
  467.          if(!this.bg.hitTest(this.dude.edgex,this.dude.topy,true))
  468.          {
  469.             this.dude.Xvel += this.speed;
  470.          }
  471.          this.dude._xscale = 100;
  472.          this.dude.charged = false;
  473.          if(this.dude.jumping != true && this.dude.Yvel <= 0)
  474.          {
  475.             if(this.dude.holding != true)
  476.             {
  477.                this.dude.guts.gotoAndStop("run");
  478.             }
  479.             else
  480.             {
  481.                this.dude.guts.gotoAndStop("runhold");
  482.             }
  483.          }
  484.          if(this.dude.Xvel < 0)
  485.          {
  486.             if(this.dude.holding != true)
  487.             {
  488.                this.dude.guts.gotoAndStop("slide");
  489.             }
  490.             else
  491.             {
  492.                this.dude.guts.gotoAndStop("holdslide");
  493.             }
  494.          }
  495.          this.dude.pushingleft = false;
  496.       }
  497.       if(Key.isDown(37) && !Key.isDown(40) && this.dude.pushingleft != true)
  498.       {
  499.          if(!this.bg.hitTest(this.dude.edgex,this.dude.topy,true))
  500.          {
  501.             this.dude.Xvel -= this.speed;
  502.          }
  503.          this.dude._xscale = -100;
  504.          this.dude.charged = false;
  505.          if(this.dude.jumping != true && this.dude.Yvel <= 0)
  506.          {
  507.             if(this.dude.holding != true)
  508.             {
  509.                this.dude.guts.gotoAndStop("run");
  510.             }
  511.             else
  512.             {
  513.                this.dude.guts.gotoAndStop("runhold");
  514.             }
  515.          }
  516.          if(this.dude.Xvel > 0)
  517.          {
  518.             if(this.dude.holding != true)
  519.             {
  520.                this.dude.guts.gotoAndStop("slide");
  521.             }
  522.             else
  523.             {
  524.                this.dude.guts.gotoAndStop("holdslide");
  525.             }
  526.          }
  527.          this.dude.pushingright = false;
  528.       }
  529.       if(Key.isDown(38) && this.dude.jumping != true)
  530.       {
  531.          this.jump.start();
  532.          if(this.dude.charged != true)
  533.          {
  534.             this.dude.Yvel -= this.maxjump + Math.abs(this.dude.Xvel) / 5;
  535.          }
  536.          else
  537.          {
  538.             if(this.whichdude == 0 || this.whichdude == 2)
  539.             {
  540.                this.dude.Yvel -= (this.maxjump + Math.abs(this.dude.Xvel) / 5) * 1.8;
  541.             }
  542.             if(this.whichdude == 1)
  543.             {
  544.                this.dude.Yvel -= (this.maxjump + Math.abs(this.dude.Xvel) / 5) * 2.1;
  545.             }
  546.             this.dude.superjump = true;
  547.             this.dude.charged = false;
  548.          }
  549.          this.dude.jumping = true;
  550.       }
  551.       if(Key.isDown(40) && this.dude.jumping != true)
  552.       {
  553.          if(this.dude.charged != true)
  554.          {
  555.             this.dude.guts.gotoAndStop("duck");
  556.          }
  557.          else
  558.          {
  559.             this.dude.guts.gotoAndStop("duckcharge");
  560.          }
  561.          this.dude.ducking = true;
  562.          this.dude.chargecount += 1;
  563.          if(this.dude.chargecount > 25)
  564.          {
  565.             this.dude.charged = true;
  566.             this.dude.pushingright = false;
  567.             this.dude.pushingleft = false;
  568.          }
  569.       }
  570.       else
  571.       {
  572.          this.dude.chargecount = 0;
  573.          this.dude.ducking = false;
  574.       }
  575.       if(!Key.isDown(37) && !Key.isDown(39) && this.dude.jumping != true && !Key.isDown(40))
  576.       {
  577.          if(this.dude.holding != true)
  578.          {
  579.             if(this.dude.charged != true)
  580.             {
  581.                this.dude.guts.gotoAndStop("rest");
  582.             }
  583.             else
  584.             {
  585.                this.dude.guts.gotoAndStop("restcharge");
  586.             }
  587.          }
  588.          else if(this.dude.charged != true)
  589.          {
  590.             this.dude.guts.gotoAndStop("resthold");
  591.          }
  592.          else
  593.          {
  594.             this.dude.guts.gotoAndStop("restholdcharge");
  595.          }
  596.          this.dude.pushingright = false;
  597.          this.dude.pushingleft = false;
  598.          this.dude.ducking = false;
  599.       }
  600.       if(!Key.isDown(40) and this.dude.charged != true)
  601.       {
  602.          this.dude.chargecount = 0;
  603.          this.dude.ducking = false;
  604.       }
  605.    }
  606.    else
  607.    {
  608.       this.dude.guts.gotoAndStop("rest");
  609.       this.bubs.bubeffect.unloadMovie();
  610.    }
  611.    this.wartlife.gotoAndStop("l" + this.hitcount);
  612. };
  613.