home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 150 / MOBICLIC150.ISO / pc / DATA / DSS150 / DSS150_04 / DSS150_04.swf / scripts / dss150_04 / Glace.as < prev    next >
Text File  |  2012-12-19  |  4KB  |  143 lines

  1. package dss150_04
  2. {
  3.    import com.milanpresse.engineaddons.facades.GameEngine;
  4.    import com.milanpresse.engineaddons.gamesprotos.Actor;
  5.    import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.ActorClip;
  6.    import com.milanpresse.engineaddons.timers.TimerChild;
  7.    
  8.    public class Glace extends Actor
  9.    {
  10.        
  11.       
  12.       public var actor:ActorClip;
  13.       
  14.       protected var labels:Array;
  15.       
  16.       private var _position:int = 0;
  17.       
  18.       public var sens:int = 1;
  19.       
  20.       public var directionInitiale:int = 1;
  21.       
  22.       protected var timer:TimerChild;
  23.       
  24.       public var speedMS:Number = 500;
  25.       
  26.       public var hited:Boolean = false;
  27.       
  28.       public var comment12_JEU_NIV3DejaJoue:Boolean = false;
  29.       
  30.       public var alreadyLaunched:Boolean = false;
  31.       
  32.       public var moveFinished:Boolean = true;
  33.       
  34.       public function Glace(game:GameEngine, params:Object = null)
  35.       {
  36.          this.labels = ["G3","G2","G1","CENTRE","D1","D2","D3"];
  37.          super(game,null,params);
  38.          this.actor = addActor({"mc":params.mc});
  39.          this.init();
  40.       }
  41.       
  42.       public static function create(game:GameEngine, params:*) : Glace
  43.       {
  44.          return new Glace(game,params);
  45.       }
  46.       
  47.       protected function init() : void
  48.       {
  49.          this.speedMS = game.moduleConfig.GlaceDuree / 100;
  50.          this.position = 0;
  51.          this.sens = 1;
  52.          this.timer = game.mainTimer.addFromObj({
  53.             "delay":this.speedMS,
  54.             "onDelay":this.onDelay
  55.          });
  56.          this.timer.reset();
  57.          this.refresh();
  58.       }
  59.       
  60.       protected function chooseDirection() : void
  61.       {
  62.          this.directionInitiale = Math.random() > 0.5 ? int(1) : int(-1);
  63.          this.sens = this.directionInitiale;
  64.          if(this.directionInitiale == 1)
  65.          {
  66.             this._position = 1;
  67.          }
  68.          else
  69.          {
  70.             this._position = this.actor.totalFrames;
  71.          }
  72.          this.refresh();
  73.       }
  74.       
  75.       public function launch() : void
  76.       {
  77.          trace("glace.launch");
  78.          this.moveFinished = false;
  79.          this.chooseDirection();
  80.          this.timer.start();
  81.          if(this.comment12_JEU_NIV3DejaJoue == false)
  82.          {
  83.             this.comment12_JEU_NIV3DejaJoue = true;
  84.             game.commentPlay({
  85.                "code":"12_JEU_NIV3",
  86.                "zapBlock":"NOZAP_NOBLOCK"
  87.             });
  88.          }
  89.       }
  90.       
  91.       public function stop() : void
  92.       {
  93.          this.alreadyLaunched = false;
  94.          this.hited = false;
  95.          this.moveFinished = true;
  96.          this.timer.stop();
  97.       }
  98.       
  99.       public function reset() : void
  100.       {
  101.          this.stop();
  102.          this._position = 1;
  103.          this.refresh();
  104.       }
  105.       
  106.       public function onDelay(timer:TimerChild) : void
  107.       {
  108.          trace("glaceOnDelay");
  109.          this.move();
  110.       }
  111.       
  112.       protected function refresh() : void
  113.       {
  114.          this.actor.gotoAndStop(this._position);
  115.       }
  116.       
  117.       protected function move() : void
  118.       {
  119.          trace("move",this.sens,this._position);
  120.          if(this.sens == 1 && this.position == this.actor.totalFrames || this.sens == -1 && this._position == 1)
  121.          {
  122.             this.stop();
  123.          }
  124.          else
  125.          {
  126.             this._position += this.sens;
  127.          }
  128.          this.refresh();
  129.       }
  130.       
  131.       public function get position() : int
  132.       {
  133.          return this._position;
  134.       }
  135.       
  136.       public function set position(value:int) : void
  137.       {
  138.          this._position = value;
  139.          this.refresh();
  140.       }
  141.    }
  142. }
  143.