home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 145
/
MOBICLIC145.ISO
/
pc
/
DATA
/
DSS145
/
DSS145_05
/
DSS145_05.swf
/
scripts
/
dss145_05
/
CapsuleAlgo.as
< prev
next >
Wrap
Text File
|
2012-07-18
|
25KB
|
675 lines
package dss145_05
{
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.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 flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.SharedObject;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.utils.getTimer;
import org.computus.model.Timekeeper;
import org.computus.model.TimekeeperEvent;
public class CapsuleAlgo
{
private var _e:EngineExt;
private var menu:MediaSwf;
private var menuTimeline:MovieClip;
private var menuTL:Timeline;
private var mainClip:MediaSwf;
private var mainTimeline:MovieClip;
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 _bitmap:Bitmap = null;
public var _sprite:Sprite;
private var attenteJeu:AttenteJeu = null;
private var _timerCursor:Timer;
private var ANIM_TIR:ExtendedClip;
public var timekeeper:Timekeeper;
private var _fondDuration:Number = 20;
private var nbOiseauxToLaunch:int = 2;
private var BT_REJOUER:ExtendedClip;
private var keeperTimeIsRunning:Boolean = false;
private var _attackTimeLast:Number = 0;
private var _attackInterval:int = 5000;
private var _attackIntervalMinimum:Number = 12000;
private var _attackIntervalMaximum:Number = 13000;
private var _limitLayer;
private var lastTimeOiseau:int = 0;
private var _levelIndex:int = -1;
private var _totalTimes:Array;
private var _oiseauxSpeedsDuration:Array;
protected var oiseauIndex:int = 0;
protected var ind:int = 2;
protected var delaiActuelTimer:Number = 0;
protected var _spriteMobile:Boolean;
private var Oiseautouche:Boolean = false;
protected var numOiseauxToKill:int = 5;
private var actualTime:int = 0;
public var startTime:int = 0;
private var lastTime:int = 0;
public function CapsuleAlgo(param1:Engine)
{
var engine:Engine = param1;
this.labelsCallback = {"_11":"prioAnim"};
this._timerCursor = new Timer(1);
this._limitLayer = new Sprite();
this._totalTimes = [25555000,35000,35000,35000,35000];
this._oiseauxSpeedsDuration = [60,60,60,60,60];
super();
this._engine = engine;
this._engine.playMusic({"code":"MU"});
this._engine.setSubtitles(this._engine.host.subtitlesOn);
this._engine.setFrameRate(12);
this.mainClip = this._engine.showSwf({
"code":"A_" + this._engine.config.moduleName,
"parent":this._engine.config.layers["content"]
});
this.mainTimeline = this.mainClip.swfContent;
this._timelineManager = new TimelineManager();
this._timeline_ = new TimelineLinear(this.mainTimeline,this._engine,this,this._timelineManager,this.labelsCallback);
this._engine.levelCZ = this._engine.config.layers["content"];
this._e = new EngineExt(this._engine,this._timelineManager);
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;
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 labelATTENTE_JEU() : void
{
this._totalTimes = [];
this._oiseauxSpeedsDuration = [];
var j:int = 1;
while(j <= 5)
{
var _loc3_:int = 0;
var _loc4_:* = §§checkfilter(this._e.config.XmlConfig.Module.Config.Params.Param);
var _loc2_:* = new XMLList("");
§§push(§§findproperty(Number));
this._e.config.XmlConfig.Module.Config.Params.Param.(@nom == "N" + j + "_TotalTime");
§§pop().push(this._totalTimes.Number(_loc2_[0].@valeur) * 1000);
_loc3_ = 0;
_loc4_ = §§checkfilter(this._e.config.XmlConfig.Module.Config.Params.Param);
_loc2_ = new XMLList("");
§§push(§§findproperty(Number));
this._e.config.XmlConfig.Module.Config.Params.Param.(@nom == "N" + j + "_OiseauVitesse");
§§pop().push(this._oiseauxSpeedsDuration.Number(_loc2_[0].@valeur));
j++;
}
_loc3_ = 0;
_loc4_ = §§checkfilter(this._e.config.XmlConfig.Module.Config.Params.Param);
_loc2_ = new XMLList("");
§§push(§§findproperty(Number));
this._e.config.XmlConfig.Module.Config.Params.Param.(@nom == "FondVitesse");
§§pop()._fondDuration = this.Number(_loc2_[0].@valeur);
_loc3_ = 0;
_loc4_ = §§checkfilter(this._e.config.XmlConfig.Module.Config.Params.Param);
_loc2_ = new XMLList("");
§§push(§§findproperty(Number));
this._e.config.XmlConfig.Module.Config.Params.Param.(@nom == "OiseauxSimultanes");
§§pop().nbOiseauxToLaunch = this.Number(_loc2_[0].@valeur);
if(this._fondDuration != -1)
{
if(this._fondDuration != 0)
{
this._fondDuration = 1000 / this._fondDuration;
}
}
this.attenteJeu = new AttenteJeu(this._e,this.labelATTENTE_JEU_CALLBACK,this);
this.attenteJeu.config.CONTAINER = this.mainTimeline;
var anim_oiseaux:MovieClip = this.mainTimeline.getChildByName("ANIM_OISEAU_FOND") as MovieClip;
anim_oiseaux.gotoAndStop(1);
this.mainTimeline.removeChild(this.mainTimeline.getChildByName("CIBLE"));
this._sprite = new Sprite();
this._bitmap = this.buildCacheFromClip(anim_oiseaux);
this._sprite.addChild(this._bitmap);
this._bitmap.x = -this._bitmap.width / 2;
this._bitmap.y = -this._bitmap.height / 2;
this._bitmap.smoothing = true;
this._sprite.cacheAsBitmap = true;
this.mainTimeline.removeChild(anim_oiseaux);
if(this._fondDuration != -1)
{
this.mainTimeline.addChild(this._sprite);
}
this.mainTimeline.addChild(this._limitLayer);
this.timekeeper = new Timekeeper();
this.timekeeper.setRealTimeValue();
this.timekeeper.setRealTimeTick();
this.timekeeper.setTickFrequency(1);
this.timekeeper.setTickDuration(1);
this.timekeeper.startTicking();
this.BT_REJOUER_Init();
this.attenteJeu.config.BT_AIDE = this.mainTimeline.getChildByName("BT_AIDE");
this.attenteJeu.config.BT_REJOUER = this.mainTimeline.getChildByName("BT_REJOUER");
this.mainTimeline.getChildByName("CLIP_AIDE").visible = false;
this.attenteJeu.config.TIMER = this.mainTimeline.getChildByName("TIMER");
var i:int = 1;
while(i <= 5)
{
this.attenteJeu.config.OISEAUX.push(this.mainTimeline.getChildByName("OISEAU_0" + i));
this.attenteJeu.config.OISEAUX_FRONT.push(this.mainTimeline.getChildByName("OISEAU_FRONT_0" + i));
i++;
}
this.mainTimeline.getChildByName("CIBLE");
this.attenteJeu.config.CLIP_AIDE = this.mainTimeline.getChildByName("CLIP_AIDE");
this.ANIM_TIR = new ExtendedClip(this.mainTimeline.getChildByName("ANIM_TIR") as MovieClip,this._e);
this.ANIM_TIR.visible = false;
this.ANIM_TIR.init();
this.attenteJeu.init();
this.gameReset();
this.levelLaunch();
}
private function BT_REJOUER_Init() : void
{
var clip:ExtendedClip = this.BT_REJOUER = new ExtendedClip(this.mainTimeline.getChildByName("BT_REJOUER") as MovieClip,this._e);
clip.onPressState = {"label":"E1"};
clip.onRollOverState = {
"label":"E2",
"noiseCode":"B_REJ"
};
clip.onRollOutState = {"label":"E1"};
clip.onPress = function():void
{
levelLaunch();
};
clip.enabled = false;
clip.visible = false;
clip.init();
}
private function cursorTimerHandler(param1:TimerEvent) : void
{
}
protected function gameReset() : void
{
this._levelIndex = -1;
this.levelReset();
}
protected function levelReset() : void
{
this.numOiseauxToKill = 5;
this.ind = 1;
this.attenteJeu.TIMER.gotoAndStop("E1");
this.attenteJeu.TIMER.movie.TIMER_E1.gotoAndStop(1);
var _loc1_:int = 0;
while(_loc1_ < 5)
{
this.attenteJeu.OISEAUX[_loc1_].gotoAndStop(1);
this.attenteJeu.OISEAUX[_loc1_].movie.CLIP.gotoAndStop("E1");
this.attenteJeu.OISEAUX[_loc1_].visible = false;
this.attenteJeu.OISEAUX[_loc1_].attack = false;
this.attenteJeu.OISEAUX[_loc1_].killed = false;
this.attenteJeu.OISEAUX[_loc1_].depthIndex = this.attenteJeu.CONTAINER.getChildIndex(this._limitLayer);
this.attenteJeu.OISEAUX_FRONT[_loc1_].enabled = false;
this.attenteJeu.OISEAUX_FRONT[_loc1_].movie.CLIP.gotoAndStop("E1");
this.attenteJeu.OISEAUX_FRONT[_loc1_].gotoAndStop(1);
this.attenteJeu.OISEAUX_FRONT[_loc1_].killed = false;
this.attenteJeu.OISEAUX_FRONT[_loc1_].visible = false;
_loc1_++;
}
}
protected function levelLaunch() : void
{
this.BT_REJOUER.visible = false;
++this._levelIndex;
if(this._levelIndex >= 3)
{
this.gameFinished();
}
else
{
this._e.noisePlay({"code":"B_MANCHE"});
this.mainTimeline.stage.addEventListener(MouseEvent.MOUSE_DOWN,this.stageMouseClicHandler);
this.startTime = this.lastTime = this.lastTimeOiseau = this._attackTimeLast = getTimer();
this.timekeeper.addEventListener(TimekeeperEvent.CHANGE,this.onTick);
this.keeperTimeIsRunning = true;
this.launchOiseaux();
}
}
protected function timeFinished() : void
{
this.mainTimeline.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.stageMouseClicHandler);
this.timekeeper.removeEventListener(TimekeeperEvent.CHANGE,this.onTick);
this.keeperTimeIsRunning = false;
this.attenteJeu.TIMER.gotoAndStop("E2");
Mouse.show();
this._e.noisePlay({
"code":"B_TIME",
"callback":function():void
{
levelReset();
_e.commentPlay({
"code":"PERDU",
"callback":function():void
{
BT_REJOUER.enabled = true;
BT_REJOUER.visible = true;
}
});
}
});
}
protected function levelFinished() : void
{
this.mainTimeline.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.stageMouseClicHandler);
this.timekeeper.removeEventListener(TimekeeperEvent.CHANGE,this.onTick);
this.keeperTimeIsRunning = false;
Mouse.show();
this.levelReset();
if(this._levelIndex >= 2)
{
this.gameFinished();
}
else
{
this._e.commentPlay({
"code":"BRAVO_0" + int(this._levelIndex + 1),
"callback":function():void
{
levelLaunch();
}
});
}
}
protected function gameFinished() : void
{
this.save();
this.attenteJeu.BT_AIDE.visible = false;
this.attenteJeu.TIMER.visible = false;
this.mainTimeline.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.stageMouseClicHandler);
this.mainTimeline.removeChild(this._sprite);
this._timeline_.GotoAndPlayUntil({"labelStop":"_10"});
}
protected function launchOiseaux() : void
{
if(this.numOiseauxToKill <= 0)
{
return;
}
var _loc1_:int = 0;
while(_loc1_ < 5)
{
if(this.attenteJeu.OISEAUX[_loc1_].attack == false)
{
this.attenteJeu.OISEAUX[_loc1_].depthIndex = this.attenteJeu.CONTAINER.getChildIndex(this._limitLayer);
this.attenteJeu.OISEAUX[_loc1_].gotoAndPlay(1,this.launchEndHandler);
this.attenteJeu.OISEAUX[_loc1_].visible = true;
this.attenteJeu.OISEAUX[_loc1_].attack = true;
if(_loc1_ + 1 >= this.nbOiseauxToLaunch)
{
return;
}
}
_loc1_++;
}
}
private function launchEndHandler(param1:* = null) : void
{
param1.target.visible = false;
param1.target.gotoAndStop(1);
var _loc2_:ExtendedClip = this.attenteJeu.OISEAUX_FRONT[param1.target.no - 1];
_loc2_.depthIndex = this.attenteJeu.CONTAINER.getChildIndex(this._limitLayer);
_loc2_.gotoAndStop(1);
_loc2_.movie.CLIP.gotoAndStop("E1");
_loc2_.visible = true;
_loc2_.movie.enabled = false;
_loc2_.movie.mouseEnabled = false;
_loc2_.movie.mouseChildren = true;
_loc2_.movie.CLIP.mouseEnabled = false;
_loc2_.movie.CLIP.enabled = false;
_loc2_.movie.CLIP.mouseEnabled = true;
_loc2_.movie.CLIP.STATE.mouseEnabled = false;
_loc2_.movie.CLIP.STATE.enabled = false;
_loc2_.movie.CLIP.STATE.mouseEnabled = true;
_loc2_.movie.CLIP.STATE.ZONE.indexOiseau = param1.target.no - 1;
_loc2_.movie.CLIP.STATE.ZONE.buttonMode = true;
_loc2_.movie.CLIP.STATE.ZONE.enabled = true;
_loc2_.movie.CLIP.STATE.ZONE.mouseEnabled = true;
_loc2_.movie.CLIP.STATE.ZONE.useHandCursor = true;
}
public function resetTimers() : void
{
this.startTime = getTimer() - this.delaiActuelTimer;
this.delaiActuelTimer = 0;
}
public function stopTimer() : void
{
this.delaiActuelTimer = this.actualTime - this.startTime;
}
protected function onTick(param1:TimekeeperEvent) : void
{
var _loc2_:int = 0;
this.actualTime = getTimer();
if(this.delaiActuelTimer == 0)
{
if(this.actualTime - this.startTime >= this._totalTimes[this._levelIndex])
{
this.timeFinished();
return;
}
this.attenteJeu.TIMER.movie.TIMER_E1.gotoAndStop(Math.floor(100 * (this.actualTime - this.startTime) / this._totalTimes[this._levelIndex]));
}
if(this._fondDuration > 0 && this.actualTime - this.lastTime > this._fondDuration)
{
this._sprite.rotation += 5;
this.lastTime = this.actualTime;
}
if(this.actualTime - this.lastTimeOiseau > this._oiseauxSpeedsDuration[this._levelIndex])
{
_loc2_ = 0;
while(_loc2_ < 5)
{
this.lastTimeOiseau = this.actualTime;
if(this.attenteJeu.OISEAUX_FRONT[_loc2_].currentFrame >= this.attenteJeu.OISEAUX_FRONT[_loc2_].totalFrames)
{
this.attenteJeu.OISEAUX_FRONT[_loc2_].gotoAndStop(1);
}
else
{
this.attenteJeu.OISEAUX_FRONT[_loc2_].gotoAndStop(this.attenteJeu.OISEAUX_FRONT[_loc2_].currentFrame + 1);
}
_loc2_++;
}
}
_loc2_ = 0;
while(_loc2_ < 5)
{
if(this.attenteJeu.OISEAUX_FRONT[_loc2_].movie.CLIP.STATE != null && this.attenteJeu.OISEAUX_FRONT[_loc2_].movie.CLIP.STATE.ZONE.hitTestPoint(this.mainTimeline.stage.mouseX,this.mainTimeline.stage.mouseY,true))
{
this.Oiseautouche = true;
break;
}
this.Oiseautouche = false;
_loc2_++;
}
}
private function oiseauReset(param1:ExtendedClip) : void
{
param1.attack = false;
param1.killed = false;
param1.visible = false;
param1.movie.CLIP.gotoAndStop("E1");
param1.gotoAndStop(1);
param1.depthIndex = this.attenteJeu.CONTAINER.getChildIndex(this._limitLayer);
param1.movie.CLIP.STATE.ZONE.removeEventListener(MouseEvent.MOUSE_DOWN,this.zoneClicHandler);
}
private function stageMouseClicHandler(param1:MouseEvent) : void
{
var oiseau:ExtendedClip = null;
var event:MouseEvent = param1;
if(event.target.hasOwnProperty("indexOiseau"))
{
oiseau = this.attenteJeu.OISEAUX_FRONT[event.target.indexOiseau];
if(oiseau.killed)
{
return;
}
oiseau.killed = true;
--this.numOiseauxToKill;
oiseau.stop();
oiseau.last = this.numOiseauxToKill == 0 ? true : false;
if(this.numOiseauxToKill <= 0)
{
this.timekeeper.removeEventListener(TimekeeperEvent.CHANGE,this.onTick);
this.keeperTimeIsRunning = false;
}
this.ANIM_TIR.x = this.attenteJeu.CONTAINER.mouseX;
this.ANIM_TIR.y = this.attenteJeu.CONTAINER.mouseY;
this.ANIM_TIR.depthIndex = this.attenteJeu.CONTAINER.numChildren - 1;
this.ANIM_TIR.gotoAndPlay(1,function():void
{
ANIM_TIR.visible = false;
(oiseau.getChildByName("CLIP") as MovieClip).gotoAndStop("E2");
_e.noisePlay({
"code":"B_CRI",
"callback":function():void
{
(oiseau.getChildByName("CLIP") as MovieClip).gotoAndStop("E3");
if(oiseau.last == false)
{
launchOiseaux();
}
_e.noisePlay({
"code":"B_CENDRE",
"callback":function():void
{
oiseau.gotoAndStop(1);
oiseau.visible = false;
oiseau.attack = false;
oiseau.killed = false;
if(oiseau.last)
{
levelFinished();
}
}
});
}
});
});
this.ANIM_TIR.visible = true;
this._e.noisePlay({"code":"B_TIR"});
}
else
{
this._e.noisePlay({"code":"B_RATE"});
}
}
private function zoneClicHandler(param1:MouseEvent) : void
{
}
public function enterFrameHandler(param1:Event) : void
{
this.actualTime = getTimer();
this.lastTime = this.actualTime;
this._sprite.rotation += 2;
}
public function buildCacheFromClip(param1:MovieClip) : Bitmap
{
var _loc4_:BitmapData = null;
var _loc5_:Matrix = null;
var _loc2_:Bitmap = new Bitmap(null,"auto",true);
param1.gotoAndStop(1);
var _loc3_:Rectangle = param1.getRect(param1);
_loc2_.x = _loc3_.x * param1.scaleX;
_loc2_.y = _loc3_.y * param1.scaleY;
_loc4_ = new BitmapData(_loc3_.width,_loc3_.height,true,0);
(_loc5_ = new Matrix()).translate(-_loc3_.x,-_loc3_.y);
_loc5_.scale(param1.scaleX,param1.scaleY);
_loc4_.draw(param1,_loc5_);
_loc2_.bitmapData = _loc4_;
return _loc2_;
}
public function labelATTENTE_JEU_CALLBACK() : void
{
this._timeline_.GotoAndPlayUntil({"labelStop":"_10"});
}
public function G2D(param1:int) : String
{
return GlobalesFunctions.gimme2digits(param1);
}
public function save() : void
{
this.BT_RETOUR._gameWon = true;
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.keeperTimeIsRunning)
{
this.stopTimer();
}
else
{
this._pauseManager = new PauseManager(this._engine,this._timelineManager);
this._pauseManager.sleepMovie(this.mainTimeline);
}
}
public function wake() : void
{
if(this.keeperTimeIsRunning)
{
this.resetTimers();
}
else
{
this._pauseManager.wakeMovie(this.mainTimeline);
}
}
public function destroy() : void
{
this._timeline_.kilListeners();
this._e.destroy();
this.mainTimeline.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.stageMouseClicHandler);
if(this.keeperTimeIsRunning)
{
this.timekeeper.stopTicking();
}
this.timekeeper.removeEventListener(TimekeeperEvent.CHANGE,this.onTick);
if(this._bitmap != null && this._bitmap.bitmapData != null)
{
this._bitmap.bitmapData.dispose();
}
if(this.attenteJeu != null)
{
this.attenteJeu.destroy();
}
this.timekeeper = null;
this.attenteJeu = null;
this._bitmap = null;
}
public function destroy2() : void
{
this._timeline_.kilListeners();
this._e.destroy();
}
}
}