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

  1. class Player
  2. {
  3.    var mc;
  4.    var timer;
  5.    var playerPosition;
  6.    var saveFramePosition;
  7.    var mcProperties;
  8.    var orientHandler;
  9.    var speedHandler;
  10.    var mouseCalculator;
  11.    var playField;
  12.    var orientAction;
  13.    var isBallOwner;
  14.    var tacleDistMax;
  15.    var ball;
  16.    var tacleVector;
  17.    var smoothTrainee = true;
  18.    function Player(mc, playField)
  19.    {
  20.       this.mc = mc;
  21.       this.mc.gotoAndStop(1);
  22.       this.mc.mcTrainee._visible = false;
  23.       this.mc.mcDirection._visible = false;
  24.       this.mc.mcLine._visible = false;
  25.       this.mc.mcRollOver._visible = false;
  26.       this.timer = new TimerSynchronizer();
  27.       this.playerPosition = new Point2D(this.mc._x,this.mc._y);
  28.       this.saveFramePosition = new Object();
  29.       this.saveFramePosition.player = 1;
  30.       this.saveFramePosition.maillot = 1;
  31.       this.saveFramePosition.frameSeq = 1;
  32.       this.saveFramePosition.frameMobile = 1;
  33.       this.saveFramePosition.frameTacle = 1;
  34.       this.mcProperties = new Object();
  35.       this.mcProperties.umountDirection = 8;
  36.       this.mcProperties.orientation = -1;
  37.       this.orientHandler = new PlayerOrientationHandler();
  38.       this.speedHandler = new PlayerSpeedHandler(this.mc.mcBoost,this.mc.mcTrainee);
  39.       this.mouseCalculator = new MouseMovieClipAngleCalculator(this.mc);
  40.       this.playField = playField;
  41.       this.orientAction = "mobile";
  42.       this.isBallOwner = false;
  43.       this.tacleDistMax = 30;
  44.    }
  45.    function move(x, y)
  46.    {
  47.       var _loc2_ = undefined;
  48.       var _loc3_ = undefined;
  49.       _loc2_ = x;
  50.       _loc3_ = y;
  51.       if(this.playField != null)
  52.       {
  53.          if(this.mc._x < this.playField.getMinX() || x < this.playField.getMinX())
  54.          {
  55.             _loc2_ = this.playField.getMinX();
  56.          }
  57.          if(this.mc._x > this.playField.getMaxX() || x > this.playField.getMaxX())
  58.          {
  59.             _loc2_ = this.playField.getMaxX();
  60.          }
  61.          if(this.mc._y < this.playField.getMinY() || y < this.playField.getMinY())
  62.          {
  63.             _loc3_ = this.playField.getMinY();
  64.          }
  65.          if(this.mc._y > this.playField.getMaxY() || y > this.playField.getMaxY())
  66.          {
  67.             _loc3_ = this.playField.getMaxY();
  68.          }
  69.       }
  70.       this.mc._x = _loc2_;
  71.       this.mc._y = _loc3_;
  72.       this.playerPosition.setX(_loc2_);
  73.       this.playerPosition.setY(_loc3_);
  74.    }
  75.    function getX()
  76.    {
  77.       return this.mc._x;
  78.    }
  79.    function getY()
  80.    {
  81.       return this.mc._y;
  82.    }
  83.    function getOrientation()
  84.    {
  85.       var _loc3_ = this.mouseCalculator.getMouseAngleDEG();
  86.       var _loc2_ = this.orientHandler.getPlayerOrientation(_loc3_,"mobile");
  87.       return _loc2_.orient;
  88.    }
  89.    function getLine()
  90.    {
  91.       return this.mc.mcLine;
  92.    }
  93.    function getRollOver()
  94.    {
  95.       return this.mc.mcRollOver;
  96.    }
  97.    function setImmobile()
  98.    {
  99.       this.orientAction = "static";
  100.       var _loc4_ = this.mouseCalculator.getMouseAngleDEG();
  101.       this.speedHandler.boostAnalyser();
  102.       this.speedHandler.setBoostLock(true);
  103.       this.mc.mcTrainee._visible = false;
  104.       this.saveFramePosition.player = this.mc.mcFootPlayer._currentframe;
  105.       this.saveFramePosition.maillot = this.mc.mcFootPlayer.mcColorMaillot._currentframe;
  106.       var _loc3_ = this.orientHandler.getPlayerOrientation(_loc4_,this.orientAction);
  107.       if(this.orientHandler.isFrameChanged())
  108.       {
  109.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndStop(_loc3_.frame);
  110.          this.mc.mcFootPlayer.gotoAndStop(_loc3_.frame);
  111.       }
  112.       else
  113.       {
  114.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndStop(this.mc.mcFootPlayer._currentframe);
  115.          this.mc.mcFootPlayer.gotoAndStop(this.mc.mcFootPlayer._currentframe);
  116.       }
  117.       if(this.smoothTrainee)
  118.       {
  119.          this.mc.mcTrainee._rotation = _loc4_;
  120.          this.mc.mcDirection._rotation = _loc4_;
  121.          this.mc.mcLine._rotation = _loc4_;
  122.       }
  123.       else
  124.       {
  125.          this.mc.mcTrainee._rotation = _loc3_.flash;
  126.          this.mc.mcDirection._rotation = _loc3_.flash;
  127.          this.mc.mcLine._rotation = _loc3_.flash;
  128.       }
  129.       if(this.isBallOwner == true)
  130.       {
  131.          var _loc5_ = new Vector2D(new Point2D(this.mc._x,this.mc._y),new Point2D(_root._xmouse,_root._ymouse));
  132.          var _loc8_ = _loc5_.getX() / _loc5_.getNorme();
  133.          var _loc7_ = _loc5_.getY() / _loc5_.getNorme();
  134.          var _loc6_ = 8;
  135.          this.ball.moveInField(this.mc._x + _loc8_ * _loc6_,this.mc._y + _loc7_ * _loc6_);
  136.       }
  137.    }
  138.    function setImmobileStaticRollOver()
  139.    {
  140.       this.setImmobile();
  141.       this.mc.mcBoost._visible = false;
  142.       this.manageRollOver();
  143.       if(this.isBallOwnerTest() == true)
  144.       {
  145.          this.mc.mcRollOver._visible = false;
  146.       }
  147.    }
  148.    function setImmobileStatic()
  149.    {
  150.       this.setImmobile();
  151.       this.mc.mcBoost._visible = false;
  152.    }
  153.    function manageRollOver()
  154.    {
  155.       if(_root._xmouse > this.mc._x - 40 && _root._xmouse < this.mc._x + 40)
  156.       {
  157.          if(_root._ymouse > this.mc._y - 40 && _root._ymouse < this.mc._y + 40)
  158.          {
  159.             if(this.isBallOwnerTest() == false)
  160.             {
  161.                this.mc.mcRollOver._visible = true;
  162.             }
  163.          }
  164.       }
  165.       else
  166.       {
  167.          this.mc.mcRollOver._visible = false;
  168.       }
  169.    }
  170.    function setMobile(orientAction)
  171.    {
  172.       var _loc11_ = undefined;
  173.       if(orientAction == "mobile")
  174.       {
  175.          _loc11_ = 7;
  176.       }
  177.       if(orientAction == "tacle")
  178.       {
  179.          _loc11_ = 4;
  180.       }
  181.       var _loc4_ = this.mouseCalculator.getMouseAngleDEG();
  182.       this.speedHandler.boostAnalyser();
  183.       this.speedHandler.setBoostLock(false);
  184.       var _loc3_ = this.orientHandler.getPlayerOrientation(_loc4_,orientAction);
  185.       if(this.smoothTrainee)
  186.       {
  187.          this.mc.mcTrainee._rotation = _loc4_;
  188.          this.mc.mcDirection._rotation = _loc4_;
  189.          this.mc.mcLine._rotation = _loc4_;
  190.       }
  191.       else
  192.       {
  193.          this.mc.mcTrainee._rotation = _loc3_.flash;
  194.          this.mc.mcDirection._rotation = _loc3_.flash;
  195.          this.mc.mcLine._rotation = _loc3_.flash;
  196.       }
  197.       var _loc12_ = this.timer.getElapsedTimeMs();
  198.       if(_loc12_ >= this.speedHandler.getPlayerFramerate())
  199.       {
  200.          this.timer.setOldTimer(getTimer());
  201.          var _loc7_ = undefined;
  202.          if(orientAction == "mobile")
  203.          {
  204.             this.saveFramePosition.frameMobile = (this.saveFramePosition.frameMobile + 1) % 7;
  205.             _loc7_ = this.saveFramePosition.frameMobile;
  206.          }
  207.          if(orientAction == "tacle")
  208.          {
  209.             this.saveFramePosition.frameTacle = (this.saveFramePosition.frameTacle + 1) % 4;
  210.             _loc7_ = this.saveFramePosition.frameTacle;
  211.          }
  212.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndPlay(_loc3_.frame + _loc7_);
  213.          this.mc.mcFootPlayer.gotoAndPlay(_loc3_.frame + _loc7_);
  214.       }
  215.       var _loc5_ = new Vector2D(new Point2D(this.mc._x,this.mc._y),new Point2D(_root._xmouse,_root._ymouse));
  216.       var _loc10_ = _loc5_.getX() / _loc5_.getNorme() * this.speedHandler.getSpeed() * this.speedHandler.getBoostPower();
  217.       var _loc8_ = _loc5_.getY() / _loc5_.getNorme() * this.speedHandler.getSpeed() * this.speedHandler.getBoostPower();
  218.       this.move(this.mc._x + _loc10_,this.mc._y + _loc8_);
  219.       this.playerPosition.setX(this.mc._x);
  220.       this.playerPosition.setY(this.mc._y);
  221.       if(this.isBallOwner == true)
  222.       {
  223.          var _loc9_ = 20;
  224.          this.ball.moveInField(this.mc._x + _loc10_ * _loc9_,this.mc._y + _loc8_ * _loc9_);
  225.       }
  226.    }
  227.    function setMobileTacle()
  228.    {
  229.       var _loc10_ = 4;
  230.       var _loc8_ = Math.atan2(this.tacleVector.getY(),this.tacleVector.getX());
  231.       var _loc3_ = _loc8_ * 180 / 3.141592653589793;
  232.       this.speedHandler.boostAnalyser();
  233.       this.speedHandler.setBoostLock(false);
  234.       var _loc2_ = this.orientHandler.getPlayerOrientation(_loc3_,"tacle");
  235.       if(this.smoothTrainee)
  236.       {
  237.          this.mc.mcTrainee._rotation = _loc3_;
  238.          this.mc.mcDirection._rotation = _loc3_;
  239.          this.mc.mcLine._rotation = _loc3_;
  240.       }
  241.       else
  242.       {
  243.          this.mc.mcTrainee._rotation = _loc2_.flash;
  244.          this.mc.mcDirection._rotation = _loc2_.flash;
  245.          this.mc.mcLine._rotation = _loc2_.flash;
  246.       }
  247.       var _loc9_ = this.timer.getElapsedTimeMs();
  248.       if(_loc9_ >= this.speedHandler.getPlayerFramerate())
  249.       {
  250.          this.timer.setOldTimer(getTimer());
  251.          var _loc4_ = undefined;
  252.          this.saveFramePosition.frameTacle = (this.saveFramePosition.frameTacle + 1) % 4;
  253.          _loc4_ = this.saveFramePosition.frameTacle;
  254.          this.mc.mcFootPlayer.mcColorMaillot.gotoAndPlay(_loc2_.frame + _loc4_);
  255.          this.mc.mcFootPlayer.gotoAndPlay(_loc2_.frame + _loc4_);
  256.       }
  257.       var _loc7_ = this.tacleVector.getX() / this.tacleVector.getNorme() * this.speedHandler.getSpeed() * this.speedHandler.getBoostPower();
  258.       var _loc5_ = this.tacleVector.getY() / this.tacleVector.getNorme() * this.speedHandler.getSpeed() * this.speedHandler.getBoostPower();
  259.       this.move(this.mc._x + _loc7_,this.mc._y + _loc5_);
  260.       this.playerPosition.setX(this.mc._x);
  261.       this.playerPosition.setY(this.mc._y);
  262.       if(this.isBallOwner == true)
  263.       {
  264.          var _loc6_ = 10;
  265.          this.ball.moveInField(this.mc._x + _loc7_ * _loc6_,this.mc._y + _loc5_ * _loc6_);
  266.       }
  267.    }
  268.    function modeNoSelected()
  269.    {
  270.       this.mc.mcBoost._visible = false;
  271.       this.mc.mcSelection._visible = false;
  272.       this.mc.mcTrainee._visible = false;
  273.       this.mc.mcLine._xscale = 0;
  274.    }
  275.    function modeSelected()
  276.    {
  277.       var _loc2_ = this.mouseCalculator.getMouseDistance();
  278.       var _loc3_ = this.mouseCalculator.getMouseAngleDEG();
  279.       if(_loc2_ <= 2)
  280.       {
  281.          this.setImmobile();
  282.       }
  283.       else
  284.       {
  285.          this.mc.mcDirection._rotation = _loc3_;
  286.          this.mc.mcLine._xscale = _loc2_ * 2;
  287.          this.setMobile("mobile");
  288.       }
  289.    }
  290.    function modeSelectedStatic()
  291.    {
  292.       var _loc2_ = this.mouseCalculator.getMouseDistance();
  293.       var _loc3_ = this.mouseCalculator.getMouseAngleDEG();
  294.       this.mc.mcSelection._visible = true;
  295.       this.mc.mcDirection._rotation = _loc3_;
  296.       this.mc.mcLine._xscale = _loc2_ * 2;
  297.    }
  298.    function modeTacle()
  299.    {
  300.       var _loc2_ = this.mouseCalculator.getMouseDistance();
  301.       var _loc3_ = this.mouseCalculator.getMouseAngleDEG();
  302.       this.mc.mcDirection._rotation = _loc3_;
  303.       this.mc.mcLine._xscale = _loc2_ * 2;
  304.       this.setMobile("tacle");
  305.    }
  306.    function modeTacle2()
  307.    {
  308.       this.setSpeedBoost(false);
  309.       var _loc2_ = this.mouseCalculator.getMouseDistance();
  310.       var _loc3_ = this.mouseCalculator.getMouseAngleDEG();
  311.       this.mc.mcFootPlayer.mcDirection._rotation = _loc3_;
  312.       this.mc.mcLine._xscale = _loc2_ * 2;
  313.       this.setMobileTacle();
  314.    }
  315.    function setSpeedBoost(bool)
  316.    {
  317.       if(bool == true && this.speedHandler.getBoostLock() == false)
  318.       {
  319.          this.speedHandler.boostActivation();
  320.          return undefined;
  321.       }
  322.       if(bool == false || this.speedHandler.getBoostLock() == false)
  323.       {
  324.          this.speedHandler.boostDesactivation();
  325.          return undefined;
  326.       }
  327.    }
  328.    function getBallInstance(ball)
  329.    {
  330.       this.ball = ball;
  331.    }
  332.    function getMovieClip()
  333.    {
  334.       return this.mc;
  335.    }
  336.    function setPlayerBallOwner(bool)
  337.    {
  338.       this.isBallOwner = bool;
  339.       this.ball.moveInField(this.playerPosition.getX(),this.playerPosition.getY());
  340.       this.ball.updateTrueValues();
  341.    }
  342.    function isBallOwnerTest()
  343.    {
  344.       return this.isBallOwner;
  345.    }
  346.    function setTacleVector(tacleVector)
  347.    {
  348.       this.tacleVector = tacleVector;
  349.    }
  350.    function getTacleVector(tacleVector)
  351.    {
  352.       return this.tacleVector;
  353.    }
  354.    function setDirectionVisible(bool)
  355.    {
  356.       this.mc.mcDirection._visible = bool;
  357.    }
  358.    function setLineVisible(bool)
  359.    {
  360.       this.mc.mcLine._visible = bool;
  361.    }
  362.    function trace()
  363.    {
  364.       trace("Player: " + this.mc);
  365.    }
  366. }
  367.