home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 149
/
MOBICLIC149.ISO
/
pc
/
DATA
/
DSS149
/
DSS149_03
/
DSS149_03.swf
/
scripts
/
dss149_03
/
LabyrintheBase.as
< prev
next >
Wrap
Text File
|
2012-11-21
|
12KB
|
360 lines
package dss149_03
{
import com.milanpresse.engine.Engine;
import com.milanpresse.engine.initmovieclip.InteractiveMovie;
import com.milanpresse.engine.managers.KeyManager;
import com.milanpresse.engine.managers.TimelineManager;
import com.milanpresse.engine.typeargument.NoiseObject;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.geom.Point;
import flash.ui.Keyboard;
public class LabyrintheBase
{
private var moduleConfig:ModuleConfig;
private var _keyManager:KeyManager;
private var gBlockKeys:Boolean = false;
private var gPauseOn:Boolean = false;
private var _e:Engine;
private var _clip:MovieClip;
private var _timelineMngr:TimelineManager;
private var _functionEnd:Function;
private var gDirection:String = "";
private var gStopMove:Boolean = true;
private var gKeyDown:Boolean = false;
private var clipPerso:InteractiveMovie;
private var nomDuClipPerso:String = "PERSO";
private var clipPersoLabelRepos:String = "E1";
private var clipPersoLabel_D:String = "E2";
private var clipPersoLabel_G:String = "E3";
private var clipPersoLabel_H:String = "E4";
private var clipPersoLabel_B:String = "E5";
private var clipPersoLabelGagne:String = "E6";
private var clipLabyrinthe:MovieClip;
private var nomDuClipLabyrinthe:String = "zone_lab";
private var nomDuClipLabyrintheFin:String = "zone_fin";
private var nomDesClipIntrusStatique:String = "TROU";
private var nbIntrusStatique:int = 2;
private var gVitessePerso:int = 5;
public function LabyrintheBase(e:Engine, mainClip:MovieClip, tlnMgr:TimelineManager)
{
super();
this._e = e;
this._clip = mainClip;
this._timelineMngr = tlnMgr;
this.clipPerso = new InteractiveMovie(this._clip[this.nomDuClipPerso],this._timelineMngr);
this.clipLabyrinthe = this._clip[this.nomDuClipLabyrinthe];
this.moduleConfig = new ModuleConfig(this._e.config.XmlConfig.Module.Config.Params);
this.moduleConfig.toString();
this.gVitessePerso = this.moduleConfig.vitessePerso;
this.clipPerso.gotoAndStop(this.clipPersoLabelRepos);
}
public function launch(functionEnd:Function) : void
{
this._functionEnd = functionEnd;
this._keyManager = new KeyManager(this._clip,this.testeKeyDown,this.testeKeyUp);
this.gStopMove = false;
}
private function reset() : void
{
this.clipPerso.mc.x = this.clipPerso.mc.pOrigLoc.x;
this.clipPerso.mc.y = this.clipPerso.mc.pOrigLoc.y;
this.gStopMove = false;
}
public function forget() : void
{
this.clipPerso.mc.parent.removeChild(this.clipPerso.mc);
}
private function appliqueDirOpposee(myMc:MovieClip) : void
{
switch(myMc.pDirection)
{
case "H":
myMc.pDirectionOpposee = "B";
break;
case "G":
myMc.pDirectionOpposee = "D";
break;
case "B":
myMc.pDirectionOpposee = "H";
break;
case "D":
myMc.pDirectionOpposee = "G";
}
}
private function persoEnterFrame(e:Event) : void
{
var newLoc:Array = null;
var nextLocH:int = 0;
var nextLocV:int = 0;
var myMc:MovieClip = null;
var i:int = 0;
if(this.gStopMove == false)
{
newLoc = [0,0];
switch(this.gDirection)
{
case "HAUT":
newLoc[1] -= this.gVitessePerso;
this.clipPerso.gotoAndStop(this.clipPersoLabel_H);
break;
case "GAUCHE":
newLoc[0] -= this.gVitessePerso;
this.clipPerso.gotoAndStop(this.clipPersoLabel_G);
break;
case "BAS":
newLoc[1] += this.gVitessePerso;
this.clipPerso.gotoAndStop(this.clipPersoLabel_B);
break;
case "DROITE":
newLoc[0] += this.gVitessePerso;
this.clipPerso.gotoAndStop(this.clipPersoLabel_D);
}
nextLocH = this.clipPerso.mc.x + newLoc[0];
nextLocV = this.clipPerso.mc.y + newLoc[1];
if(this.testeHIT(this.clipPerso.mc,newLoc).touched == true)
{
trace("testeHIT(clipPerso.mc, newLoc).x",this.testeHIT(this.clipPerso.mc,newLoc).x);
trace("testeHIT(clipPerso.mc, newLoc).y",this.testeHIT(this.clipPerso.mc,newLoc).y);
this.clipPerso.gotoAndStop(this.clipPersoLabelRepos);
}
else
{
this.clipPerso.mc.x = nextLocH;
this.clipPerso.mc.y = nextLocV;
this.clipPerso.mc.bounds_obj = this.clipPerso.mc.getBounds(this._clip);
if(this.clipPerso.mc.hitTestObject(this._clip[this.nomDuClipLabyrintheFin]))
{
trace("gagné !!!");
this._keyManager.killKeyManager();
this.gKeyDown = false;
this.clipPerso.gotoAndStop(this.clipPersoLabelGagne);
this.clipPerso.mc.removeEventListener(Event.ENTER_FRAME,this.persoEnterFrame);
this.gDirection = "";
this._e.playNoise(new NoiseObject({"code":"B_GAGNE"}));
this._functionEnd();
}
else
{
for(i = 1; i <= this.nbIntrusStatique; i++)
{
myMc = this._clip[this.nomDesClipIntrusStatique + "_" + i];
if(myMc.hitTestObject(this.clipPerso.mc.HIT))
{
this.gStopMove = true;
this.clipPerso.gotoAndPlayUntilTheEnd("E6");
this.clipPerso.mc.x = myMc.x + myMc.width / 2;
this.clipPerso.mc.y = myMc.y + myMc.height / 2;
this.gDirection = "";
this._e.playNoise(new NoiseObject({
"code":"B_TOMBE",
"callback":this.finCHUTE
}));
break;
}
}
}
}
}
}
private function finCHUTE() : void
{
this._e.playNoise(new NoiseObject({"code":"B_PERDU"}));
this.reset();
}
private function testeHIT(myMc:MovieClip, newLoc:Array) : Object
{
var minX:int = 0;
var maxX:int = 0;
var minY:int = 0;
var maxY:int = 0;
var x:int = 0;
var y:int = 0;
var i:int = 0;
var j:int = 0;
myMc.bounds_objHIT = myMc.HIT.getBounds(this._clip);
switch(this.gDirection)
{
case "HAUT":
minY = myMc.bounds_objHIT.top - this.gVitessePerso;
maxY = myMc.bounds_objHIT.top;
minX = myMc.bounds_objHIT.left;
maxX = myMc.bounds_objHIT.right;
break;
case "GAUCHE":
minY = myMc.bounds_objHIT.top;
maxY = myMc.bounds_objHIT.bottom;
minX = myMc.bounds_objHIT.left - this.gVitessePerso;
maxX = myMc.bounds_objHIT.left;
break;
case "BAS":
minY = myMc.bounds_objHIT.bottom;
maxY = myMc.bounds_objHIT.bottom + this.gVitessePerso;
minX = myMc.bounds_objHIT.left;
maxX = myMc.bounds_objHIT.right;
break;
case "DROITE":
minY = myMc.bounds_objHIT.top;
maxY = myMc.bounds_objHIT.bottom;
minX = myMc.bounds_objHIT.right;
maxX = myMc.bounds_objHIT.right + this.gVitessePerso;
}
var touched:Boolean = false;
if(newLoc[0] !== 0)
{
for(i = minY; i <= maxY; i++)
{
for(j = minX; j <= maxX; j++)
{
if(myMc.pCadre.hitTestPoint(j,i,true) == false)
{
x = j - 1;
trace("ça touche plus x",x);
touched = true;
break;
}
}
}
}
else
{
for(i = minX; i <= maxX; i++)
{
for(j = minY; j <= maxY; j++)
{
if(myMc.pCadre.hitTestPoint(i,j,true) == false)
{
y = i - 1;
trace("ça touche plus y",y);
touched = true;
break;
}
}
}
}
return {
"touched":touched,
"x":x,
"y":y
};
}
private function testeKeyDown(e:*) : void
{
var key:uint = 0;
if(this.gStopMove == false)
{
if(this.gPauseOn == false)
{
key = e.keyCode;
switch(key)
{
case Keyboard.UP:
trace("HAUT");
this.gDirection = "HAUT";
break;
case Keyboard.LEFT:
trace("GAUCHE");
this.gDirection = "GAUCHE";
break;
case Keyboard.RIGHT:
trace("DROITE");
this.gDirection = "DROITE";
break;
case Keyboard.DOWN:
trace("BAS");
this.gDirection = "BAS";
}
if(this.gDirection !== "")
{
if(this.clipPerso.mc.pOrigLoc == undefined)
{
this.clipPerso.mc.pOrigLoc = new Point(this.clipPerso.mc.x,this.clipPerso.mc.y);
this.clipPerso.mc.pCadre = this.clipLabyrinthe;
}
this.clipPerso.mc.addEventListener(Event.ENTER_FRAME,this.persoEnterFrame);
}
}
}
}
private function testeKeyUp(e:KeyboardEvent) : void
{
if(this.gStopMove == false)
{
if(this._keyManager.isKeyPressed(Keyboard.UP))
{
this.gDirection = "HAUT";
}
else if(this._keyManager.isKeyPressed(Keyboard.LEFT))
{
this.gDirection = "GAUCHE";
}
else if(this._keyManager.isKeyPressed(Keyboard.DOWN))
{
this.gDirection = "BAS";
}
else if(this._keyManager.isKeyPressed(Keyboard.RIGHT))
{
this.gDirection = "DROITE";
}
else
{
this.gKeyDown = false;
this.clipPerso.gotoAndStop(this.clipPersoLabelRepos);
this.clipPerso.mc.removeEventListener(Event.ENTER_FRAME,this.persoEnterFrame);
this.gDirection = "";
}
}
}
public function sleepLab() : void
{
this.gStopMove = true;
this.gPauseOn = true;
}
public function wakeLab() : void
{
this.gStopMove = false;
this.gPauseOn = false;
}
}
}