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 >
Wrap
Text File
|
2012-07-18
|
21KB
|
576 lines
package dss145_07
{
import com.milanpresse.engine.Engine;
import com.milanpresse.engine.managers.PauseManager;
import com.milanpresse.engine.managers.TimelineManager;
import com.milanpresse.engine.medias.MediaSwf;
import com.milanpresse.engine.text.TextBloc;
import com.milanpresse.engine.timelines.Timeline;
import com.milanpresse.engine.timelines.TimelineLinear;
import com.milanpresse.engineaddons.facades.EngineExt;
import com.milanpresse.engineaddons.initdisplayobject.ExtendedClip;
import com.milanpresse.tools.GlobalesFunctions;
import com.milanpresse.tools.Stats;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.net.SharedObject;
import flash.utils.Timer;
import flash.utils.getTimer;
public class CapsuleAlgo
{
private var menu:MediaSwf;
private var menuTimeline:MovieClip;
private var menuTL:Timeline;
private var mainClip:MediaSwf;
private var mainTimeline:MovieClip;
private var _e:EngineExt;
private var _engine:Engine;
private var labelList:Array;
private var _timeline_:TimelineLinear;
private var _timelineManager:TimelineManager;
private var _pauseManager:PauseManager;
private var labelsCallback:Object;
private var firstLabel:String;
private var so:SharedObject;
private var gListDone:Array;
private var gListeObjet:Array;
private var gListeCibles:Array;
private var gListeCurrentCibles:Array;
private var gDoneDepart:Boolean;
private var BT_RETOUR:BtRetour;
private var PANO_AIDE:MovieClip;
public var BARRE_PROGRES:BarreProgres;
public var moduleParams:ModuleConfig;
private var stage:Stage;
private var taureau:Taureau;
private var herakles_eject:MovieClip;
private var herakles_echec:MovieClip;
private var timer:TimerGame;
public var startTime:Number = 0;
public var mainTimer:Timer;
private var _actualTime:Number;
private var _diffTime:Number;
private var _diffUnityTime:Number;
private var _lastTime:Number = 0;
private var accrocheTime:Number = 0;
private var _timeAcrochage:Number = 0;
private var _timeDecrochage:Number = 0;
private var isOn:Boolean = true;
private var ejected:Boolean = false;
public var stats:Stats;
private var taureauRunning:Boolean = false;
private var startRolltime:Number = 0;
private var speedVariator:SpeedVariator;
private var lm_clique:TextBloc;
private var BT_REJOUER:ExtendedClip;
private var firstLaunch:Boolean = true;
private var taureauIsRollOut:Boolean = false;
private var waitClic:Boolean = false;
private var gameIsRunning:Boolean = false;
public function CapsuleAlgo(param1:Engine)
{
var engine:Engine = param1;
this.labelsCallback = {"_11":"prioAnim"};
this.mainTimer = new Timer(1);
this.speedVariator = new SpeedVariator();
super();
this.initStandardLinear(engine);
this.moduleParams = new ModuleConfig(this._e.config.XmlConfig.Module.Config.Params);
this.firstLabel = this.mainTimeline.currentLabels[0].name;
this._timeline_.GotoAndPlayUntil({"labelStop":this.firstLabel});
this.so = SharedObject.getLocal(this._engine.config.rubriqueName,"/");
this.gListDone = this.so.data.listDone;
if(this.gListDone != null)
{
this.gDoneDepart = this.gListDone[this._engine.config.moduleNum - 1] == 1;
}
this.BT_RETOUR = new BtRetour(this._engine,this._timelineManager,this.so);
this.BT_RETOUR.setFunctionHideCursorSpecial(function():void
{
});
this.BT_RETOUR.setFunctionShowCursorSpecial(function():void
{
});
}
public function initStandardLinear(param1:Engine) : void
{
this._engine = param1;
this._timelineManager = new TimelineManager();
this._e = new EngineExt(this._engine,this._timelineManager);
this._engine.logsTrace();
this._engine.playMusic({"code":"MU"});
this._engine.setSubtitles(this._engine.host.subtitlesOn);
this._engine.setFrameRate(12);
this._engine.levelCZ = this._engine.config.layers["content"];
this.mainClip = this._engine.showSwf({
"code":"A_" + this._engine.config.moduleName,
"parent":this._engine.config.layers["content"]
});
this.mainTimeline = this.mainClip.swfContent;
this.stage = this._engine.config.scene.stage;
this._timeline_ = new TimelineLinear(this.mainTimeline,this._engine,this,this._timelineManager,this.labelsCallback);
this.firstLabel = this.mainTimeline.currentLabels[0].name;
}
public function labelATTENTE_JEU() : void
{
this.speedVariator.generate();
this.mainTimer.addEventListener(TimerEvent.TIMER,this.gameLoop);
this.herakles_echec = this.mainTimeline.HERAKLES_ECHEC;
this.herakles_echec.gotoAndStop(1);
this.herakles_echec.visible = false;
this.herakles_eject = this.mainTimeline.HERAKLES_EJECT;
this.herakles_eject.gotoAndStop(1);
this.herakles_eject.visible = false;
this.taureau = new Taureau(this.mainTimeline.TAUREAU);
this.taureau.speedPixelSecondes = this.speedVariator.speed;
this.taureau.distanceSeuilPx = this.moduleParams.distanceSeuilPx;
this.taureau.delaiDecrochage = this.moduleParams.delaiDecrochage * 1000;
this.timer = new TimerGame(this.mainTimeline.TIMER);
this.timer.setState("E1");
this.timer.refresh(0);
this.BARRE_PROGRES = new BarreProgres(this.mainTimeline.BARRE_PROGRES);
this.taureau.setState("E0");
this._timelineManager.addMovie(this.mainTimeline.TAUREAU);
this._timelineManager.addMovie(this.mainTimeline.TAUREAU.TAUREAU);
this._timelineManager.addMovie(this.mainTimeline.TIMER);
this._timelineManager.addMovie(this.mainTimeline.TIMER.TIMER_BAR);
this._timelineManager.addMovie(this.mainTimeline.BARRE_PROGRES);
var i:int = 1;
while(i <= 6)
{
this._timelineManager.addMovie(this.mainTimeline.BARRE_PROGRES.getChildByName("TETE_0" + i) as MovieClip);
i++;
}
this.BT_REJOUER = new ExtendedClip(this.mainTimeline.BT_REJOUER,this._e);
this.BT_REJOUER.onPressState = {"label":"E1"};
this.BT_REJOUER.onRollOverState = {
"label":"E2",
"noiseCode":"B_REJ"
};
this.BT_REJOUER.onRollOutState = {"label":"E1"};
this.BT_REJOUER.onPress = function():void
{
var _loc1_:FadeOut = new FadeOut(_e.config.scene,restart);
_loc1_.start();
reset();
};
this.BT_REJOUER.enabled = true;
this.BT_REJOUER.visible = false;
this.BT_REJOUER.init();
this.lm_clique = this._e.textShow({
"id":"LM_CLIQUE",
"parent":this.mainTimeline
});
this.lm_clique.visible = false;
this.waitRollOnTaureau();
}
public function reset() : void
{
this.speedVariator.generate();
this.herakles_echec.gotoAndStop(1);
this.herakles_echec.visible = false;
this.herakles_eject.gotoAndStop(1);
this.herakles_eject.visible = false;
this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
this.taureau.speedPixelSecondes = this.speedVariator.speed;
this.taureau.distanceSeuilPx = this.moduleParams.distanceSeuilPx;
this.taureau.delaiDecrochage = this.moduleParams.delaiDecrochage * 1000;
this.timer.setState("E1");
this.timer.refresh(0);
this.taureau.reset();
this.BT_REJOUER.visible = false;
this.waitClic = false;
this.firstLaunch = true;
}
public function restart() : void
{
this.waitRollOnTaureau();
}
public function waitRollOnTaureau() : void
{
this.startRolltime = getTimer();
this.stage.addEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
}
private function taureauEnterFrameHandler(param1:Event) : void
{
if(this.taureau.hitTestPoint(this.stage.mouseX,this.stage.mouseY,true))
{
if(getTimer() - this.startRolltime >= this.moduleParams.delaiToLaunchGame)
{
this.stage.removeEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
this.ejected = false;
this.taureauRunning = true;
this.taureauIsRollOut = false;
this.taureau.setState("E1");
this.isOn = true;
this.herakles_echec.visible = false;
this.herakles_echec.gotoAndStop(1);
this.speedVariator.generate();
if(this.firstLaunch)
{
this.firstLaunch = false;
this.startTime = getTimer();
}
this._lastTime = this._timeAcrochage = this._timeDecrochage = getTimer();
this.mainTimer.start();
this._e.noisePlay({
"code":"B_TAUREAU",
"loops":999999999
});
}
}
else
{
this.startRolltime = getTimer();
}
}
private function gameLoop(param1:TimerEvent) : void
{
this._actualTime = getTimer();
this._diffTime = this._actualTime - this.startTime;
this.timer.refresh(100 * this._diffTime / this.moduleParams.timerTimeMax);
if(this._diffTime >= this.moduleParams.timerTimeMax)
{
this.failTimeFinished();
return;
}
if(this._actualTime - this._lastTime >= this.taureau.frameDuration)
{
this._lastTime = this._actualTime;
if(this.taureauRunning)
{
this.taureau.move();
}
}
if(this.isOn)
{
this.accrocheTime = this._actualTime - this._timeAcrochage;
this.speedVariator.refresh(this.accrocheTime);
this.taureau.speedPixelSecondes = this.speedVariator.speed;
if(this.accrocheTime > this.moduleParams.delaiAcrochage)
{
this.lm_clique.x = this.taureau.x - this.lm_clique.width / 2;
this.lm_clique.y = this.taureau.y - 60;
this.BARRE_PROGRES.refresh(100);
if(this.waitClic == false)
{
this.waitClic = true;
this.lm_clique.visible = true;
this._e.noisePlay({"code":"B_CORNES"});
this.taureau.addEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
}
if(this.accrocheTime - this.moduleParams.delaiAcrochage >= this.moduleParams.delayToClic)
{
this.pickFail();
}
else
{
this.taureau.setState("E2");
}
}
else
{
this.BARRE_PROGRES.refresh(100 * this.accrocheTime / this.moduleParams.delaiAcrochage);
}
if(this.taureau.hitTestPoint(this.stage.mouseX,this.stage.mouseY,true))
{
if(this.taureauIsRollOut == true)
{
this.taureauIsRollOut = false;
}
}
else
{
if(this.taureauIsRollOut == false)
{
this.taureauIsRollOut = true;
this.taureau.setState("E1");
this._timeDecrochage = getTimer();
}
if(this._actualTime - this._timeDecrochage > this.moduleParams.delaiDecrochage)
{
this.eject();
}
}
param1.updateAfterEvent();
}
}
private function failTimeFinished() : void
{
this.mainTimer.stop();
this._e.noiseStop({"code":"B_TAUREAU"});
this.lm_clique.visible = false;
this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
this.stage.removeEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
this.waitClic = false;
this.timer.setState("E2");
if(this.ejected == false)
{
this.taureau.setState("E3");
this.herakles_eject.x = this.taureau.x;
this.herakles_eject.y = this.taureau.y;
this.herakles_eject.gotoAndPlay(1);
this.herakles_eject.visible = true;
this._e.noisePlay({
"code":"B_EJECT",
"callback":function():void
{
herakles_echec.x = taureau.x;
herakles_echec.y = taureau.y;
herakles_echec.gotoAndPlay(1);
herakles_eject.visible = false;
herakles_eject.gotoAndStop(1);
herakles_echec.visible = true;
BARRE_PROGRES.refresh(0);
_e.noisePlay({
"code":"B_ECHEC",
"callback":function():void
{
taureau.setState("E4");
taureau.depthIndex = mainTimeline.numChildren - 1;
_e.commentPlay({
"code":"PERDU",
"callback":function():void
{
BT_REJOUER.visible = true;
}
});
}
});
}
});
}
else
{
this._e.commentPlay({
"code":"PERDU",
"callback":function():void
{
BT_REJOUER.visible = true;
}
});
}
}
private function pickFail() : void
{
this.mainTimer.stop();
this.lm_clique.visible = false;
this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
this.waitClic = false;
this.taureauRunning = false;
this.taureau.setState("E1");
this._e.commentPlay({
"code":"AGAIN",
"zapBlock":"NOZAP_NOBLOCK",
"callback":function():void
{
speedVariator.generate();
startTime = getTimer() - (_actualTime - startTime);
_timeAcrochage = getTimer() - moduleParams.delaiAcrochage / 2;
mainTimer.start();
taureauRunning = true;
}
});
}
private function eject() : void
{
this.lm_clique.visible = false;
this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
this.waitClic = false;
this.taureauRunning = false;
this.isOn = false;
this.ejected = true;
this.taureau.setState("E3");
this.herakles_eject.x = this.taureau.x;
this.herakles_eject.y = this.taureau.y;
this.herakles_eject.gotoAndPlay(1);
this.herakles_eject.visible = true;
this.herakles_eject.parent.setChildIndex(this.herakles_eject,this.taureau.depthIndex);
this._e.noisePlay({
"code":"B_EJECT",
"callback":function():void
{
herakles_echec.x = taureau.x;
herakles_echec.y = taureau.y;
herakles_echec.gotoAndPlay(1);
herakles_eject.visible = false;
herakles_eject.gotoAndStop(1);
herakles_echec.visible = true;
herakles_echec.parent.setChildIndex(herakles_echec,taureau.depthIndex - 1);
BARRE_PROGRES.refresh(0);
_e.noisePlay({
"code":"B_ECHEC",
"callback":function():void
{
taureau.setState("E4");
taureau.speedPixelSecondes = 300;
taureauRunning = true;
waitRollOnTaureau();
}
});
}
});
}
private function taureauMouseDownHandler(param1:MouseEvent) : void
{
this.mainTimer.stop();
this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
this.GameSucces();
}
private function GameSucces() : void
{
this.save();
this.lm_clique.visible = false;
this._e.noiseStop({"code":"B_TAUREAU"});
this.taureau.setState("E5");
this._e.noisePlay({"code":"B_SUCCES"});
this._e.commentPlay({
"code":"BRAVO",
"zapBlock":"NOZAP_NOBLOCK",
"callback":this.GameSucces2
});
}
private function GameSucces2() : void
{
this.taureau.destroy();
this._timeline_.GotoAndPlayUntil({"labelStop":"_10"});
}
public function G2D(param1:int) : String
{
return GlobalesFunctions.gimme2digits(param1);
}
public function save() : void
{
this.BT_RETOUR._gameWon = true;
if(this.gListDone != null)
{
this.gListDone[this._engine.config.moduleNum - 1] = 1;
if(this.gDoneDepart)
{
this.so.data.lastDone = 2;
}
else
{
this.so.data.lastDone = 1;
}
this.so.data.listDone = this.gListDone;
this.so.flush();
}
}
public function endMODULE() : void
{
this._engine.host.changeModule({"numMod":0});
}
public function sleep() : void
{
if(this.mainTimer.running)
{
this._e.noiseStop({"code":"B_TAUREAU"});
this.gameIsRunning = true;
this.mainTimer.stop();
}
this._pauseManager = new PauseManager(this._engine,this._timelineManager);
this._pauseManager.sleepMovie(this.mainTimeline);
}
public function wake() : void
{
this._pauseManager.wakeMovie(this.mainTimeline);
if(this.gameIsRunning)
{
this.startTime = getTimer() - (this._actualTime - this.startTime);
this._timeAcrochage = getTimer() - this.moduleParams.delaiAcrochage / 2;
this.mainTimer.start();
this._e.noisePlay({
"code":"B_TAUREAU",
"loops":999999999
});
this.gameIsRunning = false;
}
}
public function destroy() : void
{
this._engine.stopAllSounds();
this._timeline_.kilListeners();
if(this.taureau != null)
{
this.taureau.removeEventListener(MouseEvent.MOUSE_DOWN,this.taureauMouseDownHandler);
}
this.mainTimeline.stage.removeEventListener(Event.ENTER_FRAME,this.taureauEnterFrameHandler);
}
}
}