home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / breakawish.swf / scripts / __Packages / Pixies.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  3.8 KB  |  135 lines

  1. class Pixies extends Paddle
  2. {
  3.    var nInitialX;
  4.    var mcRef;
  5.    var nInitialY;
  6.    var nSpeedX;
  7.    var nSpeedY;
  8.    var nMinX;
  9.    var nMaxX;
  10.    var nMinY;
  11.    var nMaxY;
  12.    var nRandomChangeDelay;
  13.    var nDirectionX;
  14.    var nDirectionY;
  15.    static var sPADDLE_PIXIES_STATE_HIDDEN = "Hidden";
  16.    static var sPADDLE_PIXIES_STATE_IN = "In";
  17.    static var sPADDLE_PIXIES_STATE_OUT = "Out";
  18.    static var sPADDLE_PIXIES_STATE_IDLE = "Idle";
  19.    static var nSPEED = 1.2;
  20.    static var nCHANGE = 0.3;
  21.    static var nZONE_HEIGHT = 35;
  22.    static var nZONE_WIDTH = 150;
  23.    static var nDIR_CHANGE_DELAY_MIN = 90;
  24.    static var nDIR_CHANGE_DELAY_MAX = 240;
  25.    function Pixies(_mcRef)
  26.    {
  27.       super(_mcRef);
  28.       this.setState(Pixies.sPADDLE_PIXIES_STATE_HIDDEN);
  29.       this.nInitialX = this.mcRef._x;
  30.       this.nInitialY = this.mcRef._y;
  31.       this.nSpeedX = 0;
  32.       this.nSpeedY = 0;
  33.       this.nMinX = this.nInitialX - Pixies.nZONE_WIDTH / 2;
  34.       this.nMaxX = this.nInitialX + Pixies.nZONE_WIDTH / 2;
  35.       this.nMinY = this.nInitialY - Pixies.nZONE_HEIGHT / 2;
  36.       this.nMaxY = this.nInitialY + Pixies.nZONE_HEIGHT / 2;
  37.       this.setState("Hidden");
  38.    }
  39.    function doShow()
  40.    {
  41.       if(this.CurrentState == Pixies.sPADDLE_PIXIES_STATE_HIDDEN)
  42.       {
  43.          this.setState(Pixies.sPADDLE_PIXIES_STATE_IN);
  44.          this.mcRef._x = this.nInitialX;
  45.          this.mcRef._y = this.nInitialY;
  46.          this.doRandomDirectionChange();
  47.       }
  48.    }
  49.    function doHide()
  50.    {
  51.       if(this.CurrentState == Pixies.sPADDLE_PIXIES_STATE_IDLE)
  52.       {
  53.          this.setState(Pixies.sPADDLE_PIXIES_STATE_OUT);
  54.       }
  55.    }
  56.    function doDestroy()
  57.    {
  58.       super.doDestroy();
  59.    }
  60.    function doIn()
  61.    {
  62.       if(this.isStateComplete())
  63.       {
  64.          this.setState(Pixies.sPADDLE_PIXIES_STATE_IDLE);
  65.       }
  66.    }
  67.    function doOut()
  68.    {
  69.       if(this.isStateComplete())
  70.       {
  71.          this.setState(Pixies.sPADDLE_PIXIES_STATE_HIDDEN);
  72.       }
  73.    }
  74.    function doIdle()
  75.    {
  76.       this.doMove();
  77.       this.nRandomChangeDelay = this.nRandomChangeDelay - 1;
  78.       if(this.nRandomChangeDelay == 0)
  79.       {
  80.          this.doRandomDirectionChange();
  81.       }
  82.    }
  83.    function doRandomDirectionChange()
  84.    {
  85.       this.nDirectionX = Library.Utils.MoreMath.getRandomRange(0,1);
  86.       if(this.nDirectionX == 0)
  87.       {
  88.          this.nDirectionX = -1;
  89.       }
  90.       this.nDirectionY = Library.Utils.MoreMath.getRandomRange(0,1);
  91.       if(this.nDirectionY == 0)
  92.       {
  93.          this.nDirectionY = -1;
  94.       }
  95.       this.nRandomChangeDelay = Library.Utils.MoreMath.getRandomRange(Pixies.nDIR_CHANGE_DELAY_MIN,Pixies.nDIR_CHANGE_DELAY_MAX);
  96.    }
  97.    function doMove()
  98.    {
  99.       if(this.mcRef._x < this.nMinX && this.nDirectionX == -1)
  100.       {
  101.          this.nDirectionX = 1;
  102.       }
  103.       else if(this.mcRef._x > this.nMaxX && this.nDirectionX == 1)
  104.       {
  105.          this.nDirectionX = -1;
  106.       }
  107.       if(this.mcRef._y < this.nMinY && this.nDirectionY == -1)
  108.       {
  109.          this.nDirectionY = 1;
  110.       }
  111.       else if(this.mcRef._y > this.nMaxY && this.nDirectionY == 1)
  112.       {
  113.          this.nDirectionY = -1;
  114.       }
  115.       var _loc2_ = this.nDirectionX * Pixies.nSPEED;
  116.       var _loc3_ = this.nDirectionY * Pixies.nSPEED;
  117.       this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,_loc2_,Pixies.nCHANGE);
  118.       this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,_loc3_,Pixies.nCHANGE);
  119.       this.mcRef._x += this.nSpeedX;
  120.       this.mcRef._y += this.nSpeedY;
  121.    }
  122.    function doLoadStateAction()
  123.    {
  124.       super.doLoadStateAction();
  125.       if(this.CurrentState == Pixies.sPADDLE_PIXIES_STATE_HIDDEN)
  126.       {
  127.          this.mcRef._visible = false;
  128.       }
  129.       else
  130.       {
  131.          this.mcRef._visible = true;
  132.       }
  133.    }
  134. }
  135.