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

  1. class CBall
  2. {
  3.    var count = 0;
  4.    var def_bx = 54.8;
  5.    var def_by = 0.1;
  6.    var def_bz = -38.5;
  7.    var gravity = 0.9;
  8.    var friction = 0.95;
  9.    function CBall(bg, _mcParent)
  10.    {
  11.       this.mcParent = _mcParent;
  12.       this.mybg = bg;
  13.       this.camswitched = false;
  14.       this.createBall();
  15.       this.createShadow();
  16.       this.createMarker();
  17.       this.ctrNT = -1;
  18.       this.halted = false;
  19.    }
  20.    function createBall()
  21.    {
  22.       this.bx = this.def_bx;
  23.       this.by = this.def_by;
  24.       this.bz = this.def_bz;
  25.       this.ball = new sandy.core.Sprite2D(0.03);
  26.       this.mcBall = this.mcParent.attachMovie("ball","ball",this.mcParent.getNextHighestDepth());
  27.       this.mcBall._visible = false;
  28.       var _loc3_ = new sandy.skin.MovieSkin(this.mcBall);
  29.       this.ball.setSkin(_loc3_);
  30.       var _loc2_ = new sandy.core.group.TransformGroup();
  31.       this.bTrans = new sandy.core.transform.Transform3D();
  32.       this.bTrans.translate(this.bx,this.by,this.bz);
  33.       _loc2_.setTransform(this.bTrans);
  34.       _loc2_.addChild(this.ball);
  35.       this.mybg.addChild(_loc2_);
  36.    }
  37.    function getPosition()
  38.    {
  39.       var _loc2_ = this.ball.getPosition();
  40.       return _loc2_;
  41.    }
  42.    function createShadow()
  43.    {
  44.       this.bx = this.def_bx;
  45.       this.by = this.def_by;
  46.       this.bz = this.def_bz;
  47.       var _loc3_ = new sandy.primitive.Plane3D(0.5,0.5,1,"tri");
  48.       this.mcBallShadow = this.mcParent.attachMovie("ballshadow","ballshadow",this.mcParent.getNextHighestDepth());
  49.       this.mcBallShadow._visible = false;
  50.       var _loc4_ = new sandy.skin.MovieSkin(this.mcBallShadow);
  51.       _loc3_.setSkin(_loc4_);
  52.       var _loc2_ = new sandy.core.group.TransformGroup();
  53.       this.bsTrans = new sandy.core.transform.Transform3D();
  54.       this.bsTrans.translate(this.bx,-0.1,this.bz);
  55.       _loc2_.setTransform(this.bsTrans);
  56.       _loc2_.addChild(_loc3_);
  57.       this.mybg.addChild(_loc2_);
  58.    }
  59.    function createMarker()
  60.    {
  61.       this.markball = new sandy.primitive.Plane3D(1,1,1,"tri");
  62.       var _loc3_ = this.mcParent.attachMovie("bayball","bayball",this.mcParent.getNextHighestDepth());
  63.       _loc3_._visible = false;
  64.       var _loc4_ = new sandy.skin.MovieSkin(_loc3_);
  65.       this.markball.setSkin(_loc4_);
  66.       var _loc2_ = new sandy.core.group.TransformGroup();
  67.       this.bmTrans = new sandy.core.transform.Transform3D();
  68.       this.bmTrans.translate(this.def_bx + 2,0,this.def_bz - 2);
  69.       _loc2_.setTransform(this.bmTrans);
  70.       _loc2_.addChild(this.markball);
  71.       this.mybg.addChild(_loc2_);
  72.    }
  73.    function createTanda()
  74.    {
  75.       var _loc3_ = new sandy.primitive.Box(0.1,0.1,0.1,"tri");
  76.       var _loc4_ = new sandy.skin.SimpleColorSkin(65535,100);
  77.       _loc3_.setSkin(_loc4_);
  78.       var _loc2_ = new sandy.core.group.TransformGroup();
  79.       this.xTanda = new sandy.core.transform.Transform3D();
  80.       this.xTanda.translate(54,0,4.2);
  81.       _loc2_.setTransform(this.xTanda);
  82.       _loc2_.addChild(_loc3_);
  83.       this.mybg.addChild(_loc2_);
  84.    }
  85.    function createTrajectoryLine(vs1, vs2)
  86.    {
  87.       var _loc2_ = new sandy.primitive.Line3D(vs1,vs2);
  88.       _loc2_.setSkin(new sandy.skin.SimpleLineSkin(1,0,30));
  89.       this.tgTrajectoryLine = new sandy.core.group.TransformGroup();
  90.       this.tgTrajectoryLine.addChild(_loc2_);
  91.       this.mybg.addChild(this.tgTrajectoryLine);
  92.    }
  93.    function deleteTrajectoryLine()
  94.    {
  95.       this.tgTrajectoryLine.destroy();
  96.    }
  97.    function shoot(_power, anglex, angley)
  98.    {
  99.       this.power = _power;
  100.       this.Aangle = anglex * -1 * 3.141592653589793 / 180;
  101.       this.Bangle = angley * -1 * 3.141592653589793 / 180;
  102.       this.terus = true;
  103.       this.yVel = Math.sin(this.Aangle) * this.power;
  104.       var _loc2_ = Math.cos(this.Aangle) * this.power;
  105.       this.xVel = Math.sin(this.Bangle) * _loc2_;
  106.       this.zVel = Math.cos(this.Bangle) * _loc2_;
  107.    }
  108.    function makeshoot(power, anglex, angley)
  109.    {
  110.       this.Aangle = anglex * -1 * 3.141592653589793 / 180;
  111.       this.Bangle = angley * -1 * 3.141592653589793 / 180;
  112.       this.terus = true;
  113.       this.yVel = Math.sin(this.Aangle) * power;
  114.       var _loc3_ = Math.cos(this.Aangle) * power;
  115.       this.xVel = Math.sin(this.Bangle) * _loc3_;
  116.       this.zVel = Math.cos(this.Bangle) * _loc3_;
  117.       _global.__DISPATCH({type:"gameevent",param:"shoot"});
  118.       this.halted = false;
  119.    }
  120.    function haltedit()
  121.    {
  122.       this.xVel = 0;
  123.       this.zVel = 0;
  124.       this.halted = true;
  125.    }
  126.    function deflect()
  127.    {
  128.       this.yVel /= 3;
  129.       this.xVel = - this.xVel / 3;
  130.       this.zVel = - this.zVel / 3;
  131.    }
  132.    function makeBallTrajectories()
  133.    {
  134.       this.arBallTrajectories = new Array();
  135.       var _loc3_ = new Object();
  136.       _loc3_.bx = this.bx;
  137.       _loc3_.by = this.by;
  138.       _loc3_.bz = this.bz;
  139.       _loc3_.xVel = this.xVel;
  140.       _loc3_.yVel = this.yVel;
  141.       _loc3_.zVel = this.zVel;
  142.       _loc3_.power = this.power;
  143.       _loc3_.Aangle = this.Aangle;
  144.       var _loc7_ = new sandy.core.data.Vector(this.bx,0,this.bz);
  145.       var _loc5_ = false;
  146.       var _loc4_ = 20;
  147.       while(!_loc5_)
  148.       {
  149.          var _loc2_ = new CBallPoint(this.mybg,this.mcParent,_loc3_,_loc4_);
  150.          _loc4_ += 3;
  151.          if(_loc2_.obax2.by <= 0)
  152.          {
  153.             _loc5_ = true;
  154.             this.bmTrans.translate(_loc2_.obax2.bx,0,_loc2_.obax2.bz);
  155.          }
  156.          this.arBallTrajectories.push(_loc2_);
  157.          _loc3_ = _loc2_.obax2;
  158.       }
  159.       var _loc6_ = new sandy.core.data.Vector(_loc3_.bx,0,_loc3_.bz);
  160.       this.createTrajectoryLine(_loc7_,_loc6_);
  161.    }
  162.    function clearBallTrajectories()
  163.    {
  164.       var _loc2_ = 0;
  165.       while(_loc2_ < this.arBallTrajectories.length)
  166.       {
  167.          this.arBallTrajectories[_loc2_].destroy();
  168.          delete this.arBallTrajectories[_loc2_];
  169.          _loc2_ = _loc2_ + 1;
  170.       }
  171.       this.deleteTrajectoryLine();
  172.    }
  173.    function getNearestBallTrajectories(kp)
  174.    {
  175.       var _loc5_ = new sandy.core.data.Vector(0,0,0);
  176.       var _loc6_ = 100;
  177.       this.idNT = 0;
  178.       var _loc2_ = 0;
  179.       while(_loc2_ < this.arBallTrajectories.length)
  180.       {
  181.          var _loc3_ = CBallPoint(this.arBallTrajectories[_loc2_]).getPosition();
  182.          var _loc4_ = Math.abs(kp.z - _loc3_.z);
  183.          if(_loc4_ < _loc6_)
  184.          {
  185.             this.idNT = _loc2_;
  186.             _loc6_ = _loc4_;
  187.             _loc5_.x = _loc3_.x;
  188.             _loc5_.y = _loc3_.y;
  189.             _loc5_.z = _loc3_.z;
  190.          }
  191.          _loc2_ = _loc2_ + 1;
  192.       }
  193.       return _loc5_;
  194.    }
  195.    function randRange(min, max)
  196.    {
  197.       var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
  198.       return _loc1_;
  199.    }
  200.    function getRandomPos()
  201.    {
  202.       if(this.arBallTrajectories.length > 10)
  203.       {
  204.          var _loc4_ = -1;
  205.          var _loc2_ = 10;
  206.          while(_loc4_ == -1 && _loc2_ < this.arBallTrajectories.length)
  207.          {
  208.             var _loc3_ = CBallPoint(this.arBallTrajectories[_loc2_]).getPosition();
  209.             if(_loc3_.y < 3)
  210.             {
  211.                _loc4_ = _loc2_;
  212.             }
  213.             _loc2_ = _loc2_ + 1;
  214.          }
  215.          var _loc6_ = this.randRange(_loc4_,this.arBallTrajectories.length - 1);
  216.       }
  217.       else
  218.       {
  219.          _loc6_ = this.arBallTrajectories.length - 1;
  220.       }
  221.       var _loc5_ = this.arBallTrajectories[_loc6_].getPosition();
  222.       if(_loc5_.y > 2)
  223.       {
  224.          _loc5_.x += this.randRange(-0.5,0.5);
  225.       }
  226.       else
  227.       {
  228.          _loc5_.x += this.randRange(0,0);
  229.       }
  230.       _loc5_.y = 0;
  231.       return _loc5_;
  232.    }
  233.    function startTrajectoryCounter(nwait)
  234.    {
  235.       this.ctrNT = 0;
  236.       this.idNT -= nwait;
  237.    }
  238.    function reset()
  239.    {
  240.       this.bx = this.def_bx;
  241.       this.by = this.def_by;
  242.       this.bz = this.def_bz;
  243.       this.bTrans.translate(this.def_bx,this.def_by,this.def_bz);
  244.       this.bsTrans.translate(this.def_bx,-0.1,this.def_bz);
  245.       this.bmTrans.translate(this.def_bx + 2,0,this.def_bz - 2);
  246.       this.clearBallTrajectories();
  247.       this.camswitched = false;
  248.       this.halted = false;
  249.       this.ingoalsequence = 0;
  250.       this.ctrNT = -1;
  251.    }
  252.    function render(rat)
  253.    {
  254.       if(!this.terus)
  255.       {
  256.          return undefined;
  257.       }
  258.       if(rat == undefined)
  259.       {
  260.          rat = 0.01;
  261.       }
  262.       this.yVel -= this.gravity;
  263.       this.bx += this.xVel * rat;
  264.       this.by += this.yVel * rat;
  265.       this.bz += this.zVel * rat;
  266.       if(this.ctrNT != -1)
  267.       {
  268.          this.ctrNT = this.ctrNT + 1;
  269.          if(this.ctrNT == this.idNT)
  270.          {
  271.             _global.__DISPATCH({type:"kickerevent",param:"shoot"});
  272.          }
  273.       }
  274.       if(this.bz > -10 && !this.camswitched)
  275.       {
  276.          this.camswitched = true;
  277.          this.makeBallTrajectories();
  278.          _global.__DISPATCH({type:"gameevent",param:"transition"});
  279.       }
  280.       if(this.by < this.def_by)
  281.       {
  282.          this.by = this.def_by;
  283.          this.power *= 0.6;
  284.          this.yVel = Math.sin(this.Aangle) * this.power;
  285.          this.xVel *= this.friction;
  286.          this.zVel *= this.friction;
  287.          if(this.power < 0.1)
  288.          {
  289.             this.power = 0;
  290.             if(Math.abs(this.xVel) < 1)
  291.             {
  292.                this.xVel = 0;
  293.             }
  294.             if(Math.abs(this.yVel) < 1)
  295.             {
  296.                this.yVel = 0;
  297.             }
  298.             if(Math.abs(this.zVel) < 1)
  299.             {
  300.                this.zVel = 0;
  301.             }
  302.             if(this.xVel == 0 && this.yVel == 0 && this.zVel == 0)
  303.             {
  304.                this.terus = false;
  305.                _global.__DISPATCH({type:"gameevent",param:"ballout"});
  306.             }
  307.          }
  308.       }
  309.       if(this.bz > 14 || this.bx > 70 || this.bx < 30)
  310.       {
  311.          this.terus = false;
  312.          _global.__DISPATCH({type:"gameevent",param:"ballout"});
  313.       }
  314.       this.bTrans.translate(this.bx,this.by,this.bz);
  315.       this.bsTrans.translate(this.bx,-0.1,this.bz);
  316.    }
  317.    function cekinggoal()
  318.    {
  319.       if(this.ingoalsequence == 4)
  320.       {
  321.          if(this.bx > 58 || this.bz > 4.2 || this.bz < -3.2 || this.by > 3)
  322.          {
  323.             if(this.bx > 58)
  324.             {
  325.                this.bx = 58;
  326.             }
  327.             if(this.bz > 3.2)
  328.             {
  329.                this.bz = 3.2;
  330.             }
  331.             if(this.bz < -3.2)
  332.             {
  333.                this.bz = -3.2;
  334.             }
  335.             this.xVel = 0;
  336.             this.zVel = 0;
  337.             this.ingoalsequence = 5;
  338.          }
  339.       }
  340.       if(this.ingoalsequence == 3)
  341.       {
  342.          _global.__DISPATCH({type:"gameevent",param:"enteringhurdle"});
  343.       }
  344.       if(this.ingoalsequence == 2)
  345.       {
  346.          if(this.bx > 54.5)
  347.          {
  348.             if(this.bx < 58 && this.bz <= 4.2 && this.bz > -3.2 and this.by < 3)
  349.             {
  350.                this.ingoalsequence = 3;
  351.             }
  352.             else
  353.             {
  354.                _global.__DISPATCH({type:"gameevent",param:"loose"});
  355.                this.ingoalsequence = 0;
  356.             }
  357.          }
  358.       }
  359.       if(this.ingoalsequence == 1)
  360.       {
  361.          if(this.bx > 50)
  362.          {
  363.             this.ingoalsequence = 2;
  364.             _global.__DISPATCH({type:"keeperevent",param:"ballclosing"});
  365.          }
  366.       }
  367.    }
  368.    function hide()
  369.    {
  370.       this.mcBallShadow.gotoAndStop(2);
  371.       this.mcBall.gotoAndStop(2);
  372.    }
  373.    function show()
  374.    {
  375.       this.mcBallShadow.gotoAndStop(1);
  376.       this.mcBall.gotoAndStop(1);
  377.    }
  378. }
  379.