home *** CD-ROM | disk | FTP | other *** search
- class Pixies extends Paddle
- {
- var nInitialX;
- var mcRef;
- var nInitialY;
- var nSpeedX;
- var nSpeedY;
- var nMinX;
- var nMaxX;
- var nMinY;
- var nMaxY;
- var nRandomChangeDelay;
- var nDirectionX;
- var nDirectionY;
- static var sPADDLE_PIXIES_STATE_HIDDEN = "Hidden";
- static var sPADDLE_PIXIES_STATE_IN = "In";
- static var sPADDLE_PIXIES_STATE_OUT = "Out";
- static var sPADDLE_PIXIES_STATE_IDLE = "Idle";
- static var nSPEED = 1.2;
- static var nCHANGE = 0.3;
- static var nZONE_HEIGHT = 35;
- static var nZONE_WIDTH = 150;
- static var nDIR_CHANGE_DELAY_MIN = 90;
- static var nDIR_CHANGE_DELAY_MAX = 240;
- function Pixies(_mcRef)
- {
- super(_mcRef);
- this.setState(Pixies.sPADDLE_PIXIES_STATE_HIDDEN);
- this.nInitialX = this.mcRef._x;
- this.nInitialY = this.mcRef._y;
- this.nSpeedX = 0;
- this.nSpeedY = 0;
- this.nMinX = this.nInitialX - Pixies.nZONE_WIDTH / 2;
- this.nMaxX = this.nInitialX + Pixies.nZONE_WIDTH / 2;
- this.nMinY = this.nInitialY - Pixies.nZONE_HEIGHT / 2;
- this.nMaxY = this.nInitialY + Pixies.nZONE_HEIGHT / 2;
- this.setState("Hidden");
- }
- function doShow()
- {
- if(this.CurrentState == Pixies.sPADDLE_PIXIES_STATE_HIDDEN)
- {
- this.setState(Pixies.sPADDLE_PIXIES_STATE_IN);
- this.mcRef._x = this.nInitialX;
- this.mcRef._y = this.nInitialY;
- this.doRandomDirectionChange();
- }
- }
- function doHide()
- {
- if(this.CurrentState == Pixies.sPADDLE_PIXIES_STATE_IDLE)
- {
- this.setState(Pixies.sPADDLE_PIXIES_STATE_OUT);
- }
- }
- function doDestroy()
- {
- super.doDestroy();
- }
- function doIn()
- {
- if(this.isStateComplete())
- {
- this.setState(Pixies.sPADDLE_PIXIES_STATE_IDLE);
- }
- }
- function doOut()
- {
- if(this.isStateComplete())
- {
- this.setState(Pixies.sPADDLE_PIXIES_STATE_HIDDEN);
- }
- }
- function doIdle()
- {
- this.doMove();
- this.nRandomChangeDelay = this.nRandomChangeDelay - 1;
- if(this.nRandomChangeDelay == 0)
- {
- this.doRandomDirectionChange();
- }
- }
- function doRandomDirectionChange()
- {
- this.nDirectionX = Library.Utils.MoreMath.getRandomRange(0,1);
- if(this.nDirectionX == 0)
- {
- this.nDirectionX = -1;
- }
- this.nDirectionY = Library.Utils.MoreMath.getRandomRange(0,1);
- if(this.nDirectionY == 0)
- {
- this.nDirectionY = -1;
- }
- this.nRandomChangeDelay = Library.Utils.MoreMath.getRandomRange(Pixies.nDIR_CHANGE_DELAY_MIN,Pixies.nDIR_CHANGE_DELAY_MAX);
- }
- function doMove()
- {
- if(this.mcRef._x < this.nMinX && this.nDirectionX == -1)
- {
- this.nDirectionX = 1;
- }
- else if(this.mcRef._x > this.nMaxX && this.nDirectionX == 1)
- {
- this.nDirectionX = -1;
- }
- if(this.mcRef._y < this.nMinY && this.nDirectionY == -1)
- {
- this.nDirectionY = 1;
- }
- else if(this.mcRef._y > this.nMaxY && this.nDirectionY == 1)
- {
- this.nDirectionY = -1;
- }
- var _loc2_ = this.nDirectionX * Pixies.nSPEED;
- var _loc3_ = this.nDirectionY * Pixies.nSPEED;
- this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,_loc2_,Pixies.nCHANGE);
- this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,_loc3_,Pixies.nCHANGE);
- this.mcRef._x += this.nSpeedX;
- this.mcRef._y += this.nSpeedY;
- }
- function doLoadStateAction()
- {
- super.doLoadStateAction();
- if(this.CurrentState == Pixies.sPADDLE_PIXIES_STATE_HIDDEN)
- {
- this.mcRef._visible = false;
- }
- else
- {
- this.mcRef._visible = true;
- }
- }
- }
-