home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 150 / MOBICLIC150.ISO / pc / DATA / DSS150 / DSS150_04 / DSS150_04.swf / scripts / dss150_04 / ATTENTE.as next >
Text File  |  2012-12-19  |  14KB  |  460 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.*;
  6.    import com.milanpresse.engineaddons.timers.TimerChild;
  7.    import flash.display.MovieClip;
  8.    import flash.ui.Mouse;
  9.    
  10.    public class ATTENTE
  11.    {
  12.        
  13.       
  14.       private var game:GameEngine;
  15.       
  16.       public var onEvent:Function = null;
  17.       
  18.       private var _container:IActorClip;
  19.       
  20.       private var attente:Actor;
  21.       
  22.       private var timerIsOn:ActorTimer;
  23.       
  24.       private var timerRelance:ActorTimer;
  25.       
  26.       private var akiak:ActorClip;
  27.       
  28.       private var corde:Corde;
  29.       
  30.       private var glace:Glace;
  31.       
  32.       private var glaceTimer:TimerChild;
  33.       
  34.       private var copines:Vector.<ActorClip>;
  35.       
  36.       private var flecheG:ActorClip;
  37.       
  38.       private var flecheD:ActorClip;
  39.       
  40.       private var mainLoop:TimerChild;
  41.       
  42.       private var levelTimer:TimerChild;
  43.       
  44.       private var akiakTimer:TimerChild;
  45.       
  46.       private var keyDetecter:KeyDetecter;
  47.       
  48.       protected var level:int = 0;
  49.       
  50.       protected var waitKeyUp:Boolean = false;
  51.       
  52.       protected var waitKeyRight:Boolean = false;
  53.       
  54.       protected var waitKeyLeft:Boolean = false;
  55.       
  56.       protected var glaceTimerAlreadyLaunched:Boolean = false;
  57.       
  58.       protected var levelLast:int = -1;
  59.       
  60.       private var _mouseVisible:Boolean = true;
  61.       
  62.       protected var isSleeping:Boolean = false;
  63.       
  64.       protected var sleepState:Object;
  65.       
  66.       public function ATTENTE(game:GameEngine, container:IActorClip)
  67.       {
  68.          this.copines = new Vector.<ActorClip>();
  69.          this.sleepState = {"mouseVisible":true};
  70.          super();
  71.          this.game = game;
  72.          this._container = container;
  73.          this.init();
  74.          this.startNewGame();
  75.       }
  76.       
  77.       public function init() : void
  78.       {
  79.          var clip:ActorClip = null;
  80.          this.attente = this.game.addActor(new Actor(this.game));
  81.          this.attente.name = "ATTENTE";
  82.          this.akiakInit();
  83.          this.corde = this.attente.addActor({
  84.             "type":Corde,
  85.             "mc":this._container.getChildByName("JEU.CORDE") as MovieClip
  86.          }) as Corde;
  87.          this.glace = this.attente.addActor({
  88.             "type":Glace,
  89.             "mc":this._container.getChildByName("JEU.GLACE") as MovieClip
  90.          }) as Glace;
  91.          this.glaceTimer = this.game.mainTimer.addFromObj({
  92.             "delay":2000 + Math.floor(Math.random() * 2000),
  93.             "loop":1,
  94.             "onDelay":this.glaceTimerFunc
  95.          });
  96.          this.glaceTimer.reset();
  97.          for(var i:int = 1; i <= 2; i++)
  98.          {
  99.             clip = this.attente.addActor({"mc":this._container.getChildByName("JEU.COPINE_0" + i) as MovieClip});
  100.             this.copines.push(clip);
  101.          }
  102.          this.flecheG = clip = this.attente.addActor({"mc":this._container.getChildByName("JEU.FLECHE_G") as MovieClip});
  103.          this.flecheD = clip = this.attente.addActor({"mc":this._container.getChildByName("JEU.FLECHE_D") as MovieClip});
  104.          this.keyDetecter = this.attente.addActor({
  105.             "type":KeyDetecter,
  106.             "stage":this.game.stage
  107.          }) as KeyDetecter;
  108.          this.levelTimer = this.game.mainTimer.addFromObj({
  109.             "delay":this.game.moduleConfig.levelDuration,
  110.             "loop":1,
  111.             "onDelay":this.levelTimerFunc
  112.          });
  113.          this.levelTimer.reset();
  114.          this.mainLoop = this.game.mainTimer.addFromObj({
  115.             "delay":20,
  116.             "onDelay":this.mainLoopFunc
  117.          });
  118.       }
  119.       
  120.       public function levelTimerFunc(timer:TimerChild) : void
  121.       {
  122.          trace("levelTimerFunc");
  123.          ++this.level;
  124.          if(this.level > 3)
  125.          {
  126.             this.succes();
  127.          }
  128.          else
  129.          {
  130.             trace("LEVEL",this.level);
  131.             this.levelTimer = this.game.mainTimer.addFromObj({
  132.                "delay":this.game.moduleConfig.levelDuration,
  133.                "loop":1,
  134.                "onDelay":this.levelTimerFunc
  135.             });
  136.          }
  137.       }
  138.       
  139.       public function startNewGame() : void
  140.       {
  141.          this.akiak.vars.hitCorde = this.game.moduleConfig.numCordeHitToLose;
  142.          this.corde.speedAlea = false;
  143.          this.levelLast = -1;
  144.          this.level = 1;
  145.          this.corde.speedMS = this.game.moduleConfig.CordeSautVitesse;
  146.          this.glace.comment12_JEU_NIV3DejaJoue = false;
  147.          this.continueGame();
  148.       }
  149.       
  150.       public function continueGame() : void
  151.       {
  152.          trace("level",this.level);
  153.          this._container.getChildByName("ECHEC").visible = false;
  154.          this._container.getChildByName("JEU").visible = true;
  155.          this.flecheD.visible = false;
  156.          this.flecheG.visible = false;
  157.          this.keyDetecter.actionReset();
  158.          this.waitKeyRight = false;
  159.          this.waitKeyLeft = false;
  160.          this.waitKeyUp = false;
  161.          this.akiak.vars.failType = "";
  162.          this.akiakReset();
  163.          this.akiak.gotoAndStop("E1");
  164.          this.corde.position = 1;
  165.          this.corde.sens = 1;
  166.          this.glace.reset();
  167.          this.glace.hited = false;
  168.          this.copines[0].gotoAndStop("E2");
  169.          this.copines[1].gotoAndStop("E2");
  170.          this.levelTimer.reset();
  171.          this.levelTimer.start();
  172.          this.corde.launch();
  173.          this.glace.alreadyLaunched = false;
  174.          this.glaceTimer.reset();
  175.          this.keyDetecter.enabled = true;
  176.          this.game.mainTimer.start();
  177.       }
  178.       
  179.       public function stop() : void
  180.       {
  181.          this.game.mainTimer.stop();
  182.          this.corde.stop();
  183.          this.keyDetecter.enabled = false;
  184.       }
  185.       
  186.       public function glaceTimerFunc(timer:TimerChild) : void
  187.       {
  188.          trace("glaceTimerFunc");
  189.          this.glace.launch();
  190.          if(this.glace.directionInitiale == 1)
  191.          {
  192.             this.flecheD.visible = true;
  193.             this.flecheG.visible = false;
  194.          }
  195.          else
  196.          {
  197.             this.flecheD.visible = false;
  198.             this.flecheG.visible = true;
  199.          }
  200.       }
  201.       
  202.       public function mainLoopFunc(timer:TimerChild) : void
  203.       {
  204.          if(this.akiakTestCollision())
  205.          {
  206.             this.fail();
  207.             return;
  208.          }
  209.          if(this.level != this.levelLast)
  210.          {
  211.             this.levelLast = this.level;
  212.             if(this.level == 2)
  213.             {
  214.             }
  215.          }
  216.          if(this.level == 3 && this.glace.alreadyLaunched == false)
  217.          {
  218.             this.glace.alreadyLaunched = true;
  219.             this.glaceTimer.start();
  220.          }
  221.          if(this.waitKeyUp == false && this.keyDetecter.actions.up)
  222.          {
  223.             trace("up");
  224.             this.waitKeyUp = true;
  225.             this.akiakJump();
  226.          }
  227.          else if(this.keyDetecter.actions.up == false)
  228.          {
  229.             trace("up false");
  230.             this.waitKeyUp = false;
  231.          }
  232.          trace(this.waitKeyRight,this.keyDetecter.actions.right,this.glace.directionInitiale,this.glace.hited);
  233.          if(this.waitKeyRight == false && this.keyDetecter.actions.right && this.glace.directionInitiale == 1 && this.glace.hited == false)
  234.          {
  235.             this.flecheG.visible = false;
  236.             this.flecheD.visible = false;
  237.             this.glace.hited = true;
  238.             this.waitKeyRight = true;
  239.             this.glace.sens = -1;
  240.          }
  241.          else if(this.keyDetecter.actions.right == false)
  242.          {
  243.             trace("right false");
  244.             this.waitKeyRight = false;
  245.          }
  246.          if(this.waitKeyLeft == false && this.keyDetecter.actions.left && this.glace.directionInitiale == -1 && this.glace.hited == false)
  247.          {
  248.             this.flecheG.visible = false;
  249.             this.flecheD.visible = false;
  250.             this.glace.hited = true;
  251.             this.waitKeyLeft = true;
  252.             this.glace.sens = 1;
  253.          }
  254.          else if(this.keyDetecter.actions.left == false)
  255.          {
  256.             trace("right false");
  257.             this.waitKeyLeft = false;
  258.          }
  259.          this.akiakTimer.delay = this.corde.speedMS / 3;
  260.       }
  261.       
  262.       protected function akiakInit() : void
  263.       {
  264.          if(this.akiak == null)
  265.          {
  266.             this.akiak = this.attente.addActor({"mc":this._container.getChildByName("JEU.AKIAK") as MovieClip});
  267.             this.akiak.vars.nbtoursMax = Math.floor(this.game.moduleConfig.AkiakSautFinDuree / this.game.moduleConfig.AkiakSautVitesse);
  268.             this.akiakTimer = this.game.mainTimer.addFromObj({
  269.                "delay":this.game.moduleConfig.AkiakSautVitesse,
  270.                "onDelay":this.akiakOnDelay
  271.             });
  272.          }
  273.          this.akiakReset();
  274.       }
  275.       
  276.       protected function akiakReset() : void
  277.       {
  278.          this.akiak.vars.jumping = false;
  279.          this.akiak.vars.vulnerable = true;
  280.          this.akiak.vars.nbtours = this.akiak.vars.nbtoursMax;
  281.          this.akiakTimer.reset();
  282.       }
  283.       
  284.       protected function akiakOnDelay(timer:TimerChild) : void
  285.       {
  286.          if(this.akiak.vars.jumping)
  287.          {
  288.             if(this.akiak.currentLabel == "FIN_SAUT")
  289.             {
  290.                this.akiak.vars.vulnerable = true;
  291.                --this.akiak.vars.nbtours;
  292.                if(this.akiak.vars.nbtours < 0)
  293.                {
  294.                   this.akiakTimer.reset();
  295.                   this.akiak.vars.jumping = false;
  296.                   this.akiak.vars.nbtours = this.akiak.vars.nbtoursMax;
  297.                }
  298.             }
  299.             else
  300.             {
  301.                this.akiak.gotoAndStop(this.akiak.currentFrame + 1);
  302.             }
  303.          }
  304.       }
  305.       
  306.       protected function akiakJump() : void
  307.       {
  308.          trace("akiakJump",this.akiak.vars.jumping);
  309.          if(this.akiak.vars.jumping == false)
  310.          {
  311.             this.akiak.gotoAndStop("E2",{"labelLastCallback":function():void
  312.             {
  313.                game.noisePlay({"code":"B_SAUT"});
  314.                akiakTimer.start();
  315.                akiak.vars.jumping = true;
  316.                akiak.vars.vulnerable = false;
  317.             }});
  318.          }
  319.       }
  320.       
  321.       protected function akiakTestCollision() : Boolean
  322.       {
  323.          if(this.akiak.vars.vulnerable && this.corde.position == 0)
  324.          {
  325.             this.akiak.vars.failType = "corde";
  326.             return true;
  327.          }
  328.          if(this.glace.actor.currentFrame > 35 && this.glace.actor.currentFrame < 55)
  329.          {
  330.             this.akiak.vars.failType = "glace";
  331.             this.glace.hited = true;
  332.             return true;
  333.          }
  334.          return false;
  335.       }
  336.       
  337.       protected function fail() : void
  338.       {
  339.          this.stop();
  340.          if(this.akiak.vars.failType == "corde")
  341.          {
  342.             this.akiak.gotoAndStop("E3");
  343.             --this.akiak.vars.hitCorde;
  344.             trace("akiak.vars.hitCorde",this.akiak.vars.hitCorde);
  345.             this.game.noisePlay({
  346.                "code":"B_PERD",
  347.                "callback":function():void
  348.                {
  349.                   akiak.gotoAndStop("E1");
  350.                   if(akiak.vars.hitCorde > 0)
  351.                   {
  352.                      continueGame();
  353.                   }
  354.                   else
  355.                   {
  356.                      echec2();
  357.                   }
  358.                }
  359.             });
  360.          }
  361.          else if(this.akiak.vars.failType == "glace")
  362.          {
  363.             this.akiak.gotoAndStop("E4");
  364.             --this.akiak.vars.hitCorde;
  365.             trace("akiak.vars.hitCorde",this.akiak.vars.hitCorde);
  366.             this.game.noisePlay({"code":"B_GLACE"});
  367.             this.akiak.onLabelEnter = function(result:*):void
  368.             {
  369.                if(akiak.currentLabel == "FIN_E4")
  370.                {
  371.                   akiak.stop();
  372.                   echec2();
  373.                }
  374.             };
  375.             this.akiak.play("E4");
  376.          }
  377.       }
  378.       
  379.       protected function echec2() : void
  380.       {
  381.          this._container.getChildByName("ECHEC").visible = true;
  382.          this._container.getChildByName("JEU").visible = false;
  383.          this.game.commentPlay({
  384.             "code":"12_JEU_E",
  385.             "callback":function():void
  386.             {
  387.                startNewGame();
  388.             }
  389.          });
  390.       }
  391.       
  392.       protected function succes() : void
  393.       {
  394.          this.finish();
  395.       }
  396.       
  397.       public function get mouseVisible() : Boolean
  398.       {
  399.          return this._mouseVisible;
  400.       }
  401.       
  402.       public function set mouseVisible(value:Boolean) : void
  403.       {
  404.          if(value == true)
  405.          {
  406.             Mouse.show();
  407.          }
  408.          else
  409.          {
  410.             Mouse.hide();
  411.          }
  412.          this._mouseVisible = value;
  413.       }
  414.       
  415.       private function finish() : void
  416.       {
  417.          trace("finish");
  418.          this.game.memo.module.succes = true;
  419.          this.game.memo.save();
  420.          this.destroy();
  421.          if(this.onEvent != null)
  422.          {
  423.             this.onEvent({"action":"succes"});
  424.          }
  425.       }
  426.       
  427.       public function sleep() : void
  428.       {
  429.          if(this.isSleeping)
  430.          {
  431.             return;
  432.          }
  433.          this.isSleeping = true;
  434.          this.sleepState.mouseVisible = this._mouseVisible;
  435.          this.mouseVisible = true;
  436.       }
  437.       
  438.       public function wake() : void
  439.       {
  440.          if(this.isSleeping == false)
  441.          {
  442.             return;
  443.          }
  444.          this.isSleeping = false;
  445.          this.mouseVisible = this.sleepState.mouseVisible;
  446.       }
  447.       
  448.       public function destroy() : void
  449.       {
  450.          this.stop();
  451.          if(this.attente != null)
  452.          {
  453.             this.attente.dissociate();
  454.             this.attente.destroy();
  455.          }
  456.          this.attente = null;
  457.       }
  458.    }
  459. }
  460.