home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 145 / MOBICLIC145.ISO / pc / DATA / DSS145 / DSS145_07 / DSS145_07.swf / scripts / dss145_07 / Taureau.as < prev    next >
Text File  |  2012-07-18  |  9KB  |  316 lines

  1. package dss145_07
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.events.TimerEvent;
  5.    import flash.geom.Point;
  6.    import flash.utils.Timer;
  7.    import flash.utils.getTimer;
  8.    
  9.    public class Taureau
  10.    {
  11.       
  12.       public static const STOPPED:int = 0;
  13.       
  14.       public static const RUNNING:int = 1;
  15.       
  16.       public static const EJECT:int = 2;
  17.       
  18.       public static const READY_TO_PICK:int = 3;
  19.        
  20.       
  21.       private var _movie:MovieClip;
  22.       
  23.       public var state:int = 0;
  24.       
  25.       private var speed:Number = 1;
  26.       
  27.       private var _timer:Timer;
  28.       
  29.       private var _lastTime:int = 0;
  30.       
  31.       private var _actualTime:int = 0;
  32.       
  33.       private var _metreSecondes:Number = 0;
  34.       
  35.       private var _pixelSecondes:Number = 0;
  36.       
  37.       private var fps:Number = 0;
  38.       
  39.       private var _frameDuration:Number = 0;
  40.       
  41.       private var equivalentUnMetreEnPixels:Number = 100;
  42.       
  43.       private var distancePixelParFrame:Number = 10;
  44.       
  45.       public var delaiDecrochage:Number = 2000;
  46.       
  47.       public var delaiAcrochage:Number = 12000;
  48.       
  49.       public var delayToClic:Number = 2000;
  50.       
  51.       public var distanceSeuilPx:Number = 15;
  52.       
  53.       private var frameToReach:int;
  54.       
  55.       public var onRunning:Function;
  56.       
  57.       private var pt:Point;
  58.       
  59.       private var ptMouse:Point;
  60.       
  61.       public var timeToPeakExceed:Boolean = false;
  62.       
  63.       private var _lastFrameCalcul:Number = 1;
  64.       
  65.       private var isOn:Boolean = false;
  66.       
  67.       public var eject:Boolean = false;
  68.       
  69.       public var readyToPick:Boolean = false;
  70.       
  71.       public var isPicked:Boolean = false;
  72.       
  73.       public var acrochageTime:Number;
  74.       
  75.       private var decroche:Boolean = false;
  76.       
  77.       private var _timeDecrochage:Number = 0;
  78.       
  79.       private var _timeAcrochage:Number = 0;
  80.       
  81.       private var _timeActual:Number = 0;
  82.       
  83.       public function Taureau(param1:MovieClip)
  84.       {
  85.          this._timer = new Timer(20);
  86.          this.onRunning = function():void
  87.          {
  88.          };
  89.          this.pt = new Point();
  90.          this.ptMouse = new Point();
  91.          super();
  92.          this._movie = param1;
  93.          this._movie.gotoAndStop(1);
  94.       }
  95.       
  96.       public function reset() : void
  97.       {
  98.          this._movie.gotoAndStop(1);
  99.          this.setState("E0");
  100.       }
  101.       
  102.       public function run() : void
  103.       {
  104.          this._timer.removeEventListener(TimerEvent.TIMER,this.timerHandler);
  105.          this._timer.addEventListener(TimerEvent.TIMER,this.timerHandler);
  106.          this._timer.start();
  107.          this.isOn = true;
  108.          this.decroche = false;
  109.          this._lastTime = this._timeAcrochage = this._timeDecrochage = getTimer();
  110.          this.setState("E1");
  111.          this.state = RUNNING;
  112.       }
  113.       
  114.       public function continueAcrochage() : void
  115.       {
  116.          this._timer.removeEventListener(TimerEvent.TIMER,this.timerHandler);
  117.          this._timer.addEventListener(TimerEvent.TIMER,this.timerHandler);
  118.          this._timer.start();
  119.          this.isOn = true;
  120.          this.decroche = false;
  121.          this._lastTime = this._timeAcrochage = this._timeDecrochage = getTimer();
  122.          this.setState("E1");
  123.          this.state = RUNNING;
  124.       }
  125.       
  126.       public function stop() : void
  127.       {
  128.          this._timer.stop();
  129.          this._timer.removeEventListener(TimerEvent.TIMER,this.timerHandler);
  130.          this.state = STOPPED;
  131.       }
  132.       
  133.       public function move() : void
  134.       {
  135.          this.frameToReach = this._movie.currentFrame + 1;
  136.          if(this.frameToReach > this._movie.totalFrames)
  137.          {
  138.             this._movie.gotoAndStop(this.frameToReach - this._movie.totalFrames);
  139.          }
  140.          else
  141.          {
  142.             this._movie.gotoAndStop(this.frameToReach);
  143.          }
  144.       }
  145.       
  146.       private function timerHandler(param1:TimerEvent) : void
  147.       {
  148.          this._actualTime = getTimer();
  149.          if(this._actualTime - this._lastTime > this.frameDuration)
  150.          {
  151.             this._lastTime = this._actualTime;
  152.             this.frameToReach = this._movie.currentFrame + 1;
  153.             if(this.frameToReach > this._movie.totalFrames)
  154.             {
  155.                this._movie.gotoAndStop(this.frameToReach - this._movie.totalFrames);
  156.             }
  157.             else
  158.             {
  159.                this._movie.gotoAndStop(this.frameToReach);
  160.             }
  161.          }
  162.          if(this.isOn)
  163.          {
  164.             this._timeActual = getTimer();
  165.             this.acrochageTime = this._timeActual - this._timeAcrochage;
  166.             if(this.acrochageTime > this.delaiAcrochage)
  167.             {
  168.                if(this.acrochageTime - this.delaiAcrochage >= this.delayToClic)
  169.                {
  170.                   this.stop();
  171.                   this.timeToPeakExceed = true;
  172.                }
  173.                else
  174.                {
  175.                   this._movie.TAUREAU.gotoAndStop("E2");
  176.                   this.readyToPick = true;
  177.                }
  178.             }
  179.             else
  180.             {
  181.                this.readyToPick = false;
  182.             }
  183.             if(this._movie.TAUREAU.hitTestPoint(this._movie.stage.mouseX,this._movie.stage.mouseY,true))
  184.             {
  185.                if(this.decroche == true)
  186.                {
  187.                   this.decroche = false;
  188.                }
  189.             }
  190.             else
  191.             {
  192.                if(this.decroche == false)
  193.                {
  194.                   this.decroche = true;
  195.                   this._timeDecrochage = getTimer();
  196.                }
  197.                if(this._timeActual - this._timeDecrochage > this.delaiDecrochage)
  198.                {
  199.                   this.stop();
  200.                   this.isOn = false;
  201.                   this.eject = true;
  202.                }
  203.             }
  204.          }
  205.          param1.updateAfterEvent();
  206.          this.onRunning();
  207.       }
  208.       
  209.       public function setState(param1:String) : void
  210.       {
  211.          this._movie.TAUREAU.gotoAndStop(param1);
  212.       }
  213.       
  214.       public function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
  215.       {
  216.          this._movie.TAUREAU.addEventListener(param1,param2,param3,param4,param5);
  217.       }
  218.       
  219.       public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
  220.       {
  221.          this._movie.TAUREAU.removeEventListener(param1,param2,param3);
  222.       }
  223.       
  224.       public function hitTestPoint(param1:Number, param2:Number, param3:Boolean = false) : Boolean
  225.       {
  226.          return this._movie.hitTestPoint(param1,param2,param3);
  227.       }
  228.       
  229.       public function get x() : Number
  230.       {
  231.          var _loc1_:Point = new Point(this._movie.TAUREAU.x,this._movie.TAUREAU.y);
  232.          _loc1_ = this._movie.localToGlobal(_loc1_);
  233.          _loc1_ = this._movie.parent.globalToLocal(_loc1_);
  234.          return _loc1_.x;
  235.       }
  236.       
  237.       public function set x(param1:Number) : void
  238.       {
  239.          this._movie.TAUREAU.x = param1;
  240.       }
  241.       
  242.       public function get y() : Number
  243.       {
  244.          var _loc1_:Point = new Point(this._movie.TAUREAU.x,this._movie.TAUREAU.y);
  245.          _loc1_ = this._movie.localToGlobal(_loc1_);
  246.          _loc1_ = this._movie.parent.globalToLocal(_loc1_);
  247.          return _loc1_.y;
  248.       }
  249.       
  250.       public function set y(param1:Number) : void
  251.       {
  252.          this._movie.TAUREAU.y = param1;
  253.       }
  254.       
  255.       private function perdu() : void
  256.       {
  257.       }
  258.       
  259.       private function calcul() : void
  260.       {
  261.          this.fps = this._pixelSecondes / this.distancePixelParFrame;
  262.          this._frameDuration = 1000 / this.fps;
  263.       }
  264.       
  265.       public function set speedMetreSecondes(param1:Number) : void
  266.       {
  267.          this._metreSecondes = param1;
  268.          this._pixelSecondes = this._metreSecondes * this.equivalentUnMetreEnPixels;
  269.          this.calcul();
  270.       }
  271.       
  272.       public function set speedPixelSecondes(param1:Number) : void
  273.       {
  274.          this._pixelSecondes = param1;
  275.          this._metreSecondes = this._pixelSecondes / this.equivalentUnMetreEnPixels;
  276.          this.calcul();
  277.       }
  278.       
  279.       public function get acrochageTimePourCent() : Number
  280.       {
  281.          return 100 * this.acrochageTime / this.delaiAcrochage;
  282.       }
  283.       
  284.       public function get frameDuration() : Number
  285.       {
  286.          return this._frameDuration;
  287.       }
  288.       
  289.       public function set frameDuration(param1:Number) : void
  290.       {
  291.          this._frameDuration = param1;
  292.       }
  293.       
  294.       public function set depthIndex(param1:int) : void
  295.       {
  296.          if(this._movie.parent != null)
  297.          {
  298.             this._movie.parent.setChildIndex(this._movie,param1);
  299.          }
  300.       }
  301.       
  302.       public function get depthIndex() : int
  303.       {
  304.          return this._movie.parent != null ? int(this._movie.parent.getChildIndex(this._movie)) : -1;
  305.       }
  306.       
  307.       public function destroy() : void
  308.       {
  309.          if(this._movie.parent != null)
  310.          {
  311.             this._movie.parent.removeChild(this._movie);
  312.          }
  313.       }
  314.    }
  315. }
  316.