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

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