home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 150
/
MOBICLIC150.ISO
/
pc
/
DATA
/
DSS150
/
DSS150_04
/
DSS150_04.swf
/
scripts
/
dss150_04
/
ATTENTE.as
next >
Wrap
Text File
|
2012-12-19
|
14KB
|
460 lines
package dss150_04
{
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 attente:Actor;
private var timerIsOn:ActorTimer;
private var timerRelance:ActorTimer;
private var akiak:ActorClip;
private var corde:Corde;
private var glace:Glace;
private var glaceTimer:TimerChild;
private var copines:Vector.<ActorClip>;
private var flecheG:ActorClip;
private var flecheD:ActorClip;
private var mainLoop:TimerChild;
private var levelTimer:TimerChild;
private var akiakTimer:TimerChild;
private var keyDetecter:KeyDetecter;
protected var level:int = 0;
protected var waitKeyUp:Boolean = false;
protected var waitKeyRight:Boolean = false;
protected var waitKeyLeft:Boolean = false;
protected var glaceTimerAlreadyLaunched:Boolean = false;
protected var levelLast:int = -1;
private var _mouseVisible:Boolean = true;
protected var isSleeping:Boolean = false;
protected var sleepState:Object;
public function ATTENTE(game:GameEngine, container:IActorClip)
{
this.copines = new Vector.<ActorClip>();
this.sleepState = {"mouseVisible":true};
super();
this.game = game;
this._container = container;
this.init();
this.startNewGame();
}
public function init() : void
{
var clip:ActorClip = null;
this.attente = this.game.addActor(new Actor(this.game));
this.attente.name = "ATTENTE";
this.akiakInit();
this.corde = this.attente.addActor({
"type":Corde,
"mc":this._container.getChildByName("JEU.CORDE") as MovieClip
}) as Corde;
this.glace = this.attente.addActor({
"type":Glace,
"mc":this._container.getChildByName("JEU.GLACE") as MovieClip
}) as Glace;
this.glaceTimer = this.game.mainTimer.addFromObj({
"delay":2000 + Math.floor(Math.random() * 2000),
"loop":1,
"onDelay":this.glaceTimerFunc
});
this.glaceTimer.reset();
for(var i:int = 1; i <= 2; i++)
{
clip = this.attente.addActor({"mc":this._container.getChildByName("JEU.COPINE_0" + i) as MovieClip});
this.copines.push(clip);
}
this.flecheG = clip = this.attente.addActor({"mc":this._container.getChildByName("JEU.FLECHE_G") as MovieClip});
this.flecheD = clip = this.attente.addActor({"mc":this._container.getChildByName("JEU.FLECHE_D") as MovieClip});
this.keyDetecter = this.attente.addActor({
"type":KeyDetecter,
"stage":this.game.stage
}) as KeyDetecter;
this.levelTimer = this.game.mainTimer.addFromObj({
"delay":this.game.moduleConfig.levelDuration,
"loop":1,
"onDelay":this.levelTimerFunc
});
this.levelTimer.reset();
this.mainLoop = this.game.mainTimer.addFromObj({
"delay":20,
"onDelay":this.mainLoopFunc
});
}
public function levelTimerFunc(timer:TimerChild) : void
{
trace("levelTimerFunc");
++this.level;
if(this.level > 3)
{
this.succes();
}
else
{
trace("LEVEL",this.level);
this.levelTimer = this.game.mainTimer.addFromObj({
"delay":this.game.moduleConfig.levelDuration,
"loop":1,
"onDelay":this.levelTimerFunc
});
}
}
public function startNewGame() : void
{
this.akiak.vars.hitCorde = this.game.moduleConfig.numCordeHitToLose;
this.corde.speedAlea = false;
this.levelLast = -1;
this.level = 1;
this.corde.speedMS = this.game.moduleConfig.CordeSautVitesse;
this.glace.comment12_JEU_NIV3DejaJoue = false;
this.continueGame();
}
public function continueGame() : void
{
trace("level",this.level);
this._container.getChildByName("ECHEC").visible = false;
this._container.getChildByName("JEU").visible = true;
this.flecheD.visible = false;
this.flecheG.visible = false;
this.keyDetecter.actionReset();
this.waitKeyRight = false;
this.waitKeyLeft = false;
this.waitKeyUp = false;
this.akiak.vars.failType = "";
this.akiakReset();
this.akiak.gotoAndStop("E1");
this.corde.position = 1;
this.corde.sens = 1;
this.glace.reset();
this.glace.hited = false;
this.copines[0].gotoAndStop("E2");
this.copines[1].gotoAndStop("E2");
this.levelTimer.reset();
this.levelTimer.start();
this.corde.launch();
this.glace.alreadyLaunched = false;
this.glaceTimer.reset();
this.keyDetecter.enabled = true;
this.game.mainTimer.start();
}
public function stop() : void
{
this.game.mainTimer.stop();
this.corde.stop();
this.keyDetecter.enabled = false;
}
public function glaceTimerFunc(timer:TimerChild) : void
{
trace("glaceTimerFunc");
this.glace.launch();
if(this.glace.directionInitiale == 1)
{
this.flecheD.visible = true;
this.flecheG.visible = false;
}
else
{
this.flecheD.visible = false;
this.flecheG.visible = true;
}
}
public function mainLoopFunc(timer:TimerChild) : void
{
if(this.akiakTestCollision())
{
this.fail();
return;
}
if(this.level != this.levelLast)
{
this.levelLast = this.level;
if(this.level == 2)
{
}
}
if(this.level == 3 && this.glace.alreadyLaunched == false)
{
this.glace.alreadyLaunched = true;
this.glaceTimer.start();
}
if(this.waitKeyUp == false && this.keyDetecter.actions.up)
{
trace("up");
this.waitKeyUp = true;
this.akiakJump();
}
else if(this.keyDetecter.actions.up == false)
{
trace("up false");
this.waitKeyUp = false;
}
trace(this.waitKeyRight,this.keyDetecter.actions.right,this.glace.directionInitiale,this.glace.hited);
if(this.waitKeyRight == false && this.keyDetecter.actions.right && this.glace.directionInitiale == 1 && this.glace.hited == false)
{
this.flecheG.visible = false;
this.flecheD.visible = false;
this.glace.hited = true;
this.waitKeyRight = true;
this.glace.sens = -1;
}
else if(this.keyDetecter.actions.right == false)
{
trace("right false");
this.waitKeyRight = false;
}
if(this.waitKeyLeft == false && this.keyDetecter.actions.left && this.glace.directionInitiale == -1 && this.glace.hited == false)
{
this.flecheG.visible = false;
this.flecheD.visible = false;
this.glace.hited = true;
this.waitKeyLeft = true;
this.glace.sens = 1;
}
else if(this.keyDetecter.actions.left == false)
{
trace("right false");
this.waitKeyLeft = false;
}
this.akiakTimer.delay = this.corde.speedMS / 3;
}
protected function akiakInit() : void
{
if(this.akiak == null)
{
this.akiak = this.attente.addActor({"mc":this._container.getChildByName("JEU.AKIAK") as MovieClip});
this.akiak.vars.nbtoursMax = Math.floor(this.game.moduleConfig.AkiakSautFinDuree / this.game.moduleConfig.AkiakSautVitesse);
this.akiakTimer = this.game.mainTimer.addFromObj({
"delay":this.game.moduleConfig.AkiakSautVitesse,
"onDelay":this.akiakOnDelay
});
}
this.akiakReset();
}
protected function akiakReset() : void
{
this.akiak.vars.jumping = false;
this.akiak.vars.vulnerable = true;
this.akiak.vars.nbtours = this.akiak.vars.nbtoursMax;
this.akiakTimer.reset();
}
protected function akiakOnDelay(timer:TimerChild) : void
{
if(this.akiak.vars.jumping)
{
if(this.akiak.currentLabel == "FIN_SAUT")
{
this.akiak.vars.vulnerable = true;
--this.akiak.vars.nbtours;
if(this.akiak.vars.nbtours < 0)
{
this.akiakTimer.reset();
this.akiak.vars.jumping = false;
this.akiak.vars.nbtours = this.akiak.vars.nbtoursMax;
}
}
else
{
this.akiak.gotoAndStop(this.akiak.currentFrame + 1);
}
}
}
protected function akiakJump() : void
{
trace("akiakJump",this.akiak.vars.jumping);
if(this.akiak.vars.jumping == false)
{
this.akiak.gotoAndStop("E2",{"labelLastCallback":function():void
{
game.noisePlay({"code":"B_SAUT"});
akiakTimer.start();
akiak.vars.jumping = true;
akiak.vars.vulnerable = false;
}});
}
}
protected function akiakTestCollision() : Boolean
{
if(this.akiak.vars.vulnerable && this.corde.position == 0)
{
this.akiak.vars.failType = "corde";
return true;
}
if(this.glace.actor.currentFrame > 35 && this.glace.actor.currentFrame < 55)
{
this.akiak.vars.failType = "glace";
this.glace.hited = true;
return true;
}
return false;
}
protected function fail() : void
{
this.stop();
if(this.akiak.vars.failType == "corde")
{
this.akiak.gotoAndStop("E3");
--this.akiak.vars.hitCorde;
trace("akiak.vars.hitCorde",this.akiak.vars.hitCorde);
this.game.noisePlay({
"code":"B_PERD",
"callback":function():void
{
akiak.gotoAndStop("E1");
if(akiak.vars.hitCorde > 0)
{
continueGame();
}
else
{
echec2();
}
}
});
}
else if(this.akiak.vars.failType == "glace")
{
this.akiak.gotoAndStop("E4");
--this.akiak.vars.hitCorde;
trace("akiak.vars.hitCorde",this.akiak.vars.hitCorde);
this.game.noisePlay({"code":"B_GLACE"});
this.akiak.onLabelEnter = function(result:*):void
{
if(akiak.currentLabel == "FIN_E4")
{
akiak.stop();
echec2();
}
};
this.akiak.play("E4");
}
}
protected function echec2() : void
{
this._container.getChildByName("ECHEC").visible = true;
this._container.getChildByName("JEU").visible = false;
this.game.commentPlay({
"code":"12_JEU_E",
"callback":function():void
{
startNewGame();
}
});
}
protected function succes() : void
{
this.finish();
}
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;
}
private function finish() : void
{
trace("finish");
this.game.memo.module.succes = true;
this.game.memo.save();
this.destroy();
if(this.onEvent != null)
{
this.onEvent({"action":"succes"});
}
}
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();
if(this.attente != null)
{
this.attente.dissociate();
this.attente.destroy();
}
this.attente = null;
}
}
}