home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 145
/
MOBICLIC145.ISO
/
pc
/
DATA
/
DSS145
/
DSS145_12
/
DSS145_12.swf
/
scripts
/
dss145_12
/
EnemiesAttackManager.as
< prev
next >
Wrap
Text File
|
2012-07-19
|
9KB
|
272 lines
package dss145_12
{
import flash.display.MovieClip;
import flash.geom.Point;
import flash.utils.getTimer;
public class EnemiesAttackManager
{
public var _enemies:Vector.<Enemy>;
public var sequences:Vector.<AttackSequence>;
public var sequence2:Array;
public var lastAttack:Object = null;
public var decor:Decor;
public var startTime:int = 0;
private var models:MovieClip;
private var marks:MovieClip;
private var _totalTime:int = 0;
private var perso:Perso;
private var sequenceTotalTime:Number = 20000;
private var startRelTime:int = 0;
private var laveIntervalTime:int = 3000;
private var level:int = 0;
private var laveIntervals:Array;
public function EnemiesAttackManager(param1:Decor, param2:Perso)
{
var _loc3_:AttackSequence = null;
this._enemies = new Vector.<Enemy>();
this.sequences = new Vector.<AttackSequence>();
this.sequence2 = [];
this.laveIntervals = [10000,7500,6000,5000,4000,3000,2500,2000];
super();
this.decor = param1;
this.perso = param2;
this.models = param1.CLIP_CONTAINER;
this.marks = param1.CLIP_CONTAINER;
this.laveIntervalTime = this.laveIntervals[0];
_loc3_ = new AttackSequence();
_loc3_.add({
"time":3000 + Math.random() * 1000,
"type":"FEU",
"repere":this.marks.FEU_REP_01,
"speedX":-2,
"speedY":0
});
_loc3_.add({
"time":8000,
"type":"END"
});
this.sequences.push(_loc3_);
_loc3_ = new AttackSequence();
_loc3_.add({
"time":3000 + Math.random() * 1000,
"type":"FEU",
"repere":this.marks.FEU_REP_02,
"speedX":2,
"speedY":0
});
_loc3_.add({
"time":12000,
"type":"END"
});
this.sequences.push(_loc3_);
_loc3_ = new AttackSequence();
_loc3_.add({
"time":4000 + Math.random() * 1000,
"type":"FEU",
"repere":this.marks.FEU_REP_02,
"speedX":-2,
"speedY":0
});
_loc3_.add({
"time":12000,
"type":"END"
});
this.sequences.push(_loc3_);
_loc3_ = new AttackSequence();
_loc3_.add({
"time":3000 + Math.random() * 1000,
"type":"FEU",
"repere":this.marks.FEU_REP_04,
"speedX":3,
"speedY":0
});
_loc3_.add({
"time":7000,
"type":"FEU",
"repere":this.marks.FEU_REP_05,
"speedX":-3,
"speedY":0
});
_loc3_.add({
"time":10000,
"type":"END"
});
this.sequences.push(_loc3_);
_loc3_ = new AttackSequence();
_loc3_.add({
"time":3000 + Math.random() * 1000,
"type":"FEU",
"repere":this.marks.FEU_REP_03,
"speedX":3,
"speedY":0
});
_loc3_.add({
"time":10000,
"type":"END"
});
this.sequences.push(_loc3_);
}
public function update(param1:int) : void
{
var _loc3_:int = 0;
var _loc4_:AttackSequence = null;
param1 -= this.startTime;
var _loc2_:int = 0;
while(_loc2_ < this.sequences.length)
{
param1 %= this.sequences[_loc2_].attacks[this.sequences[_loc2_].attacks.length - 1].time;
if(param1 < this.sequences[_loc2_].timeActual)
{
this.sequences[_loc2_].reset();
}
this.sequences[_loc2_].timeActual = param1;
_loc3_ = 0;
while(_loc3_ < this.sequences[_loc2_].attacks.length)
{
if(this.sequences[_loc2_].attacks[_loc3_].done != true && this.sequences[_loc2_].attacks[_loc3_].time <= param1)
{
this.launchAttack(this.sequences[_loc2_].attacks[_loc3_]);
}
_loc3_++;
}
_loc2_++;
}
if(this.laveIntervalTime != 0 && getTimer() - this.startRelTime > this.laveIntervalTime)
{
this.startRelTime = getTimer();
(_loc4_ = new AttackSequence()).add({
"time":0,
"type":"LAVE",
"repere":this.marks.LAVE_REP_10,
"speedX":0,
"speedY":3
});
this.launchAttack(_loc4_.attacks[0]);
}
if(this.decor.getCurrentLevel(this.perso.y) != this.level)
{
this.level = this.decor.getCurrentLevel(this.perso.y);
this.laveIntervalTime = this.laveIntervals[this.level] + (Math.random() * 1000 - 500);
}
this.enemiesUpdate();
}
public function reset(param1:Object) : void
{
var _loc2_:int = 0;
while(_loc2_ < param1.attacks.length)
{
if(param1.attacks[_loc2_].type != "END")
{
param1.attacks[_loc2_].done = false;
}
_loc2_++;
}
}
private function launchAttack(param1:Object) : void
{
param1.done = true;
var _loc2_:Enemy = new Enemy(this.decor,this.models.getChildByName(param1.type) as MovieClip);
_loc2_.type = param1.type;
_loc2_.anim.gotoAndPlay(1);
_loc2_.x = param1.startPoint.x;
_loc2_.y = param1.startPoint.y;
_loc2_.speedX = param1.speedX;
_loc2_.speedY = param1.speedY;
if(_loc2_.speedX > 0)
{
_loc2_.scaleX *= -1;
}
_loc2_.attackParams = param1;
this._enemies.push(_loc2_);
}
public function detectCollision(param1:Perso) : Enemy
{
var _loc2_:Point = null;
var _loc3_:int = 0;
while(_loc3_ < this._enemies.length)
{
if(this._enemies[_loc3_].type == "LAVE")
{
_loc2_ = this._enemies[_loc3_].anim.parent.localToGlobal(new Point(this._enemies[_loc3_].anim.x + this._enemies[_loc3_].anim.width / 2,this._enemies[_loc3_].anim.y + this._enemies[_loc3_].anim.height / 2));
if(param1.clip.STATE.STATE2.hasOwnProperty("HIT_AREA") && param1.clip.STATE.STATE2.HIT_AREA.hitTestPoint(_loc2_.x,_loc2_.y,true))
{
return this._enemies[_loc3_];
}
}
else
{
_loc2_ = this._enemies[_loc3_].anim.parent.localToGlobal(new Point(this._enemies[_loc3_].anim.x,this._enemies[_loc3_].anim.y));
if(param1.clip.STATE.STATE2.hasOwnProperty("HIT_AREA") && param1.clip.STATE.STATE2.HIT_AREA.hitTestPoint(_loc2_.x,_loc2_.y,true))
{
return this._enemies[_loc3_];
}
}
_loc3_++;
}
return null;
}
public function enemiesUpdate() : void
{
var _loc1_:int = 0;
while(_loc1_ < this._enemies.length)
{
this._enemies[_loc1_].move();
this._enemies[_loc1_].redraw();
if(this._enemies[_loc1_].speedX > 0 && this._enemies[_loc1_].x >= this._enemies[_loc1_].attackParams.endPoint.x || this._enemies[_loc1_].speedX < 0 && this._enemies[_loc1_].x <= this._enemies[_loc1_].attackParams.endPoint.x)
{
this.enemyRemove(this._enemies[_loc1_]);
}
else if(this._enemies[_loc1_].speedY > 0 && this._enemies[_loc1_].y >= this._enemies[_loc1_].attackParams.endPoint.y || this._enemies[_loc1_].speedY < 0 && this._enemies[_loc1_].y <= this._enemies[_loc1_].attackParams.endPoint.y)
{
this.enemyRemove(this._enemies[_loc1_]);
}
_loc1_++;
}
}
public function enemyRemove(param1:Enemy) : void
{
param1.destroy();
var _loc2_:int = this._enemies.indexOf(param1);
if(_loc2_ != -1)
{
this._enemies.splice(_loc2_,1);
}
}
public function enemiesRemove() : void
{
var _loc1_:int = 0;
while(_loc1_ < this._enemies.length)
{
this._enemies[_loc1_].destroy();
_loc1_++;
}
this._enemies = new Vector.<Enemy>();
}
}
}