home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 145
/
MOBICLIC145.ISO
/
pc
/
DATA
/
DSS145
/
DSS145_12
/
DSS145_12.swf
/
scripts
/
dss145_12
/
AttenteJeu.as
< prev
next >
Wrap
Text File
|
2012-07-19
|
26KB
|
722 lines
package dss145_12
{
import com.milanpresse.engineaddons.facades.EngineExt;
import com.milanpresse.engineaddons.initdisplayobject.ExtendedClip;
import com.milanpresse.engineaddons.labelstypes.AttenteLabel;
import com.milanpresse.tools.*;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;
import flash.utils.getTimer;
public class AttenteJeu extends AttenteLabel
{
public var CONTAINER:MovieClip;
public var mainAlgo:CapsuleAlgo;
public var BT_REJOUER:ExtendedClip;
public var BT_AIDE:ExtendedClip;
public var DECOR:Decor;
public var PERSO:Perso;
public var CLIP_AIDE:ExtendedClip;
public var enemies:Vector.<Enemy>;
public var QUIZZ_FEN:MovieClip;
public var CHRONO:MovieClip;
private var _timer:Timer;
private var _timerFallEnd:Timer;
private var _questionsJeuManager:Questions;
private var _questionOriginalList:Vector.<Question>;
private var _timerToStop:Array;
private var _timerToStart:Array;
private var actions:Object;
private var keyToAction:Object;
private var posGlobal:Point;
private var containerPosOriginal:Point;
private var _enemiesManager:EnemiesAttackManager;
private var _startTime:int;
private var _ennemyCollided:Enemy;
private var _oiseauIntervalTime:int = 20000;
private var _oiseauLastTime:int = 0;
private var _oiseau:MovieClip;
private var _oiseauIsFlying:Boolean = false;
private var lastState:String = "";
private var _b_chute_AlreadyPlay:Boolean = false;
private var bonusNb:int = 5;
private var causeOfFail:String = null;
private var causeToBadComments:Object;
private var _quizReponsesClip:Vector.<ExtendedClip>;
private var _quizFenIsInitialised:Boolean = false;
private var _timerToWake:Boolean = false;
private var _timerFallEndToWake:Boolean = false;
public function AttenteJeu(param1:EngineExt, param2:MovieClip, param3:Function = null)
{
this.enemies = new Vector.<Enemy>();
this._timerFallEnd = new Timer(3000,1);
this._questionOriginalList = new Vector.<Question>();
this._timerToStop = [];
this._timerToStart = [];
this.actions = {
"left":false,
"up":false,
"right":false,
"down":false
};
this.keyToAction = {
37:"left",
38:"up",
39:"right",
40:"down"
};
this.causeToBadComments = {
"RAVIN":"BAD_01",
"FEU":"BAD_02",
"LAVE":"BAD_03",
"OISEAU":"BAD_04"
};
this._quizReponsesClip = new Vector.<ExtendedClip>();
super(param1,param3);
this.CONTAINER = param2;
}
public function init() : void
{
var params1:XMLList = null;
var pt:Point = null;
this.DECOR = new Decor(this.CONTAINER);
this.PERSO = new Perso(this.DECOR,this.CONTAINER.HERAKLES);
params1 = _e.config.XmlConfig.Module.Config.Params.Param.(hasOwnProperty("@nom") && @nom == "invincible");
if(params1.length() > 0)
{
this.PERSO.invincible = params1[0].@valeur.toString() == "true" ? true : false;
}
this.BT_REJOUER = new ExtendedClip(this.CONTAINER.parent.getChildByName("BT_REJOUER") as MovieClip,_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
{
this.visible = false;
this.enabled = false;
gameRestart2();
};
this.BT_REJOUER.onRollOut = function():void
{
_e.noiseStop({"code":"B_REJ"});
};
this.BT_REJOUER.visible = false;
this.BT_REJOUER.enabled = false;
this.BT_REJOUER.init();
this.CLIP_AIDE = new ExtendedClip(this.CONTAINER.parent.getChildByName("AIDE") as MovieClip,_e);
this.CLIP_AIDE.onPressState = {};
this.CLIP_AIDE.onRollOverState = {};
this.CLIP_AIDE.onRollOutState = {};
this.CLIP_AIDE.onPress = function():void
{
this.visible = false;
this.enabled = false;
CLIP_AIDE.gotoAndStop(1);
gameResume();
};
this.CLIP_AIDE.visible = false;
this.CLIP_AIDE.enabled = false;
this.CLIP_AIDE.init();
this.BT_AIDE = new ExtendedClip(this.CONTAINER.parent.getChildByName("BT_AIDE") as MovieClip,_e);
this.BT_AIDE.onPressState = {"label":"E1"};
this.BT_AIDE.onRollOverState = {
"label":"E2",
"noiseCode":"B_AIDE"
};
this.BT_AIDE.onRollOutState = {"label":"E1"};
this.BT_AIDE.onPress = function():void
{
gamePause();
CLIP_AIDE.gotoAndPlay(2);
CLIP_AIDE.visible = true;
CLIP_AIDE.enabled = true;
};
this.BT_AIDE.visible = true;
this.BT_AIDE.enabled = true;
this.BT_AIDE.init();
this._enemiesManager = new EnemiesAttackManager(this.DECOR,this.PERSO);
this.QUIZZ_FEN = (this.CONTAINER.parent as MovieClip).QUIZZ_FEN;
this.CONTAINER.parent.removeChild(this.QUIZZ_FEN);
this.createQuestionsListe();
this._questionsJeuManager.next();
this._oiseau = this.CONTAINER.OISEAU;
this._oiseau.gotoAndStop(1);
this.CONTAINER.removeChild(this._oiseau);
this.CHRONO = _e.timelineLinearSet((this.CONTAINER.parent as MovieClip).CHRONO,this);
this.CHRONO.timeline.GotoAndStop(1);
this.containerPosOriginal = new Point(this.CONTAINER.x,this.CONTAINER.y);
this._timer = new Timer(1);
this._timer.addEventListener(TimerEvent.TIMER,this.gameLoop);
this.CONTAINER.stage.addEventListener(KeyboardEvent.KEY_DOWN,this.keyDownHandler);
this.CONTAINER.stage.addEventListener(KeyboardEvent.KEY_UP,this.keyUpHandler);
pt = new Point(400,300);
pt = this.CONTAINER.globalToLocal(pt);
this._oiseau.x = pt.x;
this._oiseau.y = pt.y;
this.go();
}
public function gamePause() : void
{
this._timerToStart = [];
if(this._timer.running)
{
this._timer.stop();
this._timerToStart.push(this._timer);
}
if(this._timerFallEnd.running)
{
this._timerFallEnd.stop();
this._timerToStart.push(this._timerFallEnd);
}
if(this._oiseau.isFlying)
{
this._oiseau.stop();
}
if(this.CHRONO.isRunning)
{
this.CHRONO.stop();
}
}
public function gameResume() : void
{
var _loc1_:int = 0;
while(_loc1_ < this._timerToStart.length)
{
this._timerToStart[_loc1_].start();
_loc1_++;
}
if(this._oiseau.isFlying)
{
this._oiseau.play();
}
if(this.CHRONO.isRunning)
{
this.CHRONO.play();
}
}
private function reset() : void
{
if(this.QUIZZ_FEN.parent != null)
{
this.QUIZZ_FEN.parent.removeChild(this.QUIZZ_FEN);
}
this.CONTAINER.stage.focus = this.CONTAINER.stage;
this._timer.reset();
this._enemiesManager.enemiesRemove();
this._oiseau.isFlying = false;
this._oiseau.gotoAndStop(1);
this._oiseau.OISEAU.gotoAndStop("E1");
this._enemiesManager.startTime = this._startTime = this._oiseauLastTime = getTimer();
}
private function go() : void
{
this.redrawAll();
this.CHRONO.visible = true;
this.CHRONO.timeline.GotoAndPlayUntilTheEnd(1,this.run);
this.CHRONO.isRunning = true;
}
private function gameContinue() : void
{
this.reset();
this.PERSO.resetContinue();
this._ennemyCollided = null;
this.go();
}
private function gameRestart() : void
{
this.reset();
this.PERSO.reset();
this.bonusNb = 0;
this.bonusRefresh();
this._ennemyCollided = null;
this.redrawAll();
this.BT_REJOUER.enabled = true;
this.BT_REJOUER.visible = true;
}
private function gameRestart2() : void
{
this.bonusNb = 5;
this.bonusRefresh();
this.go();
}
private function createQuestionsListe() : void
{
var xmllist:XMLList = null;
var xmllist2:XMLList = null;
var question:Question = null;
var node:XML = null;
var node2:XML = null;
var reponse:Reponse = null;
var j:int = 0;
this._questionsJeuManager = new Questions();
var questions:Vector.<Question> = new Vector.<Question>();
var i:int = 1;
while(i <= 5)
{
xmllist = _e.config.XmlConfig.Module[_e.config.lang].LegendesMedias.*.(hasOwnProperty("@id") && @id.search("LM_Q_" + GlobalesFunctions.gimme2digits(i)) != -1);
if(xmllist.length() <= 0)
{
break;
}
node = xmllist[0];
question = new Question();
question.no = i;
question.idLM = node.@id;
question.text = node.toString();
j = 1;
while(j <= 3)
{
node2 = _e.config.XmlConfig.Module[_e.config.lang].LegendesMedias.*.(hasOwnProperty("@id") && @id.search("LM_R_" + GlobalesFunctions.gimme2digits(i) + "_" + GlobalesFunctions.gimme2digits(j)) != -1)[0];
reponse = new Reponse();
reponse.good = j == 1 ? true : false;
reponse.no = j;
reponse.idLM = node2.@id.toString();
reponse.text = node2.toString();
question.reponses.push(reponse);
j++;
}
this._questionsJeuManager.addQuestion(question);
i++;
}
this._questionOriginalList = this._questionsJeuManager.questions.slice();
}
private function run() : void
{
_e.noisePlay({"code":"B_CHRONO"});
this.CHRONO.visible = false;
this.CHRONO.isRunning = false;
this._enemiesManager.startTime = this._startTime = this._oiseauLastTime = getTimer();
this._timer.start();
}
private function keyDownHandler(param1:KeyboardEvent) : void
{
this.actions[this.keyToAction[param1.keyCode]] = true;
}
private function keyUpHandler(param1:KeyboardEvent) : void
{
this.actions[this.keyToAction[param1.keyCode]] = false;
}
private function oiseauHandler(param1:Event) : void
{
if(this._oiseau.currentFrame >= this._oiseau.totalFrames)
{
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.oiseauHandler);
this.CONTAINER.removeChild(this._oiseau);
this._oiseau.isFlying = false;
}
}
private function gameLoop(param1:TimerEvent) : void
{
var _loc3_:Number = NaN;
if(this._ennemyCollided != null)
{
return;
}
this.PERSO.move(this.actions);
if(this.PERSO.isArrivedToEnd)
{
this.stopAll();
this.gameSucces();
return;
}
if(getTimer() - this._oiseauLastTime >= this._oiseauIntervalTime)
{
this._oiseauIsFlying = true;
this._oiseauLastTime = getTimer();
this.CONTAINER.addChild(this._oiseau);
this._oiseau.gotoAndPlay(1);
this._oiseau.isFlying = true;
this._oiseau.visible = true;
this._oiseau.x = 400;
this._oiseau.y = this.PERSO.y;
this.CONTAINER.stage.addEventListener(Event.ENTER_FRAME,this.oiseauHandler);
}
var _loc2_:Point = this._oiseau.localToGlobal(new Point(this._oiseau.OISEAU.x,this._oiseau.OISEAU.y - 95));
_loc2_ = this.CONTAINER.globalToLocal(_loc2_);
if(this.PERSO.invincible == false)
{
_loc3_ = Point.distance(new Point(this.PERSO.x,this.PERSO.y),_loc2_);
if(_loc3_ < 30)
{
this._timer.stop();
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.oiseauHandler);
this.PERSO.isJumping = false;
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.jumpHandler);
this.CONTAINER.HERAKLES.STATE.gotoAndStop("E4");
this.causeOfFail = "OISEAU";
this._oiseau.stop();
this._oiseau.OISEAU.gotoAndStop("E2");
_e.noisePlay({"code":"B_PIAF"});
this._timerFallEnd.addEventListener(TimerEvent.TIMER_COMPLETE,this.endFallHandler);
this._timerFallEnd.start();
return;
}
this._enemiesManager.update(getTimer());
this._ennemyCollided = this._enemiesManager.detectCollision(this.PERSO);
if(this._ennemyCollided != null)
{
this.stopAll();
this.causeOfFail = this._ennemyCollided.type;
this.PERSO.isJumping = false;
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.jumpHandler);
if(this._ennemyCollided.type == "FEU")
{
this._enemiesManager.enemyRemove(this._ennemyCollided);
_e.noisePlay({"code":"B_FEU"});
this.CONTAINER.HERAKLES.STATE.gotoAndStop("E2");
this._timerFallEnd.addEventListener(TimerEvent.TIMER_COMPLETE,this.endFallHandler);
this._timerFallEnd.start();
}
else if(this._ennemyCollided.type == "LAVE")
{
this._enemiesManager.enemyRemove(this._ennemyCollided);
_e.noisePlay({"code":"B_LAVE"});
this.CONTAINER.HERAKLES.STATE.gotoAndStop("E3");
this._timerFallEnd.addEventListener(TimerEvent.TIMER_COMPLETE,this.endFallHandler);
this._timerFallEnd.start();
}
return;
}
}
this.redrawAll();
}
private function redrawAll() : void
{
this.posGlobal = this.CONTAINER.parent.localToGlobal(new Point(this.PERSO.x,this.PERSO.y));
var _loc1_:Number = 300 - this.posGlobal.y;
if(_loc1_ - this.containerPosOriginal.y > 0 && _loc1_ - this.containerPosOriginal.y < 1168)
{
this.CONTAINER.y = _loc1_;
}
else if(_loc1_ - this.containerPosOriginal.y <= 0)
{
this.CONTAINER.y = this.containerPosOriginal.y;
}
else if(_loc1_ - this.containerPosOriginal.y >= 1168)
{
this.CONTAINER.y = -345;
}
this.CONTAINER.HERAKLES.x = this.PERSO.x;
this.CONTAINER.HERAKLES.y = this.PERSO.y;
if(this.PERSO.state == Perso.UPSTAIRS_STOP)
{
this.PERSO.isJumping = false;
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.jumpHandler);
if(this.CONTAINER.HERAKLES.currentFrameLabel != Perso.GO_UP)
{
this.CONTAINER.HERAKLES.gotoAndStop(Perso.GO_UP);
}
this.CONTAINER.HERAKLES.STATE.STATE2.stop();
}
else if(this.PERSO.state == Perso.JUMP_LEFT || this.PERSO.state == Perso.JUMP_RIGHT)
{
if(this.CONTAINER.HERAKLES.currentFrameLabel != this.PERSO.state || this.PERSO.isJumping == false)
{
this.PERSO.isJumping = true;
this.CONTAINER.HERAKLES.gotoAndStop(this.PERSO.state);
this.CONTAINER.HERAKLES.STATE.STATE2.gotoAndPlay(1);
this.CONTAINER.stage.addEventListener(Event.ENTER_FRAME,this.jumpHandler);
}
}
else if(this.PERSO.state == Perso.FALL_END_LEFT || this.PERSO.state == Perso.FALL_END_RIGHT)
{
this.stopAll();
this._b_chute_AlreadyPlay = false;
_e.noiseStop({"code":"B_CHUTE"});
_e.noisePlay({"code":"B_BOUM"});
this.CONTAINER.HERAKLES.STATE.gotoAndStop("E2");
this.causeOfFail = "RAVIN";
this._timerFallEnd.addEventListener(TimerEvent.TIMER_COMPLETE,this.endFallHandler);
this._timerFallEnd.start();
}
else
{
if(this.PERSO.isFalling)
{
if(this._b_chute_AlreadyPlay == false)
{
this._b_chute_AlreadyPlay = true;
_e.noisePlay({"code":"B_CHUTE"});
}
}
this.PERSO.isJumping = false;
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.jumpHandler);
if(this.CONTAINER.HERAKLES.currentFrameLabel != this.PERSO.state)
{
this.CONTAINER.HERAKLES.gotoAndStop(this.PERSO.state);
}
if(this.PERSO.state == Perso.GO_UP || this.PERSO.state == Perso.GO_DOWN)
{
this.CONTAINER.HERAKLES.STATE.STATE2.play();
}
if(this.PERSO.state == Perso.DUCK_LEFT || this.PERSO.state == Perso.DUCK_RIGHT)
{
this.CONTAINER.HERAKLES.STATE.STATE2.gotoAndStop("FIN");
}
}
_e.timelineManager.addMovie(this.CONTAINER.HERAKLES);
_e.timelineManager.addMovie(this.CONTAINER.HERAKLES.STATE);
this.lastState = this.PERSO.state;
}
private function stopAll() : void
{
this._timer.stop();
this._oiseau.gotoAndStop(1);
if(this._oiseau.parent != null)
{
this.CONTAINER.removeChild(this._oiseau);
}
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.oiseauHandler);
}
public function bonusRefresh() : void
{
var _loc1_:MovieClip = null;
var _loc2_:int = 1;
while(_loc2_ <= 5)
{
_loc1_ = this.CONTAINER.parent.getChildByName("BONUS_0" + _loc2_) as MovieClip;
if(_loc2_ <= this.bonusNb)
{
_loc1_.gotoAndPlay(1);
_loc1_.visible = true;
}
else
{
_loc1_.gotoAndStop(1);
_loc1_.visible = false;
}
_loc2_++;
}
}
private function endFallHandler(param1:TimerEvent) : void
{
var event:TimerEvent = param1;
this._timerFallEnd.removeEventListener(TimerEvent.TIMER_COMPLETE,this.endFallHandler);
this._timerFallEnd.reset();
if(this.bonusNb <= 0)
{
this.gameFailure();
}
else
{
--this.bonusNb;
this.bonusRefresh();
_e.noisePlay({
"code":"B_BONUS",
"callback":function():void
{
_e.commentPlay({
"code":causeToBadComments[causeOfFail],
"callback":quizLaunch
});
}
});
}
}
private function gameFailure() : void
{
_e.commentPlay({
"code":"REJ",
"callback":this.gameRestart
});
}
private function gameSucces() : void
{
this.gameEnd();
}
private function gameEnd() : void
{
this.destroy();
_e.instanceToDestroyRemove(this);
_callbackEnd();
}
private function quizLaunch() : void
{
var quizReponse:ExtendedClip = null;
var i:int = 0;
var j:int = 0;
this._questionsJeuManager.next();
this._questionsJeuManager.question.melangerReponses();
this._questionsJeuManager.question.melangerReponses();
this._questionsJeuManager.question.melangerReponses();
if(this._quizFenIsInitialised == false)
{
this._quizFenIsInitialised = true;
this.QUIZZ_FEN.QUESTION.textBloc = _e.textShow({
"id":this._questionsJeuManager.question.idLM,
"model":this.QUIZZ_FEN.QUESTION.TEXT,
"idStyle":"LM.LM_Q"
});
i = 1;
while(i <= 3)
{
this.QUIZZ_FEN["REP_0" + i].textBloc = _e.textShow({
"id":this._questionsJeuManager.question.reponses[i - 1].idLM,
"model":this.QUIZZ_FEN["REP_0" + i].TEXT,
"idStyle":"LM.LM_Q"
});
quizReponse = new ExtendedClip(this.QUIZZ_FEN.getChildByName("REP_0" + i) as MovieClip,_e);
quizReponse.reponse = this._questionsJeuManager.question.reponses[i - 1];
quizReponse.onPressState = {"label":"E1"};
quizReponse.onRollOverState = {
"label":"E2",
"noiseCode":"B_REP"
};
quizReponse.onRollOutState = {"label":"E1"};
quizReponse.onPress = function():void
{
if(this.reponse.good)
{
_e.commentPlay({
"code":"Q_GOOD",
"callback":gameContinue
});
}
else
{
_e.commentPlay({
"code":"Q_RATE",
"callback":gameRestart
});
}
};
quizReponse.enabled = true;
quizReponse.init();
this._quizReponsesClip.push(quizReponse);
i++;
}
}
else
{
this.QUIZZ_FEN.QUESTION.textBloc.text = this._questionsJeuManager.question.text;
this.QUIZZ_FEN.QUESTION.textBloc.x = this.QUIZZ_FEN.QUESTION.TEXT.x + this.QUIZZ_FEN.QUESTION.TEXT.width / 2 - this.QUIZZ_FEN.QUESTION.textBloc.width / 2;
this.QUIZZ_FEN.QUESTION.textBloc.y = this.QUIZZ_FEN.QUESTION.TEXT.y + this.QUIZZ_FEN.QUESTION.TEXT.height / 2 - this.QUIZZ_FEN.QUESTION.textBloc.height / 2;
j = 1;
while(j <= this._quizReponsesClip.length)
{
this.QUIZZ_FEN["REP_0" + j].textBloc.text = this._questionsJeuManager.question.reponses[j - 1].text;
this.QUIZZ_FEN["REP_0" + j].textBloc.x = this.QUIZZ_FEN["REP_0" + j].TEXT.x + this.QUIZZ_FEN["REP_0" + j].TEXT.width / 2 - this.QUIZZ_FEN["REP_0" + j].textBloc.width / 2;
this.QUIZZ_FEN["REP_0" + j].textBloc.y = this.QUIZZ_FEN["REP_0" + j].TEXT.y + this.QUIZZ_FEN["REP_0" + j].TEXT.height / 2 - this.QUIZZ_FEN["REP_0" + j].textBloc.height / 2;
this._quizReponsesClip[j - 1].reponse = this._questionsJeuManager.question.reponses[j - 1];
j++;
}
}
this.CONTAINER.parent.addChild(this.QUIZZ_FEN);
}
private function jumpHandler(param1:Event) : void
{
if(this.CONTAINER.HERAKLES.STATE.STATE2.currentFrame >= this.CONTAINER.HERAKLES.STATE.STATE2.totalFrames)
{
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.jumpHandler);
this.CONTAINER.HERAKLES.STATE.STATE2.stop();
this.PERSO.isJumping = false;
}
}
public function sleep() : void
{
if(this._timer.running)
{
this._timerToWake = true;
this._timer.stop();
}
if(this._timerFallEnd.running)
{
this._timerFallEndToWake = true;
this._timerFallEnd.stop();
}
}
public function wake() : void
{
if(this._timerToWake)
{
this._timerToWake = false;
this._timer.start();
}
if(this._timerFallEndToWake)
{
this._timerFallEndToWake = false;
this._timerFallEnd.start();
}
}
public function destroy() : void
{
this._timerFallEnd.addEventListener(TimerEvent.TIMER_COMPLETE,this.endFallHandler);
this.CONTAINER.stage.addEventListener(Event.ENTER_FRAME,this.oiseauHandler);
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.jumpHandler);
this.CONTAINER.stage.removeEventListener(KeyboardEvent.KEY_DOWN,this.keyDownHandler);
this.CONTAINER.stage.removeEventListener(KeyboardEvent.KEY_UP,this.keyUpHandler);
}
}
}