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

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