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

  1. class CKeeper
  2. {
  3.    var def_bx = 54.8;
  4.    var def_by = 0;
  5.    var def_bz = 0.1;
  6.    var afterAct = 0;
  7.    var AI_KEEPERJUMPRANDOM = 1;
  8.    function CKeeper(bg, _mcParent)
  9.    {
  10.       this.mybg = bg;
  11.       this.mcParent = _mcParent;
  12.       this.createMarker();
  13.       this.AutoCatch = false;
  14.       EventCenter.access().addEventListener("keeperevent",this);
  15.    }
  16.    function createMarker()
  17.    {
  18.       this.bx = this.def_bx;
  19.       this.by = this.def_by;
  20.       this.bz = this.def_bz;
  21.       var _loc3_ = new sandy.core.Sprite2D(0.26);
  22.       this.mcKeeper = this.mcParent.attachMovie("keeper","keeper",this.mcParent.getNextHighestDepth());
  23.       this.mcKeeper._visible = false;
  24.       this.mcKeeper.gotoAndStop(1);
  25.       var _loc4_ = new sandy.skin.MovieSkin(this.mcKeeper);
  26.       _loc3_.setSkin(_loc4_);
  27.       var _loc2_ = new sandy.core.group.TransformGroup();
  28.       this.bTrans = new sandy.core.transform.Transform3D();
  29.       this.bTrans.translate(this.def_bx,0,this.def_bz);
  30.       _loc2_.setTransform(this.bTrans);
  31.       _loc2_.addChild(_loc3_);
  32.       this.mybg.addChild(_loc2_);
  33.    }
  34.    function startcatch()
  35.    {
  36.       this.AutoCatch = true;
  37.    }
  38.    function cekinput(mball)
  39.    {
  40.       if(Key.isDown(38) && Key.isDown(37))
  41.       {
  42.          this.todo = "upleft";
  43.          return undefined;
  44.       }
  45.       if(Key.isDown(38) && Key.isDown(39))
  46.       {
  47.          this.todo = "upright";
  48.          return undefined;
  49.       }
  50.       if(Key.isDown(40) && Key.isDown(37))
  51.       {
  52.          this.todo = "downleft";
  53.          return undefined;
  54.       }
  55.       if(Key.isDown(40) && Key.isDown(39))
  56.       {
  57.          this.todo = "downright";
  58.          return undefined;
  59.       }
  60.       if(Key.isDown(37))
  61.       {
  62.          this.todo = "downleft";
  63.          return undefined;
  64.       }
  65.       if(Key.isDown(39))
  66.       {
  67.          this.todo = "downright";
  68.          return undefined;
  69.       }
  70.       if(Key.isDown(38))
  71.       {
  72.          this.todo = "jump";
  73.          return undefined;
  74.       }
  75.       if(Key.isDown(40))
  76.       {
  77.          this.todo = "block";
  78.          return undefined;
  79.       }
  80.    }
  81.    function cekinputA(mball)
  82.    {
  83.       if(this.doing != "")
  84.       {
  85.          return undefined;
  86.       }
  87.       if(Key.isDown(37))
  88.       {
  89.          this.todo = "left";
  90.       }
  91.       if(Key.isDown(39))
  92.       {
  93.          this.todo = "right";
  94.       }
  95.       this.doAction();
  96.    }
  97.    function spacehit(mball)
  98.    {
  99.       this.cekinput(mball);
  100.       this.doAction();
  101.    }
  102.    function setLevel(level)
  103.    {
  104.       this.AI_KEEPERJUMPRANDOM = level;
  105.    }
  106.    function catchball(mball)
  107.    {
  108.       if(this.AI_KEEPERJUMPRANDOM == 0)
  109.       {
  110.          this.catchball1(mball);
  111.       }
  112.       else
  113.       {
  114.          this.catchball2(mball);
  115.       }
  116.    }
  117.    function catchball1(mball)
  118.    {
  119.       var _loc3_ = this.randRange(1,6);
  120.       var _loc2_ = this.bx - mball.bx;
  121.       if(_loc2_ > 9)
  122.       {
  123.          this.catchball2(mball);
  124.          return undefined;
  125.       }
  126.       switch(_loc3_)
  127.       {
  128.          case 1:
  129.             this.todo = "jump";
  130.             break;
  131.          case 2:
  132.             this.todo = "block";
  133.             break;
  134.          case 3:
  135.             this.todo = "downleft";
  136.             break;
  137.          case 4:
  138.             this.todo = "upleft";
  139.             break;
  140.          case 5:
  141.             this.todo = "downright";
  142.             break;
  143.          case 6:
  144.             this.todo = "upright";
  145.       }
  146.    }
  147.    function catchball2(mball)
  148.    {
  149.       var _loc4_ = Math.atan2(mball.xVel,mball.zVel);
  150.       var _loc6_ = this.bx - mball.bx;
  151.       var _loc5_ = _loc6_ / Math.tan(_loc4_);
  152.       var _loc2_ = mball.bz + _loc5_;
  153.       if(Math.abs(_loc2_ - this.bz) < 1)
  154.       {
  155.          if(Math.random() < 0.5)
  156.          {
  157.             this.todo = "jump";
  158.             return undefined;
  159.          }
  160.          this.todo = "block";
  161.          return undefined;
  162.       }
  163.       if(_loc2_ > this.bz)
  164.       {
  165.          if(Math.random() <= 0.5)
  166.          {
  167.             this.todo = "downleft";
  168.             return undefined;
  169.          }
  170.          this.todo = "upleft";
  171.          return undefined;
  172.       }
  173.       if(Math.random() <= 0.5)
  174.       {
  175.          this.todo = "downright";
  176.          return undefined;
  177.       }
  178.       this.todo = "upright";
  179.       return undefined;
  180.    }
  181.    function cekGoal(mball)
  182.    {
  183.       switch(this.doing)
  184.       {
  185.          case "":
  186.          case "left":
  187.          case "right":
  188.             if(mball.bz <= this.bz + 0.5 && mball.bz > this.bz - 0.5 && mball.by <= 2)
  189.             {
  190.                return false;
  191.             }
  192.             break;
  193.          case "jump":
  194.             if(mball.bz <= this.bz + 1 && mball.bz > this.bz - 1 && mball.by > 0.7 && mball.by < 3)
  195.             {
  196.                return false;
  197.             }
  198.             break;
  199.          case "block":
  200.             if(mball.bz <= this.bz + 1 && mball.bz > this.bz - 1 && mball.by <= 2)
  201.             {
  202.                return false;
  203.             }
  204.             break;
  205.          case "downleft":
  206.             if(mball.bz > this.bz && mball.bz < this.bz + 3 && mball.by <= 1.5)
  207.             {
  208.                return false;
  209.             }
  210.             break;
  211.          case "upleft":
  212.             if(mball.bz > this.bz && mball.bz < this.bz + 3 && mball.by > 1.5 && mball.by <= 3)
  213.             {
  214.                return false;
  215.             }
  216.             break;
  217.          case "upright":
  218.             if(mball.bz < this.bz && mball.bz > this.bz - 3 && mball.by > 1.5 && mball.by <= 3)
  219.             {
  220.                return false;
  221.             }
  222.             break;
  223.          case "downright":
  224.             if(mball.bz < this.bz && mball.bz > this.bz - 3 && mball.by <= 1.5)
  225.             {
  226.                return false;
  227.             }
  228.             break;
  229.       }
  230.       return true;
  231.    }
  232.    function doAction()
  233.    {
  234.       switch(this.todo)
  235.       {
  236.          case "downleft":
  237.             this.mcKeeper.gotoAndPlay("downleft");
  238.             this.doing = this.todo;
  239.             break;
  240.          case "downright":
  241.             this.mcKeeper.gotoAndPlay("downright");
  242.             this.doing = this.todo;
  243.             break;
  244.          case "upleft":
  245.             this.mcKeeper.gotoAndPlay("upleft");
  246.             this.doing = this.todo;
  247.             break;
  248.          case "upright":
  249.             this.mcKeeper.gotoAndPlay("upright");
  250.             this.doing = this.todo;
  251.             break;
  252.          case "win":
  253.             this.mcKeeper.gotoAndPlay("win");
  254.             this.doing = this.todo;
  255.             break;
  256.          case "win2":
  257.             this.mcKeeper.gotoAndPlay("win2");
  258.             this.doing = this.todo;
  259.             break;
  260.          case "loose":
  261.             this.mcKeeper.gotoAndPlay("loose");
  262.             this.doing = this.todo;
  263.             break;
  264.          case "loose2":
  265.             this.mcKeeper.gotoAndPlay("loose2");
  266.             this.doing = this.todo;
  267.             break;
  268.          case "jump":
  269.             this.mcKeeper.gotoAndPlay("jump");
  270.             this.doing = this.todo;
  271.             break;
  272.          case "block":
  273.             this.mcKeeper.gotoAndPlay("block");
  274.             this.doing = this.todo;
  275.             break;
  276.          case "left":
  277.             this.mcKeeper.gotoAndPlay("left");
  278.             this.doing = this.todo;
  279.             break;
  280.          case "right":
  281.             this.mcKeeper.gotoAndPlay("right");
  282.             this.doing = this.todo;
  283.       }
  284.       this.todo = "";
  285.    }
  286.    function win()
  287.    {
  288.       this.afterAct = 1;
  289.    }
  290.    function loose()
  291.    {
  292.       this.afterAct = -1;
  293.    }
  294.    function hide()
  295.    {
  296.       this.bTrans.translate(this.def_bx - 50,this.def_by,this.def_bz);
  297.    }
  298.    function show()
  299.    {
  300.       this.bx = this.def_bx;
  301.       this.by = this.def_by;
  302.       this.bz = this.def_bz;
  303.       this.bTrans.translate(this.bx,this.by,this.bz);
  304.       this.mcKeeper.gotoAndPlay("idle");
  305.       this.todo = "";
  306.       this.doing = "";
  307.    }
  308.    function restart()
  309.    {
  310.       this.mcKeeper.gotoAndStop(1);
  311.    }
  312.    function keeperevent(ob)
  313.    {
  314.       switch(ob.param)
  315.       {
  316.          case "idle":
  317.             this.mcKeeper.gotoAndPlay("idle");
  318.             this.doing = "";
  319.             break;
  320.          case "downleft":
  321.          case "downright":
  322.          case "upleft":
  323.          case "upright":
  324.          case "jump":
  325.          case "block":
  326.             if(this.afterAct != 0)
  327.             {
  328.                if(this.afterAct == -1)
  329.                {
  330.                   this.afterAct = 0;
  331.                   Math.random() >= 0.5 ? (this.todo = _loc0_ = "loose2", _loc0_) : (this.todo = _loc0_ = "loose", _loc0_);
  332.                   this.doAction();
  333.                }
  334.                else
  335.                {
  336.                   this.afterAct = 0;
  337.                   Math.random() >= 0.5 ? (this.todo = _loc0_ = "win2", _loc0_) : (this.todo = _loc0_ = "win", _loc0_);
  338.                   this.doAction();
  339.                }
  340.             }
  341.             else
  342.             {
  343.                this.mcKeeper.stop();
  344.             }
  345.             break;
  346.          case "addup":
  347.             this.bx += ob.tbmc;
  348.             this.bTrans.translate(this.bx,this.by,this.bz);
  349.             break;
  350.          case "adddown":
  351.             this.bx -= ob.tbmc;
  352.             this.bTrans.translate(this.bx,this.by,this.bz);
  353.             break;
  354.          case "addleft":
  355.             this.bz += ob.tbmc;
  356.             this.bTrans.translate(this.bx,this.by,this.bz);
  357.             break;
  358.          case "addright":
  359.             this.bz -= ob.tbmc;
  360.             this.bTrans.translate(this.bx,this.by,this.bz);
  361.             break;
  362.          case "ballclosing":
  363.             if(this.AutoCatch)
  364.             {
  365.                this.doAction();
  366.             }
  367.       }
  368.    }
  369.    function randRange(min, max)
  370.    {
  371.       var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
  372.       return _loc1_;
  373.    }
  374.    function setHuman(human)
  375.    {
  376.       if(human)
  377.       {
  378.          this.mcKeeper.indicator._visible = true;
  379.       }
  380.       else
  381.       {
  382.          this.mcKeeper.indicator._visible = false;
  383.       }
  384.    }
  385. }
  386.