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

  1. package dss145_07
  2. {
  3.    import com.milanpresse.engine.Engine;
  4.    import com.milanpresse.engine.managers.PauseManager;
  5.    import com.milanpresse.engine.managers.TimelineManager;
  6.    import com.milanpresse.engine.medias.MediaSwf;
  7.    import com.milanpresse.engine.text.TextBloc;
  8.    import com.milanpresse.engine.timelines.Timeline;
  9.    import com.milanpresse.engine.timelines.TimelineLinear;
  10.    import com.milanpresse.engineaddons.facades.EngineExt;
  11.    import com.milanpresse.engineaddons.initdisplayobject.ExtendedClip;
  12.    import com.milanpresse.tools.GlobalesFunctions;
  13.    import com.milanpresse.tools.Stats;
  14.    import flash.display.MovieClip;
  15.    import flash.display.Stage;
  16.    import flash.events.Event;
  17.    import flash.events.MouseEvent;
  18.    import flash.events.TimerEvent;
  19.    import flash.net.SharedObject;
  20.    import flash.utils.Timer;
  21.    import flash.utils.getTimer;
  22.    
  23.    public class CapsuleAlgo
  24.    {
  25.        
  26.       
  27.       private var menu:MediaSwf;
  28.       
  29.       private var menuTimeline:MovieClip;
  30.       
  31.       private var menuTL:Timeline;
  32.       
  33.       private var mainClip:MediaSwf;
  34.       
  35.       private var mainTimeline:MovieClip;
  36.       
  37.       private var _e:EngineExt;
  38.       
  39.       private var _engine:Engine;
  40.       
  41.       private var labelList:Array;
  42.       
  43.       private var _timeline_:TimelineLinear;
  44.       
  45.       private var _timelineManager:TimelineManager;
  46.       
  47.       private var _pauseManager:PauseManager;
  48.       
  49.       private var labelsCallback:Object;
  50.       
  51.       private var firstLabel:String;
  52.       
  53.       private var so:SharedObject;
  54.       
  55.       private var gListDone:Array;
  56.       
  57.       private var gListeObjet:Array;
  58.       
  59.       private var gListeCibles:Array;
  60.       
  61.       private var gListeCurrentCibles:Array;
  62.       
  63.       private var gDoneDepart:Boolean;
  64.       
  65.       private var BT_RETOUR:BtRetour;
  66.       
  67.       private var PANO_AIDE:MovieClip;
  68.       
  69.       public var BARRE_PROGRES:BarreProgres;
  70.       
  71.       public var moduleParams:ModuleConfig;
  72.       
  73.       private var stage:Stage;
  74.       
  75.       private var taureau:Taureau;
  76.       
  77.       private var herakles_eject:MovieClip;
  78.       
  79.       private var herakles_echec:MovieClip;
  80.       
  81.       private var timer:TimerGame;
  82.       
  83.       public var startTime:Number = 0;
  84.       
  85.       public var mainTimer:Timer;
  86.       
  87.       private var _actualTime:Number;
  88.       
  89.       private var _diffTime:Number;
  90.       
  91.       private var _diffUnityTime:Number;
  92.       
  93.       private var _lastTime:Number = 0;
  94.       
  95.       private var accrocheTime:Number = 0;
  96.       
  97.       private var _timeAcrochage:Number = 0;
  98.       
  99.       private var _timeDecrochage:Number = 0;
  100.       
  101.       private var isOn:Boolean = true;
  102.       
  103.       private var ejected:Boolean = false;
  104.       
  105.       public var stats:Stats;
  106.       
  107.       private var taureauRunning:Boolean = false;
  108.       
  109.       private var startRolltime:Number = 0;
  110.       
  111.       private var speedVariator:SpeedVariator;
  112.       
  113.       private var lm_clique:TextBloc;
  114.       
  115.       private var BT_REJOUER:ExtendedClip;
  116.       
  117.       private var firstLaunch:Boolean = true;
  118.       
  119.       private var taureauIsRollOut:Boolean = false;
  120.       
  121.       private var waitClic:Boolean = false;
  122.       
  123.       private var gameIsRunning:Boolean = false;
  124.       
  125.       public function CapsuleAlgo(param1:Engine)
  126.       {
  127.          var engine:Engine = param1;
  128.          this.labelsCallback = {"_11":"prioAnim"};
  129.          this.mainTimer = new Timer(1);
  130.          this.speedVariator = new SpeedVariator();
  131.          super();
  132.          this.initStandardLinear(engine);
  133.          this.moduleParams = new ModuleConfig(this._e.config.XmlConfig.Module.Config.Params);
  134.          this.firstLabel = this.mainTimeline.currentLabels[0].name;
  135.          this._timeline_.GotoAndPlayUntil({"labelStop":this.firstLabel});
  136.          this.so = SharedObject.getLocal(this._engine.config.rubriqueName,"/");
  137.          this.gListDone = this.so.data.listDone;
  138.          if(this.gListDone != null)
  139.          {
  140.             this.gDoneDepart = this.gListDone[this._engine.config.moduleNum - 1] == 1;
  141.          }
  142.          this.BT_RETOUR = new BtRetour(this._engine,this._timelineManager,this.so);
  143.          this.BT_RETOUR.setFunctionHideCursorSpecial(function():void
  144.          {
  145.          });
  146.          this.BT_RETOUR.setFunctionShowCursorSpecial(function():void
  147.          {
  148.          });
  149.       }
  150.       
  151.       public function initStandardLinear(param1:Engine) : void
  152.       {
  153.          this._engine = param1;
  154.          this._timelineManager = new TimelineManager();
  155.          this._e = new EngineExt(this._engine,this._timelineManager);
  156.          this._engine.logsTrace();
  157.          this._engine.playMusic({"code":"MU"});
  158.          this._engine.setSubtitles(this._engine.host.subtitlesOn);
  159.          this._engine.setFrameRate(12);
  160.          this._engine.levelCZ = this._engine.config.layers["content"];
  161.          this.mainClip = this._engine.showSwf({
  162.             "code":"A_" + this._engine.config.moduleName,
  163.             "parent":this._engine.config.layers["content"]
  164.          });
  165.          this.mainTimeline = this.mainClip.swfContent;
  166.          this.stage = this._engine.config.scene.stage;
  167.          this._timeline_ = new TimelineLinear(this.mainTimeline,this._engine,this,this._timelineManager,this.labelsCallback);
  168.          this.firstLabel = this.mainTimeline.currentLabels[0].name;
  169.       }
  170.       
  171.       public function labelATTENTE_JEU() : void
  172.       {
  173.          this.speedVariator.generate();
  174.          this.mainTimer.addEventListener(TimerEvent.TIMER,this.gameLoop);
  175.          this.herakles_echec = this.mainTimeline.HERAKLES_ECHEC;
  176.          this.herakles_echec.gotoAndStop(1);
  177.          this.herakles_echec.visible = false;
  178.          this.herakles_eject = this.mainTimeline.HERAKLES_EJECT;
  179.          this.herakles_eject.gotoAndStop(1);
  180.          this.herakles_eject.visible = false;
  181.          this.taureau = new Taureau(this.mainTimeline.TAUREAU);
  182.          this.taureau.speedPixelSecondes = this.speedVariator.speed;
  183.          this.taureau.distanceSeuilPx = this.moduleParams.distanceSeuilPx;
  184.          this.taureau.delaiDecrochage = this.moduleParams.delaiDecrochage * 1000;
  185.          this.timer = new TimerGame(this.mainTimeline.TIMER);
  186.          this.timer.setState("E1");
  187.          this.timer.refresh(0);
  188.          this.BARRE_PROGRES = new BarreProgres(this.mainTimeline.BARRE_PROGRES);
  189.          this.taureau.setState("E0");
  190.          this._timelineManager.addMovie(this.mainTimeline.TAUREAU);
  191.          this._timelineManager.addMovie(this.mainTimeline.TAUREAU.TAUREAU);
  192.          this._timelineManager.addMovie(this.mainTimeline.TIMER);
  193.          this._timelineManager.addMovie(this.mainTimeline.TIMER.TIMER_BAR);
  194.          this._timelineManager.addMovie(this.mainTimeline.BARRE_PROGRES);
  195.          var i:int = 1;
  196.          while(i <= 6)
  197.          {
  198.             this._timelineManager.addMovie(this.mainTimeline.BARRE_PROGRES.getChildByName("TETE_0" + i) as MovieClip);
  199.             i++;
  200.          }
  201.          this.BT_REJOUER = new ExtendedClip(this.mainTimeline.BT_REJOUER,this._e);
  202.          this.BT_REJOUER.onPressState = {"label":"E1"};
  203.          this.BT_REJOUER.onRollOverState = {
  204.             "label":"E2",
  205.             "noiseCode":"B_REJ"
  206.          };
  207.          this.BT_REJOUER.onRollOutState = {"label":"E1"};
  208.          this.BT_REJOUER.onPress = function():void
  209.          {
  210.             var _loc1_:FadeOut = new FadeOut(_e.config.scene,restart);
  211.             _loc1_.start();
  212.             reset();
  213.          };
  214.          this.BT_REJOUER.enabled = true;
  215.          this.BT_REJOUER.visible = false;
  216.          this.BT_REJOUER.init();
  217.          this.lm_clique = this._e.textShow({
  218.             "id":"LM_CLIQUE",
  219.             "parent":this.mainTimeline
  220.          });
  221.          this.lm_clique.visible = false;
  222.          this.waitRollOnTaureau();
  223.       }
  224.       
  225.       public function reset() : void
  226.       {
  227.          this.speedVariator.generate();
  228.          this.herakles_echec.gotoAndStop(1);
  229.          this.herakles_echec.visible = false;
  230.          this.herakles_eject.gotoAndStop(1);
  231.          this.herakles_eject.visible = false;
  232.          this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  233.          this.taureau.speedPixelSecondes = this.speedVariator.speed;
  234.          this.taureau.distanceSeuilPx = this.moduleParams.distanceSeuilPx;
  235.          this.taureau.delaiDecrochage = this.moduleParams.delaiDecrochage * 1000;
  236.          this.timer.setState("E1");
  237.          this.timer.refresh(0);
  238.          this.taureau.reset();
  239.          this.BT_REJOUER.visible = false;
  240.          this.waitClic = false;
  241.          this.firstLaunch = true;
  242.       }
  243.       
  244.       public function restart() : void
  245.       {
  246.          this.waitRollOnTaureau();
  247.       }
  248.       
  249.       public function waitRollOnTaureau() : void
  250.       {
  251.          this.startRolltime = getTimer();
  252.          this.stage.addEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
  253.       }
  254.       
  255.       private function taureauEnterFrameHandler(param1:Event) : void
  256.       {
  257.          if(this.taureau.hitTestPoint(this.stage.mouseX,this.stage.mouseY,true))
  258.          {
  259.             if(getTimer() - this.startRolltime >= this.moduleParams.delaiToLaunchGame)
  260.             {
  261.                this.stage.removeEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
  262.                this.ejected = false;
  263.                this.taureauRunning = true;
  264.                this.taureauIsRollOut = false;
  265.                this.taureau.setState("E1");
  266.                this.isOn = true;
  267.                this.herakles_echec.visible = false;
  268.                this.herakles_echec.gotoAndStop(1);
  269.                this.speedVariator.generate();
  270.                if(this.firstLaunch)
  271.                {
  272.                   this.firstLaunch = false;
  273.                   this.startTime = getTimer();
  274.                }
  275.                this._lastTime = this._timeAcrochage = this._timeDecrochage = getTimer();
  276.                this.mainTimer.start();
  277.                this._e.noisePlay({
  278.                   "code":"B_TAUREAU",
  279.                   "loops":999999999
  280.                });
  281.             }
  282.          }
  283.          else
  284.          {
  285.             this.startRolltime = getTimer();
  286.          }
  287.       }
  288.       
  289.       private function gameLoop(param1:TimerEvent) : void
  290.       {
  291.          this._actualTime = getTimer();
  292.          this._diffTime = this._actualTime - this.startTime;
  293.          this.timer.refresh(100 * this._diffTime / this.moduleParams.timerTimeMax);
  294.          if(this._diffTime >= this.moduleParams.timerTimeMax)
  295.          {
  296.             this.failTimeFinished();
  297.             return;
  298.          }
  299.          if(this._actualTime - this._lastTime >= this.taureau.frameDuration)
  300.          {
  301.             this._lastTime = this._actualTime;
  302.             if(this.taureauRunning)
  303.             {
  304.                this.taureau.move();
  305.             }
  306.          }
  307.          if(this.isOn)
  308.          {
  309.             this.accrocheTime = this._actualTime - this._timeAcrochage;
  310.             this.speedVariator.refresh(this.accrocheTime);
  311.             this.taureau.speedPixelSecondes = this.speedVariator.speed;
  312.             if(this.accrocheTime > this.moduleParams.delaiAcrochage)
  313.             {
  314.                this.lm_clique.x = this.taureau.x - this.lm_clique.width / 2;
  315.                this.lm_clique.y = this.taureau.y - 60;
  316.                this.BARRE_PROGRES.refresh(100);
  317.                if(this.waitClic == false)
  318.                {
  319.                   this.waitClic = true;
  320.                   this.lm_clique.visible = true;
  321.                   this._e.noisePlay({"code":"B_CORNES"});
  322.                   this.taureau.addEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  323.                }
  324.                if(this.accrocheTime - this.moduleParams.delaiAcrochage >= this.moduleParams.delayToClic)
  325.                {
  326.                   this.pickFail();
  327.                }
  328.                else
  329.                {
  330.                   this.taureau.setState("E2");
  331.                }
  332.             }
  333.             else
  334.             {
  335.                this.BARRE_PROGRES.refresh(100 * this.accrocheTime / this.moduleParams.delaiAcrochage);
  336.             }
  337.             if(this.taureau.hitTestPoint(this.stage.mouseX,this.stage.mouseY,true))
  338.             {
  339.                if(this.taureauIsRollOut == true)
  340.                {
  341.                   this.taureauIsRollOut = false;
  342.                }
  343.             }
  344.             else
  345.             {
  346.                if(this.taureauIsRollOut == false)
  347.                {
  348.                   this.taureauIsRollOut = true;
  349.                   this.taureau.setState("E1");
  350.                   this._timeDecrochage = getTimer();
  351.                }
  352.                if(this._actualTime - this._timeDecrochage > this.moduleParams.delaiDecrochage)
  353.                {
  354.                   this.eject();
  355.                }
  356.             }
  357.             param1.updateAfterEvent();
  358.          }
  359.       }
  360.       
  361.       private function failTimeFinished() : void
  362.       {
  363.          this.mainTimer.stop();
  364.          this._e.noiseStop({"code":"B_TAUREAU"});
  365.          this.lm_clique.visible = false;
  366.          this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  367.          this.stage.removeEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
  368.          this.waitClic = false;
  369.          this.timer.setState("E2");
  370.          if(this.ejected == false)
  371.          {
  372.             this.taureau.setState("E3");
  373.             this.herakles_eject.x = this.taureau.x;
  374.             this.herakles_eject.y = this.taureau.y;
  375.             this.herakles_eject.gotoAndPlay(1);
  376.             this.herakles_eject.visible = true;
  377.             this._e.noisePlay({
  378.                "code":"B_EJECT",
  379.                "callback":function():void
  380.                {
  381.                   herakles_echec.x = taureau.x;
  382.                   herakles_echec.y = taureau.y;
  383.                   herakles_echec.gotoAndPlay(1);
  384.                   herakles_eject.visible = false;
  385.                   herakles_eject.gotoAndStop(1);
  386.                   herakles_echec.visible = true;
  387.                   BARRE_PROGRES.refresh(0);
  388.                   _e.noisePlay({
  389.                      "code":"B_ECHEC",
  390.                      "callback":function():void
  391.                      {
  392.                         taureau.setState("E4");
  393.                         taureau.depthIndex = mainTimeline.numChildren - 1;
  394.                         _e.commentPlay({
  395.                            "code":"PERDU",
  396.                            "callback":function():void
  397.                            {
  398.                               BT_REJOUER.visible = true;
  399.                            }
  400.                         });
  401.                      }
  402.                   });
  403.                }
  404.             });
  405.          }
  406.          else
  407.          {
  408.             this._e.commentPlay({
  409.                "code":"PERDU",
  410.                "callback":function():void
  411.                {
  412.                   BT_REJOUER.visible = true;
  413.                }
  414.             });
  415.          }
  416.       }
  417.       
  418.       private function pickFail() : void
  419.       {
  420.          this.mainTimer.stop();
  421.          this.lm_clique.visible = false;
  422.          this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  423.          this.waitClic = false;
  424.          this.taureauRunning = false;
  425.          this.taureau.setState("E1");
  426.          this._e.commentPlay({
  427.             "code":"AGAIN",
  428.             "zapBlock":"NOZAP_NOBLOCK",
  429.             "callback":function():void
  430.             {
  431.                speedVariator.generate();
  432.                startTime = getTimer() - (_actualTime - startTime);
  433.                _timeAcrochage = getTimer() - moduleParams.delaiAcrochage / 2;
  434.                mainTimer.start();
  435.                taureauRunning = true;
  436.             }
  437.          });
  438.       }
  439.       
  440.       private function eject() : void
  441.       {
  442.          this.lm_clique.visible = false;
  443.          this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  444.          this.waitClic = false;
  445.          this.taureauRunning = false;
  446.          this.isOn = false;
  447.          this.ejected = true;
  448.          this.taureau.setState("E3");
  449.          this.herakles_eject.x = this.taureau.x;
  450.          this.herakles_eject.y = this.taureau.y;
  451.          this.herakles_eject.gotoAndPlay(1);
  452.          this.herakles_eject.visible = true;
  453.          this.herakles_eject.parent.setChildIndex(this.herakles_eject,this.taureau.depthIndex);
  454.          this._e.noisePlay({
  455.             "code":"B_EJECT",
  456.             "callback":function():void
  457.             {
  458.                herakles_echec.x = taureau.x;
  459.                herakles_echec.y = taureau.y;
  460.                herakles_echec.gotoAndPlay(1);
  461.                herakles_eject.visible = false;
  462.                herakles_eject.gotoAndStop(1);
  463.                herakles_echec.visible = true;
  464.                herakles_echec.parent.setChildIndex(herakles_echec,taureau.depthIndex - 1);
  465.                BARRE_PROGRES.refresh(0);
  466.                _e.noisePlay({
  467.                   "code":"B_ECHEC",
  468.                   "callback":function():void
  469.                   {
  470.                      taureau.setState("E4");
  471.                      taureau.speedPixelSecondes = 300;
  472.                      taureauRunning = true;
  473.                      waitRollOnTaureau();
  474.                   }
  475.                });
  476.             }
  477.          });
  478.       }
  479.       
  480.       private function taureauMouseDownHandler(param1:MouseEvent) : void
  481.       {
  482.          this.mainTimer.stop();
  483.          this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  484.          this.GameSucces();
  485.       }
  486.       
  487.       private function GameSucces() : void
  488.       {
  489.          this.save();
  490.          this.lm_clique.visible = false;
  491.          this._e.noiseStop({"code":"B_TAUREAU"});
  492.          this.taureau.setState("E5");
  493.          this._e.noisePlay({"code":"B_SUCCES"});
  494.          this._e.commentPlay({
  495.             "code":"BRAVO",
  496.             "zapBlock":"NOZAP_NOBLOCK",
  497.             "callback":this.GameSucces2
  498.          });
  499.       }
  500.       
  501.       private function GameSucces2() : void
  502.       {
  503.          this.taureau.destroy();
  504.          this._timeline_.GotoAndPlayUntil({"labelStop":"_10"});
  505.       }
  506.       
  507.       public function G2D(param1:int) : String
  508.       {
  509.          return GlobalesFunctions.gimme2digits(param1);
  510.       }
  511.       
  512.       public function save() : void
  513.       {
  514.          this.BT_RETOUR._gameWon = true;
  515.          if(this.gListDone != null)
  516.          {
  517.             this.gListDone[this._engine.config.moduleNum - 1] = 1;
  518.             if(this.gDoneDepart)
  519.             {
  520.                this.so.data.lastDone = 2;
  521.             }
  522.             else
  523.             {
  524.                this.so.data.lastDone = 1;
  525.             }
  526.             this.so.data.listDone = this.gListDone;
  527.             this.so.flush();
  528.          }
  529.       }
  530.       
  531.       public function endMODULE() : void
  532.       {
  533.          this._engine.host.changeModule({"numMod":0});
  534.       }
  535.       
  536.       public function sleep() : void
  537.       {
  538.          if(this.mainTimer.running)
  539.          {
  540.             this._e.noiseStop({"code":"B_TAUREAU"});
  541.             this.gameIsRunning = true;
  542.             this.mainTimer.stop();
  543.          }
  544.          this._pauseManager = new PauseManager(this._engine,this._timelineManager);
  545.          this._pauseManager.sleepMovie(this.mainTimeline);
  546.       }
  547.       
  548.       public function wake() : void
  549.       {
  550.          this._pauseManager.wakeMovie(this.mainTimeline);
  551.          if(this.gameIsRunning)
  552.          {
  553.             this.startTime = getTimer() - (this._actualTime - this.startTime);
  554.             this._timeAcrochage = getTimer() - this.moduleParams.delaiAcrochage / 2;
  555.             this.mainTimer.start();
  556.             this._e.noisePlay({
  557.                "code":"B_TAUREAU",
  558.                "loops":999999999
  559.             });
  560.             this.gameIsRunning = false;
  561.          }
  562.       }
  563.       
  564.       public function destroy() : void
  565.       {
  566.          this._engine.stopAllSounds();
  567.          this._timeline_.kilListeners();
  568.          if(this.taureau != null)
  569.          {
  570.             this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
  571.          }
  572.          this.mainTimeline.stage.removeEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
  573.       }
  574.    }
  575. }
  576.