home *** CD-ROM | disk | FTP | other *** search
/ Equipe de France et Bonbons / EquipeFrancePromoCD.iso / pages / cs_cadbury / loadergfx.swf / scripts / __Packages / PlayerTargetTracker.as < prev    next >
Encoding:
Text File  |  2006-03-19  |  6.5 KB  |  204 lines

  1. class PlayerTargetTracker
  2. {
  3.    var mc;
  4.    var timer;
  5.    var playerPosition;
  6.    var saveFramePosition;
  7.    var mcProperties;
  8.    var orientHandler;
  9.    var speedHandler;
  10.    var targetCalculator;
  11.    var playField;
  12.    var mcTarget;
  13.    var isBallOwner;
  14.    var ball;
  15.    var smoothTrainee = true;
  16.    function PlayerTargetTracker(mc, playField, mcTarget)
  17.    {
  18.       this.mc = mc;
  19.       this.mc.gotoAndStop(1);
  20.       this.mc.mcTrainee._visible = false;
  21.       this.mc.mcDirection._visible = false;
  22.       this.mc.mcLine._visible = false;
  23.       this.timer = new TimerSynchronizer();
  24.       this.playerPosition = new Point2D(this.mc._x,this.mc._y);
  25.       this.saveFramePosition = new Object();
  26.       this.saveFramePosition.player = 1;
  27.       this.saveFramePosition.maillot = 1;
  28.       this.saveFramePosition.frameSeq = 1;
  29.       this.mcProperties = new Object();
  30.       this.mcProperties.umountDirection = 8;
  31.       this.mcProperties.orientation = -1;
  32.       this.orientHandler = new PlayerOrientationHandler();
  33.       this.speedHandler = new PlayerSpeedHandler(this.mc.mcBoost,this.mc.mcTrainee);
  34.       this.targetCalculator = new TargetMovieClipAngleCalculator(this.mc,mcTarget);
  35.       this.playField = playField;
  36.       this.mcTarget = mcTarget;
  37.    }
  38.    function move(x, y)
  39.    {
  40.       var _loc2_ = undefined;
  41.       var _loc3_ = undefined;
  42.       _loc2_ = x;
  43.       _loc3_ = y;
  44.       if(this.playField != null)
  45.       {
  46.          if(this.mc._x < this.playField.getMinX() || x < this.playField.getMinX())
  47.          {
  48.             _loc2_ = this.playField.getMinX();
  49.          }
  50.          if(this.mc._x > this.playField.getMaxX() || x > this.playField.getMaxX())
  51.          {
  52.             _loc2_ = this.playField.getMaxX();
  53.          }
  54.          if(this.mc._y < this.playField.getMinY() || y < this.playField.getMinY())
  55.          {
  56.             _loc3_ = this.playField.getMinY();
  57.          }
  58.          if(this.mc._y > this.playField.getMaxY() || y > this.playField.getMaxY())
  59.          {
  60.             _loc3_ = this.playField.getMaxY();
  61.          }
  62.       }
  63.       this.mc._x = _loc2_;
  64.       this.mc._y = _loc3_;
  65.       this.playerPosition.setX(_loc2_);
  66.       this.playerPosition.setY(_loc3_);
  67.    }
  68.    function getX()
  69.    {
  70.       return this.mc._x;
  71.    }
  72.    function getY()
  73.    {
  74.       return this.mc._y;
  75.    }
  76.    function getOrientation()
  77.    {
  78.       var _loc3_ = this.targetCalculator.getTargetAngleDEG();
  79.       var _loc2_ = this.orientHandler.getPlayerOrientation(_loc3_,"mobile");
  80.       return _loc2_.orient;
  81.    }
  82.    function setImmobile()
  83.    {
  84.       var _loc3_ = this.targetCalculator.getTargetAngleDEG();
  85.       this.speedHandler.boostAnalyser();
  86.       this.speedHandler.setBoostLock(true);
  87.       this.mc.mcTrainee._visible = false;
  88.       this.saveFramePosition.player = this.mc.mcFootPlayer._currentframe;
  89.       this.saveFramePosition.maillot = this.mc.mcFootPlayer.mcColorMaillot._currentframe;
  90.       var _loc2_ = this.orientHandler.getPlayerOrientation(_loc3_,"static");
  91.       if(this.orientHandler.isFrameChanged())
  92.       {
  93.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndStop(_loc2_.frame);
  94.          this.mc.mcFootPlayer.gotoAndStop(_loc2_.frame);
  95.       }
  96.       else
  97.       {
  98.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndStop(this.mc.mcFootPlayer._currentframe);
  99.          this.mc.mcFootPlayer.gotoAndStop(this.mc.mcFootPlayer._currentframe);
  100.       }
  101.       if(this.isBallOwner == true)
  102.       {
  103.       }
  104.    }
  105.    function setMobile()
  106.    {
  107.       var _loc4_ = this.targetCalculator.getTargetAngleDEG();
  108.       this.speedHandler.setBoostLock(false);
  109.       this.mc.mcFootPlayer.mcDirection._visible = true;
  110.       var _loc3_ = this.orientHandler.getPlayerOrientation(_loc4_,"mobile");
  111.       if(this.smoothTrainee)
  112.       {
  113.          this.mc.mcTrainee._rotation = _loc4_;
  114.       }
  115.       else
  116.       {
  117.          this.mc.mcTrainee._rotation = _loc3_.flash;
  118.       }
  119.       var _loc9_ = this.timer.getElapsedTimeMs();
  120.       if(_loc9_ >= this.speedHandler.getPlayerFramerate())
  121.       {
  122.          this.timer.setOldTimer(getTimer());
  123.          this.saveFramePosition.frameSeq = (this.saveFramePosition.frameSeq + 1) % 7;
  124.          var _loc5_ = this.saveFramePosition.frameSeq;
  125.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndPlay(_loc3_.frame + _loc5_);
  126.          this.mc.mcFootPlayer.gotoAndPlay(_loc3_.frame + _loc5_);
  127.       }
  128.       var _loc2_ = new Vector2D(new Point2D(this.mc._x,this.mc._y),new Point2D(this.mcTarget._x,this.mcTarget._y));
  129.       var _loc8_ = _loc2_.getX() / _loc2_.getNorme() * this.speedHandler.getSpeed() * this.speedHandler.getBoostPower();
  130.       var _loc6_ = _loc2_.getY() / _loc2_.getNorme() * this.speedHandler.getSpeed() * this.speedHandler.getBoostPower();
  131.       this.move(this.mc._x + _loc8_,this.mc._y + _loc6_);
  132.       this.playerPosition.setX(this.mc._x);
  133.       this.playerPosition.setY(this.mc._y);
  134.       if(this.isBallOwner == true)
  135.       {
  136.          var _loc7_ = 6;
  137.          this.ball.setRotationDEG(_loc4_);
  138.          this.ball.moveInField(this.mc._x + _loc8_ * _loc7_,this.mc._y + _loc6_ * _loc7_);
  139.       }
  140.    }
  141.    function modeNoSelected()
  142.    {
  143.       this.mc.mcBoost._visible = false;
  144.       this.mc.mcSelection._visible = false;
  145.       this.mc.mcTrainee._visible = false;
  146.    }
  147.    function modeSelected()
  148.    {
  149.       var _loc2_ = this.targetCalculator.getTargetDistance();
  150.       var _loc3_ = this.targetCalculator.getTargetAngleDEG();
  151.       if(_loc2_ <= 2)
  152.       {
  153.          this.setImmobile();
  154.       }
  155.       else
  156.       {
  157.          this.mc.mcFootPlayer.mcDirection._rotation = _loc3_;
  158.          this.setMobile();
  159.       }
  160.    }
  161.    function setSpeedBoost(bool)
  162.    {
  163.       if(bool == true && this.speedHandler.getBoostLock() == false)
  164.       {
  165.          this.speedHandler.boostActivation();
  166.          return undefined;
  167.       }
  168.       if(bool == false || this.speedHandler.getBoostLock() == false)
  169.       {
  170.          this.speedHandler.boostDesactivation();
  171.          return undefined;
  172.       }
  173.    }
  174.    function getBallInstance(ball)
  175.    {
  176.       this.ball = ball;
  177.    }
  178.    function getMovieClip()
  179.    {
  180.       return this.mc;
  181.    }
  182.    function setRunSpeed(speed)
  183.    {
  184.       this.speedHandler.setSpeed(speed);
  185.    }
  186.    function setPlayerBallOwner(bool)
  187.    {
  188.       this.isBallOwner = bool;
  189.       this.ball.moveInField(this.playerPosition.getX(),this.playerPosition.getY());
  190.    }
  191.    function isBallOwnerTest()
  192.    {
  193.       return this.isBallOwner;
  194.    }
  195.    function setDirectionVisible(bool)
  196.    {
  197.       this.mc.mcDirection._visible = bool;
  198.    }
  199.    function setLineVisible(bool)
  200.    {
  201.       this.mc.mcLine._visible = bool;
  202.    }
  203. }
  204.