home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Esportes / CrossingCup.swf / scripts / __Packages / CKicker.as < prev    next >
Encoding:
Text File  |  2007-12-11  |  13.3 KB  |  531 lines

  1. class CKicker
  2. {
  3.    var mball;
  4.    var mybg;
  5.    var mcParent;
  6.    var AutoKick;
  7.    var mcKicker;
  8.    var bx;
  9.    var by;
  10.    var bz;
  11.    var mark;
  12.    var bTrans;
  13.    var todo;
  14.    var AutoRun;
  15.    var xrunto;
  16.    var zrunto;
  17.    var angley;
  18.    var anglex;
  19.    var power;
  20.    var def_bx = 39;
  21.    var def_by = 0;
  22.    var def_bz = 1;
  23.    var tbmc = 1;
  24.    var zInner = 0.4;
  25.    var zOuter = 1.1;
  26.    var xInner = 1;
  27.    var xOuter = 2;
  28.    var KS_IDLE = 1;
  29.    var KS_RUNRIGHT = 2;
  30.    var KS_RUNLEFT = 3;
  31.    var KS_RUNUP = 4;
  32.    var KS_RUNDOWN = 5;
  33.    var KS_HEADING = 6;
  34.    var KS_VOLLEY = 7;
  35.    var KS_DIVE = 8;
  36.    var KS_BACKFLIP = 9;
  37.    var KS_CHESTVOLLEY = 10;
  38.    var kickerstate = 0;
  39.    var AI_KICKERSHOOTLR = 0;
  40.    function CKicker(bg, _mcParent, _mball)
  41.    {
  42.       this.mball = _mball;
  43.       this.mybg = bg;
  44.       this.mcParent = _mcParent;
  45.       this.createMarker();
  46.       this.tbmc = 0.3;
  47.       this.AutoKick = false;
  48.       EventCenter.access().addEventListener("kickerevent",this);
  49.    }
  50.    function createAnim()
  51.    {
  52.       this.mcKicker = this.mcParent.attachMovie("kicker","kicker",this.mcParent.getNextHighestDepth());
  53.       this.mcKicker._x = 260;
  54.       this.mcKicker._y = 387;
  55.       this.mcKicker._visible = false;
  56.    }
  57.    function createMarker()
  58.    {
  59.       this.bx = this.def_bx;
  60.       this.by = this.def_by;
  61.       this.bz = this.def_bz;
  62.       this.mark = new sandy.core.Sprite2D(0.09);
  63.       this.mcKicker = this.mcParent.attachMovie("kicker","kicker",this.mcParent.getNextHighestDepth());
  64.       this.mcKicker.gotoAndStop(1);
  65.       this.mcKicker._visible = false;
  66.       var _loc3_ = new sandy.skin.MovieSkin(this.mcKicker);
  67.       this.mark.setSkin(_loc3_);
  68.       var _loc2_ = new sandy.core.group.TransformGroup();
  69.       this.bTrans = new sandy.core.transform.Transform3D();
  70.       this.bTrans.translate(this.def_bx,0,this.def_bz);
  71.       _loc2_.setTransform(this.bTrans);
  72.       _loc2_.addChild(this.mark);
  73.       this.mybg.addChild(_loc2_);
  74.    }
  75.    function restart()
  76.    {
  77.       this.mcKicker.gotoAndStop(1);
  78.    }
  79.    function hide()
  80.    {
  81.       this.bTrans.translate(this.def_bx,this.def_by,this.def_bz);
  82.       this.AutoKick = false;
  83.       this.mcKicker.gotoAndStop(1);
  84.       this.mcKicker._visible = false;
  85.    }
  86.    function show()
  87.    {
  88.       this.bx = this.def_bx;
  89.       this.by = this.def_by;
  90.       this.bz = this.def_bz;
  91.       this.bTrans.translate(this.bx,this.by,this.bz);
  92.       this.mcKicker.gotoAndPlay(2);
  93.       this.kickerstate = this.KS_IDLE;
  94.    }
  95.    function getPosition()
  96.    {
  97.       var _loc2_ = this.mark.getPosition();
  98.       return _loc2_;
  99.    }
  100.    function win()
  101.    {
  102.       switch(this.randRange(1,6))
  103.       {
  104.          case 1:
  105.             this.mcKicker.gotoAndPlay("win");
  106.             break;
  107.          case 2:
  108.          case 3:
  109.             this.mcKicker.gotoAndPlay("win2");
  110.             break;
  111.          case 4:
  112.          case 5:
  113.          case 6:
  114.             this.mcKicker.gotoAndPlay("win3");
  115.       }
  116.    }
  117.    function loose()
  118.    {
  119.       switch(this.randRange(1,4))
  120.       {
  121.          case 1:
  122.             this.mcKicker.gotoAndPlay("loose");
  123.             break;
  124.          case 2:
  125.          case 3:
  126.          case 4:
  127.             this.mcKicker.gotoAndPlay("loose2");
  128.       }
  129.    }
  130.    function toidle()
  131.    {
  132.       this.kickerstate = this.KS_IDLE;
  133.       this.mcKicker.gotoAndStop("idle");
  134.    }
  135.    function doaction()
  136.    {
  137.       switch(this.todo)
  138.       {
  139.          case "backflip":
  140.             _global.__DISPATCH({type:"gameevent",param:"shooting"});
  141.             this.kickerstate = this.KS_BACKFLIP;
  142.             this.mcKicker.gotoAndPlay("backflip");
  143.             break;
  144.          case "heading":
  145.             _global.__DISPATCH({type:"gameevent",param:"shooting"});
  146.             this.kickerstate = this.KS_HEADING;
  147.             this.mcKicker.gotoAndPlay("heading");
  148.             break;
  149.          case "chestvolley":
  150.             _global.__DISPATCH({type:"gameevent",param:"shooting"});
  151.             this.kickerstate = this.KS_CHESTVOLLEY;
  152.             this.mcKicker.gotoAndPlay("chestvolley");
  153.             break;
  154.          case "dive":
  155.             _global.__DISPATCH({type:"gameevent",param:"shooting"});
  156.             this.kickerstate = this.KS_DIVE;
  157.             this.mcKicker.gotoAndPlay("dive");
  158.             break;
  159.          case "volley":
  160.             _global.__DISPATCH({type:"gameevent",param:"shooting"});
  161.             this.kickerstate = this.KS_VOLLEY;
  162.             this.mcKicker.gotoAndPlay("volley");
  163.       }
  164.    }
  165.    function action()
  166.    {
  167.       var _loc7_ = this.mball.getPosition();
  168.       var _loc8_ = this.mball.markball.getPosition();
  169.       var _loc3_ = this.mark.getPosition();
  170.       var _loc0_ = null;
  171.       var _loc5_ = near = this.mball.getNearestBallTrajectories(_loc3_);
  172.       var _loc2_ = _loc5_.x - _loc3_.x;
  173.       var _loc4_ = _loc5_.y - _loc3_.y;
  174.       var _loc6_ = _loc5_.z - _loc3_.z;
  175.       this.todo = "nothing";
  176.       if(_loc6_ > -0.5 && _loc4_ < 3.3 && _loc2_ > -1 && _loc2_ < 6)
  177.       {
  178.          if(_loc4_ >= 2)
  179.          {
  180.             if(_loc2_ < 0)
  181.             {
  182.                this.todo = "backflip";
  183.             }
  184.             else
  185.             {
  186.                this.todo = "heading";
  187.             }
  188.          }
  189.          else if(_loc2_ > 3)
  190.          {
  191.             this.todo = "dive";
  192.          }
  193.          else if(_loc2_ < 0)
  194.          {
  195.             this.todo = "backflip";
  196.          }
  197.          else if(_loc4_ > 1)
  198.          {
  199.             this.todo = "chestvolley";
  200.          }
  201.          else if(_loc4_ < 1)
  202.          {
  203.             this.todo = "volley";
  204.          }
  205.          else
  206.          {
  207.             this.todo = "chestvolley";
  208.          }
  209.       }
  210.       if(!this.AutoKick)
  211.       {
  212.          this.doaction();
  213.       }
  214.    }
  215.    function startrun()
  216.    {
  217.       this.AutoRun = true;
  218.       this.AutoKick = true;
  219.       var _loc2_ = this.mball.getRandomPos();
  220.       this.xrunto = _loc2_.x;
  221.       this.zrunto = _loc2_.z;
  222.    }
  223.    function autoRunAction()
  224.    {
  225.       if(this.bx > this.xrunto)
  226.       {
  227.          this.bx -= this.tbmc;
  228.       }
  229.       if(this.bx < this.xrunto)
  230.       {
  231.          this.bx += this.tbmc;
  232.       }
  233.       if(this.bz > this.zrunto)
  234.       {
  235.          this.bz -= this.tbmc;
  236.       }
  237.       if(this.bz < this.zrunto)
  238.       {
  239.          this.bz += this.tbmc;
  240.       }
  241.       if(this.kickerstate == this.KS_IDLE)
  242.       {
  243.          this.kickerstate = this.KS_RUNUP;
  244.          this.mcKicker.gotoAndPlay("runuploop");
  245.       }
  246.       this.bTrans.translate(this.bx,this.by,this.bz);
  247.       if(Math.abs(this.bx - this.xrunto) < 0.5 && Math.abs(this.bz - this.zrunto) < 0.5)
  248.       {
  249.          this.action();
  250.          this.kickerstate = this.KS_IDLE;
  251.          this.mcKicker.gotoAndStop("idle");
  252.          this.AutoRun = false;
  253.       }
  254.    }
  255.    function randRange(min, max)
  256.    {
  257.       var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
  258.       return _loc1_;
  259.    }
  260.    function autokicklevel1()
  261.    {
  262.       if(this.bz > 1)
  263.       {
  264.          this.angley = -90 - this.randRange(0,45);
  265.       }
  266.       else
  267.       {
  268.          this.angley = -90 + this.randRange(0,45);
  269.       }
  270.       Math.random() >= 0.5 ? (this.anglex -= 10) : (this.anglex += 10);
  271.    }
  272.    function autokicklevel2()
  273.    {
  274.       if(this.bz > 1)
  275.       {
  276.          if(this.bz > 5)
  277.          {
  278.             this.angley = -110 - this.randRange(0,30);
  279.          }
  280.          else
  281.          {
  282.             this.angley = -90 - this.randRange(0,30);
  283.          }
  284.       }
  285.       else if(this.bz > -1)
  286.       {
  287.          this.angley = -90 + this.randRange(0,30);
  288.       }
  289.       else
  290.       {
  291.          this.angley = -70 + this.randRange(0,30);
  292.       }
  293.       Math.random() >= 0.5 ? (this.anglex -= 5) : (this.anglex += 5);
  294.    }
  295.    function setLevel(level)
  296.    {
  297.       this.AI_KICKERSHOOTLR = level;
  298.    }
  299.    function makeshoot()
  300.    {
  301.       this.power = 80;
  302.       this.anglex = 0;
  303.       this.angley = -90;
  304.       if(this.AutoKick)
  305.       {
  306.          if(this.AI_KICKERSHOOTLR == 0)
  307.          {
  308.             this.autokicklevel1();
  309.          }
  310.          else
  311.          {
  312.             this.autokicklevel2();
  313.          }
  314.       }
  315.       else
  316.       {
  317.          if(Key.isDown(37))
  318.          {
  319.             this.angley += 15;
  320.          }
  321.          if(Key.isDown(39))
  322.          {
  323.             this.angley -= 16;
  324.          }
  325.          if(Key.isDown(38))
  326.          {
  327.             this.anglex -= 15;
  328.          }
  329.          if(Key.isDown(40))
  330.          {
  331.             this.anglex += 10;
  332.          }
  333.       }
  334.       this.mball.makeshoot(this.power,this.anglex,this.angley);
  335.    }
  336.    function cekrun()
  337.    {
  338.       if(this.AutoRun)
  339.       {
  340.          this.autoRunAction();
  341.          return undefined;
  342.       }
  343.    }
  344.    function cekinput(canspace)
  345.    {
  346.       if(canspace == undefined)
  347.       {
  348.          canspace = true;
  349.       }
  350.       if(this.kickerstate == this.KS_IDLE)
  351.       {
  352.          if(Key.isDown(38))
  353.          {
  354.             this.kickerstate = this.KS_RUNUP;
  355.             this.mcKicker.gotoAndPlay("runuploop");
  356.          }
  357.          if(Key.isDown(40))
  358.          {
  359.             this.kickerstate = this.KS_RUNDOWN;
  360.             this.mcKicker.gotoAndPlay("rundownloop");
  361.          }
  362.          if(Key.isDown(37))
  363.          {
  364.             this.kickerstate = this.KS_RUNLEFT;
  365.             this.mcKicker.gotoAndPlay("runleftloop");
  366.          }
  367.          if(Key.isDown(39))
  368.          {
  369.             this.kickerstate = this.KS_RUNRIGHT;
  370.             this.mcKicker.gotoAndPlay("runrightloop");
  371.          }
  372.          if(Key.isDown(32) && canspace)
  373.          {
  374.             this.action();
  375.          }
  376.          return undefined;
  377.       }
  378.       if(this.kickerstate == this.KS_RUNRIGHT)
  379.       {
  380.          if(Key.isDown(38))
  381.          {
  382.             this.bx += this.tbmc;
  383.          }
  384.          if(Key.isDown(40))
  385.          {
  386.             this.bx -= this.tbmc;
  387.          }
  388.          if(Key.isDown(32))
  389.          {
  390.             this.action();
  391.          }
  392.          if(Key.isDown(39))
  393.          {
  394.             this.bz -= this.tbmc;
  395.             this.bTrans.translate(this.bx,this.by,this.bz);
  396.          }
  397.          else
  398.          {
  399.             this.kickerstate = this.KS_IDLE;
  400.             this.mcKicker.gotoAndStop("idle");
  401.          }
  402.          return undefined;
  403.       }
  404.       if(this.kickerstate == this.KS_RUNLEFT)
  405.       {
  406.          if(Key.isDown(38))
  407.          {
  408.             this.bx += this.tbmc;
  409.          }
  410.          if(Key.isDown(40))
  411.          {
  412.             this.bx -= this.tbmc;
  413.          }
  414.          if(Key.isDown(32))
  415.          {
  416.             this.action();
  417.          }
  418.          if(Key.isDown(37))
  419.          {
  420.             this.bz += this.tbmc;
  421.             this.bTrans.translate(this.bx,this.by,this.bz);
  422.          }
  423.          else
  424.          {
  425.             this.kickerstate = this.KS_IDLE;
  426.             this.mcKicker.gotoAndStop("idle");
  427.          }
  428.          return undefined;
  429.       }
  430.       if(this.kickerstate == this.KS_RUNUP)
  431.       {
  432.          if(Key.isDown(37))
  433.          {
  434.             this.bz += this.tbmc;
  435.          }
  436.          if(Key.isDown(39))
  437.          {
  438.             this.bz -= this.tbmc;
  439.          }
  440.          if(Key.isDown(32))
  441.          {
  442.             this.action();
  443.          }
  444.          if(Key.isDown(38))
  445.          {
  446.             this.bx += this.tbmc;
  447.             this.bTrans.translate(this.bx,this.by,this.bz);
  448.          }
  449.          else
  450.          {
  451.             this.kickerstate = this.KS_IDLE;
  452.             this.mcKicker.gotoAndStop("idle");
  453.          }
  454.          return undefined;
  455.       }
  456.       if(this.kickerstate == this.KS_RUNDOWN)
  457.       {
  458.          if(Key.isDown(37))
  459.          {
  460.             this.bz += this.tbmc;
  461.          }
  462.          if(Key.isDown(39))
  463.          {
  464.             this.bz -= this.tbmc;
  465.          }
  466.          if(Key.isDown(32))
  467.          {
  468.             this.action();
  469.          }
  470.          if(Key.isDown(40))
  471.          {
  472.             this.bx -= this.tbmc;
  473.             this.bTrans.translate(this.bx,this.by,this.bz);
  474.          }
  475.          else
  476.          {
  477.             this.kickerstate = this.KS_IDLE;
  478.             this.mcKicker.gotoAndStop("idle");
  479.          }
  480.          return undefined;
  481.       }
  482.    }
  483.    function kickerevent(ob)
  484.    {
  485.       switch(ob.param)
  486.       {
  487.          case "shoot":
  488.             this.doaction(this.todo);
  489.             break;
  490.          case "runright":
  491.             this.mcKicker.gotoAndPlay("runrightloop");
  492.             break;
  493.          case "runleft":
  494.             this.mcKicker.gotoAndPlay("runleftloop");
  495.             break;
  496.          case "rundown":
  497.             this.mcKicker.gotoAndPlay("rundownloop");
  498.             break;
  499.          case "runup":
  500.             this.mcKicker.gotoAndPlay("runuploop");
  501.             break;
  502.          case "addup":
  503.             this.bx += ob.tbmc;
  504.             this.bTrans.translate(this.bx,this.by,this.bz);
  505.             break;
  506.          case "adddown":
  507.             this.bx -= ob.tbmc;
  508.             this.bTrans.translate(this.bx,this.by,this.bz);
  509.             break;
  510.          case "addleft":
  511.             this.bz += ob.tbmc;
  512.             this.bTrans.translate(this.bx,this.by,this.bz);
  513.             break;
  514.          case "addright":
  515.             this.bz -= ob.tbmc;
  516.             this.bTrans.translate(this.bx,this.by,this.bz);
  517.       }
  518.    }
  519.    function setHuman(human)
  520.    {
  521.       if(human)
  522.       {
  523.          this.mcKicker.indicator._visible = true;
  524.       }
  525.       else
  526.       {
  527.          this.mcKicker.indicator._visible = false;
  528.       }
  529.    }
  530. }
  531.