home *** CD-ROM | disk | FTP | other *** search
- class actionscript.Enemy extends MovieClip
- {
- var game;
- var _startX;
- var _startY;
- var _totEnergy;
- var _currentEnergy;
- var _speed;
- var _initialSpeed;
- var _hit;
- var _slowedDown;
- var _bubblePopped;
- var _killed;
- var powerbar;
- var enemy_hitArea;
- var _rotArray;
- var _curvesArray;
- var _direction;
- var _type;
- var enemy;
- var bubble_mc;
- var _info;
- var _value;
- var _currentRot = 0;
- function Enemy()
- {
- super();
- com.mosesSupposes.fuse.ZigoEngine.register(com.mosesSupposes.fuse.Fuse);
- this.game = this._parent;
- this._x = this._startX = 65;
- this._y = this._startY = 650;
- this._totEnergy = this._currentEnergy = this.game._enemyEnergy;
- this._speed = this._initialSpeed = this.game._enemySpeed;
- this._hit = false;
- this._slowedDown = false;
- this._bubblePopped = false;
- this._killed = false;
- this.powerbar.gotoAndStop(100);
- this.enemy_hitArea._alpha = 0;
- this._rotArray = new Array(null,90,90,-90,-90,90,90,90,-90,-90,-90,-90,90,90);
- this._curvesArray = new Array("up","right","down","right","up","left","up","right","down","right","up","left","down","left","up");
- this._direction = "up";
- this.gotoAndPlay(this._type);
- }
- function moveEnemy(nSpeed, nDirection)
- {
- switch(nDirection)
- {
- case "up":
- this._y -= nSpeed;
- if(this.enemy._rotation != 0)
- {
- this.rotateEnemy(this.enemy._rotation,0);
- }
- break;
- case "right":
- this._x += nSpeed;
- if(this.enemy._rotation != 90)
- {
- this.rotateEnemy(this.enemy._rotation,90);
- }
- break;
- case "left":
- if(this.enemy._rotation != -90)
- {
- this.rotateEnemy(this.enemy._rotation,-90);
- }
- this._x -= nSpeed;
- break;
- case "down":
- if(this.enemy._rotation < 0)
- {
- if(this.enemy._rotation != -180)
- {
- this.rotateEnemy(this.enemy._rotation,-180);
- }
- }
- else if(this.enemy._rotation != 180)
- {
- this.rotateEnemy(this.enemy._rotation,180);
- }
- this._y += nSpeed;
- }
- }
- function rotateEnemy(nStart, nEnd)
- {
- if(nStart < nEnd)
- {
- this.enemy._rotation += 5;
- if(this.enemy._rotation >= nEnd)
- {
- this.enemy._rotation = nEnd;
- }
- }
- else
- {
- this.enemy._rotation -= 5;
- if(this.enemy._rotation <= nEnd)
- {
- this.enemy._rotation = nEnd;
- }
- }
- }
- function setDirection(sDirection)
- {
- this._direction = sDirection;
- }
- function wait(nSec, fFunc)
- {
- var _loc2_ = new com.mosesSupposes.fuse.Fuse();
- _loc2_.scope = this;
- _loc2_.push({delay:nSec,func:fFunc});
- _loc2_.start();
- }
- function slowDownEnemy(nLevel)
- {
- if(!this._slowedDown)
- {
- this._speed *= this.game.sdMult["Pepsi" + nLevel];
- this.wait(this.game.sdTime["Pepsi" + nLevel],"resumeSpeed");
- this._slowedDown = true;
- }
- }
- function resumeSpeed()
- {
- this._speed = this._initialSpeed;
- this._slowedDown = false;
- }
- function calcEnergy()
- {
- var _loc2_ = Math.round(this._currentEnergy * 100 / this._totEnergy);
- return _loc2_;
- }
- function loseEnergy(nDamage)
- {
- if(!this._bubblePopped)
- {
- this.bubble_mc.swapDepths(this.getNextHighestDepth());
- this.bubble_mc.removeMovieClip();
- this._bubblePopped = true;
- }
- this._currentEnergy -= nDamage;
- this.powerbar.gotoAndStop(this.calcEnergy());
- if(this._currentEnergy <= 0 && !this._killed)
- {
- this.game.interface_mc.addSubtractMoney(this.game._enemyValue);
- this.game.interface_mc.addScore(this._totEnergy / 10);
- if(this._type == "roast")
- {
- if(this.game._sfxOn)
- {
- var _loc2_ = new Sound();
- _loc2_.attachSound("death_sound6");
- _loc2_.start();
- }
- }
- else if(this.game._sfxOn)
- {
- var _loc3_ = random(5) + 1;
- _loc2_ = new Sound();
- _loc2_.attachSound("death_sound" + _loc3_);
- _loc2_.start();
- }
- this.killEnemy();
- }
- }
- function killEnemy()
- {
- this._killed = true;
- this.game._enemyKilled = this.game._enemyKilled + 1;
- if(this.game._enemyKilled >= this.game._enemyNumber && !this.game._stopped)
- {
- this.game.wellDone();
- }
- this.powerbar._visible = false;
- this._speed = 0;
- this.enemy.gotoAndStop("die");
- }
- function onEnterFrame()
- {
- if(this.game._stopped)
- {
- return undefined;
- }
- var _loc2_ = 1;
- while(_loc2_ <= this._curvesArray.length - 1)
- {
- if(this.enemy_hitArea.hitTest(this.game.trail_mc["c" + _loc2_]))
- {
- this.setDirection(this._curvesArray[_loc2_]);
- this._currentRot = this._rotArray[_loc2_];
- }
- _loc2_ = _loc2_ + 1;
- }
- this.moveEnemy(this._speed,this._direction);
- if(this._y < -20 && !this._killed)
- {
- if(this.game._lvl == 48)
- {
- this.game.gameOver();
- }
- this.game.interface_mc.loseLife();
- this.killEnemy();
- }
- }
- function updateInfo()
- {
- this._info = this._type + ":<br><br>Energy: " + this._currentEnergy + " / " + this._totEnergy + "<br>Value: " + this._value + " coin(s)<br>" + this.getDesc(this._type);
- }
- function getDesc(sType)
- {
- var _loc3_ = this.game.textMessages;
- var _loc2_ = this.game.enemyType;
- switch(sType)
- {
- case _loc2_[1]:
- return _loc3_._e1Desc;
- case _loc2_[2]:
- return _loc3_._e2Desc;
- case _loc2_[3]:
- return _loc3_._e3Desc;
- case _loc2_[4]:
- return _loc3_._e4Desc;
- case _loc2_[5]:
- return _loc3_._e5Desc;
- case _loc2_[6]:
- return _loc3_._e6Desc;
- default:
- }
- }
- function onRollOver()
- {
- this.updateInfo();
- this.game.interface_mc.setText(this.game.interface_mc.info_txt,this._info);
- }
- function onRollOut()
- {
- this.game.interface_mc.setText(this.game.interface_mc.info_txt,"");
- }
- }
-