home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / hungerstrike.swf / scripts / __Packages / actionscript / Enemy.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  6.7 KB  |  241 lines

  1. class actionscript.Enemy extends MovieClip
  2. {
  3.    var game;
  4.    var _startX;
  5.    var _startY;
  6.    var _totEnergy;
  7.    var _currentEnergy;
  8.    var _speed;
  9.    var _initialSpeed;
  10.    var _hit;
  11.    var _slowedDown;
  12.    var _bubblePopped;
  13.    var _killed;
  14.    var powerbar;
  15.    var enemy_hitArea;
  16.    var _rotArray;
  17.    var _curvesArray;
  18.    var _direction;
  19.    var _type;
  20.    var enemy;
  21.    var bubble_mc;
  22.    var _info;
  23.    var _value;
  24.    var _currentRot = 0;
  25.    function Enemy()
  26.    {
  27.       super();
  28.       com.mosesSupposes.fuse.ZigoEngine.register(com.mosesSupposes.fuse.Fuse);
  29.       this.game = this._parent;
  30.       this._x = this._startX = 65;
  31.       this._y = this._startY = 650;
  32.       this._totEnergy = this._currentEnergy = this.game._enemyEnergy;
  33.       this._speed = this._initialSpeed = this.game._enemySpeed;
  34.       this._hit = false;
  35.       this._slowedDown = false;
  36.       this._bubblePopped = false;
  37.       this._killed = false;
  38.       this.powerbar.gotoAndStop(100);
  39.       this.enemy_hitArea._alpha = 0;
  40.       this._rotArray = new Array(null,90,90,-90,-90,90,90,90,-90,-90,-90,-90,90,90);
  41.       this._curvesArray = new Array("up","right","down","right","up","left","up","right","down","right","up","left","down","left","up");
  42.       this._direction = "up";
  43.       this.gotoAndPlay(this._type);
  44.    }
  45.    function moveEnemy(nSpeed, nDirection)
  46.    {
  47.       switch(nDirection)
  48.       {
  49.          case "up":
  50.             this._y -= nSpeed;
  51.             if(this.enemy._rotation != 0)
  52.             {
  53.                this.rotateEnemy(this.enemy._rotation,0);
  54.             }
  55.             break;
  56.          case "right":
  57.             this._x += nSpeed;
  58.             if(this.enemy._rotation != 90)
  59.             {
  60.                this.rotateEnemy(this.enemy._rotation,90);
  61.             }
  62.             break;
  63.          case "left":
  64.             if(this.enemy._rotation != -90)
  65.             {
  66.                this.rotateEnemy(this.enemy._rotation,-90);
  67.             }
  68.             this._x -= nSpeed;
  69.             break;
  70.          case "down":
  71.             if(this.enemy._rotation < 0)
  72.             {
  73.                if(this.enemy._rotation != -180)
  74.                {
  75.                   this.rotateEnemy(this.enemy._rotation,-180);
  76.                }
  77.             }
  78.             else if(this.enemy._rotation != 180)
  79.             {
  80.                this.rotateEnemy(this.enemy._rotation,180);
  81.             }
  82.             this._y += nSpeed;
  83.       }
  84.    }
  85.    function rotateEnemy(nStart, nEnd)
  86.    {
  87.       if(nStart < nEnd)
  88.       {
  89.          this.enemy._rotation += 5;
  90.          if(this.enemy._rotation >= nEnd)
  91.          {
  92.             this.enemy._rotation = nEnd;
  93.          }
  94.       }
  95.       else
  96.       {
  97.          this.enemy._rotation -= 5;
  98.          if(this.enemy._rotation <= nEnd)
  99.          {
  100.             this.enemy._rotation = nEnd;
  101.          }
  102.       }
  103.    }
  104.    function setDirection(sDirection)
  105.    {
  106.       this._direction = sDirection;
  107.    }
  108.    function wait(nSec, fFunc)
  109.    {
  110.       var _loc2_ = new com.mosesSupposes.fuse.Fuse();
  111.       _loc2_.scope = this;
  112.       _loc2_.push({delay:nSec,func:fFunc});
  113.       _loc2_.start();
  114.    }
  115.    function slowDownEnemy(nLevel)
  116.    {
  117.       if(!this._slowedDown)
  118.       {
  119.          this._speed *= this.game.sdMult["Pepsi" + nLevel];
  120.          this.wait(this.game.sdTime["Pepsi" + nLevel],"resumeSpeed");
  121.          this._slowedDown = true;
  122.       }
  123.    }
  124.    function resumeSpeed()
  125.    {
  126.       this._speed = this._initialSpeed;
  127.       this._slowedDown = false;
  128.    }
  129.    function calcEnergy()
  130.    {
  131.       var _loc2_ = Math.round(this._currentEnergy * 100 / this._totEnergy);
  132.       return _loc2_;
  133.    }
  134.    function loseEnergy(nDamage)
  135.    {
  136.       if(!this._bubblePopped)
  137.       {
  138.          this.bubble_mc.swapDepths(this.getNextHighestDepth());
  139.          this.bubble_mc.removeMovieClip();
  140.          this._bubblePopped = true;
  141.       }
  142.       this._currentEnergy -= nDamage;
  143.       this.powerbar.gotoAndStop(this.calcEnergy());
  144.       if(this._currentEnergy <= 0 && !this._killed)
  145.       {
  146.          this.game.interface_mc.addSubtractMoney(this.game._enemyValue);
  147.          this.game.interface_mc.addScore(this._totEnergy / 10);
  148.          if(this._type == "roast")
  149.          {
  150.             if(this.game._sfxOn)
  151.             {
  152.                var _loc2_ = new Sound();
  153.                _loc2_.attachSound("death_sound6");
  154.                _loc2_.start();
  155.             }
  156.          }
  157.          else if(this.game._sfxOn)
  158.          {
  159.             var _loc3_ = random(5) + 1;
  160.             _loc2_ = new Sound();
  161.             _loc2_.attachSound("death_sound" + _loc3_);
  162.             _loc2_.start();
  163.          }
  164.          this.killEnemy();
  165.       }
  166.    }
  167.    function killEnemy()
  168.    {
  169.       this._killed = true;
  170.       this.game._enemyKilled = this.game._enemyKilled + 1;
  171.       if(this.game._enemyKilled >= this.game._enemyNumber && !this.game._stopped)
  172.       {
  173.          this.game.wellDone();
  174.       }
  175.       this.powerbar._visible = false;
  176.       this._speed = 0;
  177.       this.enemy.gotoAndStop("die");
  178.    }
  179.    function onEnterFrame()
  180.    {
  181.       if(this.game._stopped)
  182.       {
  183.          return undefined;
  184.       }
  185.       var _loc2_ = 1;
  186.       while(_loc2_ <= this._curvesArray.length - 1)
  187.       {
  188.          if(this.enemy_hitArea.hitTest(this.game.trail_mc["c" + _loc2_]))
  189.          {
  190.             this.setDirection(this._curvesArray[_loc2_]);
  191.             this._currentRot = this._rotArray[_loc2_];
  192.          }
  193.          _loc2_ = _loc2_ + 1;
  194.       }
  195.       this.moveEnemy(this._speed,this._direction);
  196.       if(this._y < -20 && !this._killed)
  197.       {
  198.          if(this.game._lvl == 48)
  199.          {
  200.             this.game.gameOver();
  201.          }
  202.          this.game.interface_mc.loseLife();
  203.          this.killEnemy();
  204.       }
  205.    }
  206.    function updateInfo()
  207.    {
  208.       this._info = this._type + ":<br><br>Energy: " + this._currentEnergy + " / " + this._totEnergy + "<br>Value: " + this._value + " coin(s)<br>" + this.getDesc(this._type);
  209.    }
  210.    function getDesc(sType)
  211.    {
  212.       var _loc3_ = this.game.textMessages;
  213.       var _loc2_ = this.game.enemyType;
  214.       switch(sType)
  215.       {
  216.          case _loc2_[1]:
  217.             return _loc3_._e1Desc;
  218.          case _loc2_[2]:
  219.             return _loc3_._e2Desc;
  220.          case _loc2_[3]:
  221.             return _loc3_._e3Desc;
  222.          case _loc2_[4]:
  223.             return _loc3_._e4Desc;
  224.          case _loc2_[5]:
  225.             return _loc3_._e5Desc;
  226.          case _loc2_[6]:
  227.             return _loc3_._e6Desc;
  228.          default:
  229.       }
  230.    }
  231.    function onRollOver()
  232.    {
  233.       this.updateInfo();
  234.       this.game.interface_mc.setText(this.game.interface_mc.info_txt,this._info);
  235.    }
  236.    function onRollOut()
  237.    {
  238.       this.game.interface_mc.setText(this.game.interface_mc.info_txt,"");
  239.    }
  240. }
  241.