home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 150
/
MOBICLIC150.ISO
/
pc
/
DATA
/
DSS150
/
DSS150_02
/
DSS150_02.swf
/
scripts
/
dss150_02
/
ATTENTE.as
next >
Wrap
Text File
|
2012-12-19
|
27KB
|
739 lines
package dss150_02
{
import com.milanpresse.engineaddons.facades.GameEngine;
import com.milanpresse.engineaddons.gamesprotos.Actor;
import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.*;
import com.milanpresse.engineaddons.timers.TimerChild;
import flash.display.MovieClip;
import flash.ui.Mouse;
public class ATTENTE
{
private var game:GameEngine;
public var onEvent:Function = null;
private var _container:IActorClip;
private var mainTimeline:IActorClip;
private var attente:Actor;
private var timerIgloo:ActorTimer;
private var timerOiseauAll:ActorTimer;
private var timerOiseau:ActorTimer;
private var timerPhoqueAll:ActorTimer;
private var timerPhoque:ActorTimer;
private var timerPiege:ActorTimer;
private var timerRelance:ActorTimer;
private var phoqueAll:IActorClip;
private var phoque:IActorClip;
private var oiseaux:Vector.<IActorClip>;
protected var oiseauxDisponibles:Vector.<IActorClip>;
private var iglooJeu:IActorClip;
private var akiak:IActorClip;
private var piste02:IActorClip;
private var piege:IActorClip;
private var neige:IActorClip;
protected var level:int = 0;
protected var timerCurseur:TimerChild;
private var curseur:IActorClip;
private var _mouseVisible:Boolean = true;
protected var timerLevel:TimerChild;
protected var timerPiegeOuvert:TimerChild = null;
protected var timerPhoqueMove:TimerChild = null;
protected var numOiseauxAvantEchec:int = 5;
protected var oiseauxMaxNum:int = 2;
protected var gameFinished:Boolean = false;
protected var enemiesLaunched:Vector.<IActorClip>;
protected var keyDetecter:KeyDetecter;
protected var waitKeyDown:Boolean = false;
protected var isSleeping:Boolean = false;
protected var sleepState:Object;
public function ATTENTE(game:GameEngine, container:IActorClip, mainTimeline:IActorClip)
{
this.oiseaux = new Vector.<IActorClip>();
this.oiseauxDisponibles = new Vector.<IActorClip>();
this.enemiesLaunched = new Vector.<IActorClip>();
this.sleepState = {"mouseVisible":true};
super();
this.game = game;
this._container = container;
this.mainTimeline = mainTimeline;
this.init();
this.start();
}
public function loopDebugLaunch() : void
{
this.game.mainTimer.addFromObj({
"id":"loopDebug",
"delay":100,
"onDelay":function(tc:TimerChild):void
{
}
});
}
public function init() : void
{
this.attente = this.game.addActor(new Actor(this.game));
this.attente.name = "ATTENTE";
this.keyDetecter = this.attente.addActor({
"type":KeyDetecter,
"stage":this.game.stage
}) as KeyDetecter;
this.waitKeyDown = false;
this.level = 0;
this.oiseauxDisponibles.length = 0;
this.oiseaux.length = 0;
this.numOiseauxAvantEchec = 5;
this.gameFinished = false;
this.enemiesLaunched.length = 0;
this.neigeInit();
this.phoqueInit();
this.piegeInit();
this.iglooInit();
this.oiseauxInit();
this.piste02Init();
this.curseurInit();
}
public function start() : void
{
this.mouseVisible = false;
this.game.mainTimer.start();
this.iglooLaunch();
this.loopDebugLaunch();
this.levelStart();
}
public function restart() : void
{
for(var i:int = 0; i < this.oiseaux.length; i++)
{
this.oiseaux[i]["oiseau"].clip.OISEAU_IN.scaleX = this.oiseaux[i]["scaleXOri"];
}
this.destroy();
this.init();
this.start();
}
public function levelStart() : void
{
trace("levelStart");
++this.level;
if(this.level > 5)
{
this.level = 5;
}
trace(">> LEVEL START",this.level);
this.timerLevel = this.game.mainTimer.addFromObj({
"id":"timerLevel",
"delay":this.game.moduleConfig.levels[this.level - 1].duration,
"loop":1,
"onDelay":function(tc:TimerChild):void
{
timerLevel["finished"] = true;
trace(">> LEVEL FINISHED",level);
}
});
this.timerLevel["finished"] = false;
trace("levelContinue from levelStart");
this.levelContinue();
}
public function levelContinue() : void
{
var _loc1_:int = 0;
var _loc2_:int = 0;
trace("levelContinue",this.level,"ox:",this.getNumEnemiesLaunched("oiseau"),"ph:",this.getNumEnemiesLaunched("phoque"));
if(this.timerLevel == null || this.timerLevel["finished"] == false)
{
_loc1_ = this.game.moduleConfig.levels[this.level - 1].oiseauxMaxNum - this.getNumEnemiesLaunched("oiseau");
for(_loc2_ = 0; _loc2_ < _loc1_; _loc2_++)
{
this.oiseauLaunch();
}
_loc1_ = this.game.moduleConfig.levels[this.level - 1].phoquesMaxNum - this.getNumEnemiesLaunched("phoque");
for(_loc2_ = 0; _loc2_ < _loc1_; _loc2_++)
{
this.phoqueLaunch();
}
}
else if(this.getNumEnemiesLaunched() == 0)
{
this.levelStart();
}
}
public function succes() : void
{
trace("succes");
this.mouseVisible = true;
this.game.mainTimer.stop();
this.gameFinished = true;
this.game.noiseStop();
this.game.commentStop();
this.game.memo.module.succes = true;
this.game.memo.save();
this.game.noisePlay({
"code":"B_VALIDE",
"callback":function():void
{
finish();
}
});
}
private function finish() : void
{
trace("finish");
this.destroy();
if(this.onEvent != null)
{
this.onEvent({"action":"succes"});
}
}
public function curseurInit() : void
{
this.curseur = this.attente.addActor({"mc":this._container.getChildByName("CURSEUR") as MovieClip});
this.curseur.enabled = false;
this.curseur.clip.cacheAsBitmap = true;
this.curseur["timerCurseur"] = this.game.mainTimer.addFromObj({
"id":"timerCurseur",
"delay":10,
"onDelay":function(tc:TimerChild):void
{
curseur.setToPos(game.stage.mouseX,game.stage.mouseY);
}
});
this.mouseVisible = false;
}
public function iglooInit() : void
{
this.iglooJeu = this.attente.addActor({"mc":this._container.getChildByName("IGLOO_JEU") as MovieClip});
this.iglooJeu["pourcent"] = 0;
this.iglooJeu["frameActual"] = 1;
this.akiak = this.attente.addActor({"mc":this._container.getChildByName("IGLOO_JEU.AKIAK") as MovieClip});
}
public function iglooLaunch() : void
{
this.iglooJeu["timerIgloo"] = this.game.mainTimer.addFromObj({
"id":"timerIgloo",
"delay":this.game.moduleConfig["iglooSpeed"],
"onDelay":function(tc:TimerChild):void
{
++iglooJeu["frameActual"];
iglooJeu.gotoAndStop(iglooJeu["frameActual"]);
if(iglooJeu["frameActual"] == iglooJeu.totalFrames)
{
succes();
return;
}
if(iglooJeu["frameActual"] == 11)
{
game.commentPlay({
"code":"18_JEU_INFO_01",
"zapBlock":"NOZAP_NOBLOCK"
});
}
else if(iglooJeu["frameActual"] == 28)
{
}
}
});
}
public function neigeInit() : void
{
this.neige = this.attente.addActor({"mc":this._container.getChildByName("NEIGE") as MovieClip});
this.neige.gotoAndStop(1);
this.neige.visible = false;
}
public function oiseauxInit() : void
{
var oiseauAll:IActorClip = null;
var oiseau:IActorClip = null;
for(var i:int = 1; i <= 2; i++)
{
oiseauAll = this.attente.addActor({"mc":this._container.getChildByName("OISEAU_0" + i) as MovieClip});
oiseau = oiseauAll["oiseau"] = oiseauAll.addActor({
"mc":this._container.getChildByName("OISEAU_0" + i + ".OISEAU") as MovieClip,
"onRollOverState":{"label":undefined},
"onRollOutState":{"label":undefined},
"onRollClickState":{"label":undefined}
});
oiseau["oiseauAll"] = oiseauAll;
oiseau.initAs();
oiseau["no"] = i;
oiseauAll["typeEnemy"] = "oiseau";
oiseauAll["sens"] = 1;
oiseauAll["launched"] = false;
oiseauAll["scaleXOri"] = oiseau.clip.OISEAU_IN.scaleX;
oiseau.onClick = function(actor:IActorClip):void
{
trace(this,"click");
actor.enabled = false;
actor["oiseauAll"]["alreadyHit"] = true;
actor["oiseauAll"]["timerOiseauMove"].stop();
actor.gotoAndStop("E2");
game.noisePlay({
"code":"B_TIR",
"callback":function():void
{
if(gameFinished == false)
{
actor.gotoAndStop("E1");
actor["oiseauAll"]["sens"] = -1;
actor.clip.OISEAU_IN.scaleX = actor["oiseauAll"]["scaleXOri"] * actor["oiseauAll"]["sens"];
actor["oiseauAll"]["timerOiseauMove"].start();
}
}
});
};
oiseau.enabled = true;
oiseau.gotoAndStop("E1");
oiseauAll.gotoAndStop(1);
this.oiseaux.push(oiseauAll);
}
var lasttimeOiseau:Number = 0;
}
public function oiseauLaunch() : void
{
var oiseauActuel:IActorClip = null;
trace("oiseauLaunch");
this.oiseauxDisponibles = this.oiseaux.filter(function(item:*, index:int, array:Vector.<IActorClip>):Boolean
{
return item["launched"] == false;
},this);
oiseauActuel = this.oiseauxDisponibles[Math.floor(Math.random() * this.oiseauxDisponibles.length)];
oiseauActuel.gotoAndStop(1);
oiseauActuel["sens"] = 1;
oiseauActuel["oiseau"].clip.OISEAU_IN.scaleX = oiseauActuel["scaleXOri"];
oiseauActuel["oiseau"].gotoAndStop("E1");
oiseauActuel["oiseau"].enabled = true;
oiseauActuel["alreadyHit"] = false;
oiseauActuel["launched"] = true;
this.curseur.dragDrop.dropTargets = [oiseauActuel["oiseau"]];
this.enemiesLaunchedAdd(oiseauActuel);
this.game.mainTimer.addFromObj({
"delay":Math.floor(Math.random() * 3000),
"loop":1,
"onDelay":function(tc:TimerChild):void
{
trace("oiseauLaunch time");
if(gameFinished)
{
return;
}
oiseauActuel["timerOiseauMove"] = game.mainTimer.addFromObj({
"id":"timerOiseauMove" + oiseauActuel["oiseau"]["no"],
"delay":game.moduleConfig.levels[level - 1].oiseauxSpeed,
"onDelay":function(tc:TimerChild):void
{
trace("oiseauMove time");
if(gameFinished)
{
return;
}
if(oiseauActuel.currentLabel == "HIT" && oiseauActuel["alreadyHit"] == false)
{
trace("HIT");
--numOiseauxAvantEchec;
oiseauActuel["alreadyHit"] = true;
oiseauActuel["oiseau"].enabled = false;
tc.stop();
iglooJeu["timerIgloo"].reset();
iglooJeu["frameActual"] = iglooJeu["frameActual"] <= 1 ? 1 : iglooJeu["frameActual"] - 1;
iglooJeu.gotoAndStop(iglooJeu["frameActual"]);
oiseauActuel["oiseau"].gotoAndStop("E3");
game.noisePlay({
"code":"B_PERD",
"callback":function():void
{
oiseauActuel["oiseau"].gotoAndStop("E1");
oiseauActuel["alreadyHit"] = true;
tc.start();
iglooJeu["timerIgloo"].start();
}
});
if(numOiseauxAvantEchec <= 0)
{
game.mainTimer.stop();
gameFinished = true;
game.commentStop();
oiseauNoiseVolClean();
akiak.gotoAndStop("E2");
mouseVisible = true;
keyDetecter.enabled = false;
game.noisePlay({
"code":"B_COLERE",
"callback":function():void
{
akiak.gotoAndStop("E1");
piste02.onLabelEnter = function(result:*):void
{
if(piste02.currentLabel == "FIN")
{
piste02.visible = false;
piste02.stop();
_container.visible = false;
mainTimeline.gotoAndStop("_18_JEU_E1",{"labelLastCallback":function():void
{
mainTimeline.visible = false;
_container.visible = true;
restart();
}});
mainTimeline.visible = true;
}
};
piste02.play(1);
}
});
}
return;
}
if(oiseauActuel["sens"] == 1 && oiseauActuel.currentFrame < oiseauActuel.totalFrames || oiseauActuel["sens"] == -1 && oiseauActuel.currentFrame > 1)
{
oiseauActuel["frameActual"] = oiseauActuel.currentFrame + oiseauActuel["sens"] * 4;
if(oiseauActuel["frameActual"] < 1)
{
oiseauActuel["frameActual"] = 1;
}
else if(oiseauActuel["frameActual"] > oiseauActuel.totalFrames)
{
oiseauActuel["frameActual"] = oiseauActuel.totalFrames;
}
oiseauActuel.gotoAndStop(oiseauActuel["frameActual"]);
}
else
{
trace("fini");
tc.stop();
enemiesLaunchedRemove(oiseauActuel);
oiseauActuel["launched"] = false;
trace("levelContinue from piaf");
levelContinue();
}
}
});
}
});
}
public function oiseauNoiseVolClean() : void
{
}
public function phoqueInit() : void
{
this.phoqueAll = this.attente.addActor({"mc":this._container.getChildByName("PHOQUE") as MovieClip});
this.phoqueAll["typeEnemy"] = "phoque";
this.phoqueAll["launched"] = "false";
this.phoqueAll["JEU_NIV4_JOUE"] = false;
this.phoque = this.attente.addActor({"mc":this._container.getChildByName("PHOQUE.PHOQUE") as MovieClip});
}
public function phoqueLaunch() : void
{
trace("phoqueLaunch");
this.enemiesLaunchedAdd(this.phoqueAll);
this.game.mainTimer.addFromObj({
"id":"phoqueLaunch",
"delay":Math.floor(Math.random() * 3000),
"loop":1,
"onDelay":function(tci:TimerChild):void
{
trace("phoqueLaunchInTimer");
phoqueAll.gotoAndStop(1);
phoque.gotoAndStop("E1");
piege.enabled = true;
keyDetecter.enabled = true;
if(phoqueAll["JEU_NIV4_JOUE"] == false)
{
phoqueAll["JEU_NIV4_JOUE"] = true;
piege.gotoAndStop("E4");
game.commentPlay({
"code":"18_JEU_NIV4",
"zapBlock":"NOZAP_NOBLOCK",
"callback":function():void
{
piege.gotoAndStop("E1");
}
});
}
timerPhoqueMove = game.mainTimer.addFromObj({
"id":"timerPhoqueMove",
"delay":game.moduleConfig.levels[level - 1].phoquesSpeed,
"onDelay":function(tc:TimerChild):void
{
trace("phoque move");
if(gameFinished)
{
return;
}
if(phoqueAll.currentLabel == "FIN")
{
tc.stop();
keyDetecter.enabled = false;
keyDetecter.actionReset();
if(timerPiegeOuvert != null)
{
timerPiegeOuvert.reset();
}
if(piege["opened"])
{
if(gameFinished)
{
return;
}
game.noisePlay({"code":"B_PLOUF"});
phoque.gotoAndStop("E2",{"labelLastCallback":function():void
{
if(gameFinished)
{
return;
}
piege.gotoAndStop("E0");
piege.enabled = false;
piege["opened"] = false;
phoque.gotoAndStop("E1");
phoqueAll.gotoAndStop(1);
enemiesLaunchedRemove(phoqueAll);
trace("levelContinue from phoque");
levelContinue();
}});
}
else
{
if(gameFinished)
{
return;
}
mouseVisible = true;
game.noisePlay({"code":"B_BOOM"});
game.mainTimer.stop();
gameFinished = true;
game.commentStop();
oiseauNoiseVolClean();
phoque.gotoAndStop("E3",{"labelLastCallback":function():void
{
piege.gotoAndStop("E0");
piege.enabled = false;
piege["opened"] = false;
phoque.gotoAndStop("E1");
phoqueAll.gotoAndStop(1);
enemiesLaunchedRemove(phoqueAll);
piste02.onLabelEnter = function(result:*):void
{
if(piste02.currentLabel == "FIN")
{
piste02.visible = false;
piste02.stop();
_container.visible = false;
mainTimeline.gotoAndStop("_18_JEU_E2",{"labelLastCallback":function():void
{
mainTimeline.visible = false;
_container.visible = true;
restart();
}});
mainTimeline.visible = true;
}
};
piste02.play(1);
}});
}
}
else
{
phoqueAll.gotoAndStop(phoqueAll.currentFrame + 1);
if(waitKeyDown == false && keyDetecter.actions.down)
{
trace("up");
waitKeyDown = true;
piegeOpen();
}
else if(keyDetecter.actions.down == false)
{
trace("up false");
waitKeyDown = false;
}
}
}
});
}
});
}
public function piegeInit() : void
{
this.piege = this.attente.addActor({
"mc":this._container.getChildByName("PIEGE") as MovieClip,
"onRollOverState":{"label":undefined},
"onRollOutState":{"label":undefined},
"onClickState":{"label":undefined}
});
this.piege["opened"] = false;
this.piege.initAs();
this.piege.onClick = function(actor:IActorClip):void
{
};
this.piege.enabled = false;
this.piege.gotoAndStop("E0");
}
public function piegeOpen() : void
{
this.piege["opened"] = true;
this.piege.enabled = false;
this.piege.gotoAndStop("E2");
this.timerPiegeOuvert = this.game.mainTimer.addFromObj({
"id":"timerPiegeOuvert",
"delay":1000,
"loop":1,
"onDelay":function(tc:TimerChild):void
{
if(gameFinished)
{
return;
}
piege.gotoAndStop("E1");
piege.enabled = true;
piege["opened"] = false;
}
});
}
public function piste02Init() : void
{
this.piste02 = this.attente.addActor({"mc":this._container.getChildByName("PISTE_02") as MovieClip});
}
public function getNumEnemiesLaunched(type:String = "all") : int
{
if(type == "all")
{
return this.enemiesLaunched.length;
}
var enemy:int = 0;
this.enemiesLaunched.forEach(function(item:*, index:int, array:Vector.<IActorClip>):void
{
if(item["typeEnemy"] == type)
{
++enemy;
}
},this);
return enemy;
}
protected function enemiesLaunchedAdd(obj:Object) : void
{
this.enemiesLaunched.push(obj);
}
protected function enemiesLaunchedRemove(obj:Object) : void
{
this.enemiesLaunched.splice(this.enemiesLaunched.indexOf(obj),1);
}
public function get mouseVisible() : Boolean
{
return this._mouseVisible;
}
public function set mouseVisible(value:Boolean) : void
{
if(value == true)
{
Mouse.show();
}
else
{
Mouse.hide();
}
this._mouseVisible = value;
}
protected function stop() : void
{
if(this.attente != null)
{
}
}
public function sleep() : void
{
if(this.isSleeping)
{
return;
}
this.isSleeping = true;
this.sleepState.mouseVisible = this._mouseVisible;
this.mouseVisible = true;
}
public function wake() : void
{
if(this.isSleeping == false)
{
return;
}
this.isSleeping = false;
this.mouseVisible = this.sleepState.mouseVisible;
}
public function destroy() : void
{
this.stop();
this.game.mainTimer.stop();
this.game.mainTimer.removeAllChilds();
this.mouseVisible = true;
if(this.attente != null)
{
this.attente.dissociate();
this.attente.destroy();
}
this.attente = null;
}
}
}