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

  1. class LevelManager extends Library.DispatcherBase
  2. {
  3.    var mcRef;
  4.    var nLevel;
  5.    var aPaddles;
  6.    var aBlocks;
  7.    var aBalls;
  8.    var aItems;
  9.    var aBolts;
  10.    var nBallNum;
  11.    var nItemNum;
  12.    var bLevelEnded;
  13.    var bDropDownMotionWait;
  14.    var bDropDownMotion;
  15.    var aDropDownElements;
  16.    var aEndLevelElements;
  17.    var bBallSpeedUp;
  18.    var bCalledLevelEnd;
  19.    var bSentEndingWord;
  20.    var nEndCountDown;
  21.    var nNextRemoveDepth;
  22.    var nNextFrontDepth;
  23.    var bPaused;
  24.    var nGameState;
  25.    var nPreventiveEndDelay;
  26.    var bPaddleEndMoveComplete;
  27.    var oMainBall;
  28.    var oBallSpeedUpTimer;
  29.    var oMainPaddle;
  30.    var oPixies;
  31.    var bPixiesVisible;
  32.    var oPixiesVisibleTimer;
  33.    static var oCtrl;
  34.    static var nBLOCKS_NEAR_DISTANCE_X = 60;
  35.    static var nBLOCKS_NEAR_DISTANCE_Y = 40;
  36.    static var nBALLS_NEAR_DISTANCE = 75;
  37.    static var nPADDLE_NEAR_DISTANCE = 185;
  38.    static var nDROPDOWN_LINE_BUFFER = 12;
  39.    static var nLIMITS_CEIL = 35;
  40.    static var nLIMITS_FLOOR = 520;
  41.    static var nLIMITS_LEFT = 15;
  42.    static var nLIMITS_RIGHT = 435;
  43.    static var nGAME_STATE_DROP_DOWN_MOTION = 1;
  44.    static var nGAME_STATE_PLAYING = 2;
  45.    static var nGAME_STATE_WAIT_END_ITEMS_REMAIN = 3;
  46.    static var nGAME_STATE_END_WON_COUNTDOWN = 4;
  47.    static var nGAME_STATE_END_LOSE_COUNTDOWN = 5;
  48.    static var nGAME_STATE_END_EXPLOSION = 6;
  49.    static var nEND_COUNTDOWN = 45;
  50.    static var sLINKAGE_MAIN_BALL = "mcBall";
  51.    static var sBOLT_LINKAGE = "mcBolt";
  52.    static var sTRAIL_STARS_LINKAGE = "mcTrailStars";
  53.    static var sTRAIL_TIMMY_LINKAGE = "mcTrailTimmy";
  54.    static var sWORDS_LINKAGE = "mcMots";
  55.    static var nENDING_WORD_X = 225;
  56.    static var nENDING_WORD_Y = 260;
  57.    static var nMAIN_PADDLE_DEPTH = 50;
  58.    static var nPIXIES_DEPTH_START = 75;
  59.    static var nMAIN_PADDLE_START_X = 225;
  60.    static var nMAIN_PADDLE_START_Y = 420;
  61.    static var nBALL_DEPTH_START = 25000;
  62.    static var nITEMS_DEPTH_START = 75000;
  63.    static var nCHECK_DISTANCE_X = 50;
  64.    static var nCHECK_DISTANCE_Y = 50;
  65.    static var nDEPTH_REMOVE_MIN = 150000;
  66.    static var nDEPTH_REMOVE_MAX = 160000;
  67.    static var nDEPTH_FRONT_MIN = 550000;
  68.    static var nDEPTH_FRONT_MAX = 760000;
  69.    function LevelManager(_mcRef, _nLevel)
  70.    {
  71.       super();
  72.       this.mcRef = _mcRef;
  73.       LevelManager.oCtrl = this;
  74.       this.nLevel = _nLevel;
  75.       this.mcRef.gotoAndStop(_nLevel);
  76.       this.mcRef.mcLevel.gotoAndStop("Init");
  77.       this.aPaddles = new Array();
  78.       this.aBlocks = new Array();
  79.       this.aBalls = new Array();
  80.       this.aItems = new Array();
  81.       this.aBolts = new Array();
  82.       this.nBallNum = 0;
  83.       this.nItemNum = 0;
  84.       this.bLevelEnded = false;
  85.       this.bDropDownMotionWait = true;
  86.       this.bDropDownMotion = false;
  87.       this.aDropDownElements = new Array();
  88.       this.aEndLevelElements = new Array();
  89.       this.bBallSpeedUp = false;
  90.       this.bCalledLevelEnd = false;
  91.       this.bSentEndingWord = false;
  92.       this.nEndCountDown = 0;
  93.       this.nNextRemoveDepth = LevelManager.nDEPTH_REMOVE_MIN;
  94.       this.nNextFrontDepth = LevelManager.nDEPTH_FRONT_MIN;
  95.       this.onInitLevel();
  96.       Game.Instance.doAddListener(this);
  97.    }
  98.    static function get Instance()
  99.    {
  100.       return LevelManager.oCtrl;
  101.    }
  102.    function doEnterFrame()
  103.    {
  104.       super.doEnterFrame();
  105.       if(!this.bPaused)
  106.       {
  107.          if(this.nGameState == LevelManager.nGAME_STATE_END_WON_COUNTDOWN)
  108.          {
  109.             this.nEndCountDown = this.nEndCountDown - 1;
  110.             if(this.nEndCountDown == 0)
  111.             {
  112.                this.onLevelEnded();
  113.             }
  114.          }
  115.          else if(this.nGameState == LevelManager.nGAME_STATE_END_LOSE_COUNTDOWN)
  116.          {
  117.             this.nEndCountDown = this.nEndCountDown - 1;
  118.             if(this.nEndCountDown == 0)
  119.             {
  120.                Game.Instance.doLevelEnd(false);
  121.             }
  122.          }
  123.          else if(this.nGameState == LevelManager.nGAME_STATE_DROP_DOWN_MOTION)
  124.          {
  125.             if(this.bDropDownMotionWait && this.aDropDownElements.length != 0)
  126.             {
  127.                this.bDropDownMotionWait = false;
  128.                this.bDropDownMotion = true;
  129.             }
  130.             if(this.bDropDownMotion)
  131.             {
  132.                this.doDropDownMotion();
  133.             }
  134.          }
  135.          else if(this.nGameState == LevelManager.nGAME_STATE_END_EXPLOSION)
  136.          {
  137.             if(this.bLevelEnded)
  138.             {
  139.                this.doLevelEndExplode();
  140.                if(!this.bCalledLevelEnd)
  141.                {
  142.                   this.nPreventiveEndDelay = this.nPreventiveEndDelay - 1;
  143.                   if(this.nPreventiveEndDelay <= 0)
  144.                   {
  145.                      Game.Instance.doLevelEnd(true);
  146.                      this.bCalledLevelEnd = true;
  147.                   }
  148.                }
  149.             }
  150.          }
  151.          this.doCheckActiveModifiers();
  152.       }
  153.    }
  154.    function doCheckLevelEndAnimComplete()
  155.    {
  156.       if(this.aEndLevelElements.length <= 0 && this.bPaddleEndMoveComplete && !this.bCalledLevelEnd)
  157.       {
  158.          Game.Instance.doLevelEnd(true);
  159.          this.bCalledLevelEnd = true;
  160.       }
  161.    }
  162.    function onPaddleMovedCenter()
  163.    {
  164.       if(this.bLevelEnded)
  165.       {
  166.          this.bPaddleEndMoveComplete = true;
  167.          this.doCheckLevelEndAnimComplete();
  168.       }
  169.    }
  170.    function onLevelEndAnimEnded(_oElement)
  171.    {
  172.       for(var _loc3_ in this.aEndLevelElements)
  173.       {
  174.          if(this.aEndLevelElements[_loc3_].oObj == _oElement)
  175.          {
  176.             delete this.aEndLevelElements[_loc3_].oObj;
  177.             delete this.aEndLevelElements[_loc3_].bExploded;
  178.             this.aEndLevelElements.splice(Number(_loc3_),1);
  179.          }
  180.       }
  181.       this.doCheckLevelEndAnimComplete();
  182.    }
  183.    function onDropDownCompleteForElement(_oElement)
  184.    {
  185.       for(var _loc3_ in this.aDropDownElements)
  186.       {
  187.          if(this.aDropDownElements[_loc3_].oObj == _oElement)
  188.          {
  189.             delete this.aDropDownElements[_loc3_].oObj;
  190.             delete this.aDropDownElements[_loc3_].bMoving;
  191.             this.aDropDownElements.splice(Number(_loc3_),1);
  192.          }
  193.       }
  194.       if(this.aDropDownElements.length <= 0)
  195.       {
  196.          this.onDropDownComplete();
  197.       }
  198.    }
  199.    function doAddPaddle(_oPaddle)
  200.    {
  201.       this.aPaddles.push(_oPaddle);
  202.    }
  203.    function doRemovePaddle(_oPaddle)
  204.    {
  205.       for(var _loc3_ in this.aPaddles)
  206.       {
  207.          if(this.aPaddles[_loc3_] == _oPaddle)
  208.          {
  209.             delete this.aPaddles[_loc3_];
  210.             this.aPaddles.splice(_loc3_,1);
  211.          }
  212.       }
  213.    }
  214.    function doAddLevelDesignItem(_mcItem, _nItemType)
  215.    {
  216.       new LevelDesignItem(_mcItem,_nItemType);
  217.    }
  218.    function doAddItemAt(_nX, _nY, _nItemType)
  219.    {
  220.       var _loc2_ = undefined;
  221.       switch(_nItemType)
  222.       {
  223.          case LevelDesignItem.nBONUS_FAIRY_CROWN:
  224.             _loc2_ = LevelDesignItem.sLINKAGE_BONUS_FAIRY_CROWN;
  225.             break;
  226.          case LevelDesignItem.nBONUS_CC_POWERSUIT:
  227.             _loc2_ = LevelDesignItem.sLINKAGE_BONUS_CC_POWERSUIT;
  228.             break;
  229.          case LevelDesignItem.nBONUS_CC_SYMBOL:
  230.             _loc2_ = LevelDesignItem.sLINKAGE_BONUS_CC_SYMBOL;
  231.             break;
  232.          case LevelDesignItem.nPOWERDOWN_ROCKET:
  233.             _loc2_ = LevelDesignItem.sLINKAGE_POWERDOWN_ROCKET;
  234.             break;
  235.          case LevelDesignItem.nBONUS_TRAMPOLINE:
  236.             _loc2_ = LevelDesignItem.sLINKAGE_BONUS_TRAMPOLINE;
  237.             break;
  238.          case LevelDesignItem.nPOWERDOWN_JACKBOX:
  239.             _loc2_ = LevelDesignItem.sLINKAGE_POWERDOWN_JACKBOX;
  240.             break;
  241.          case LevelDesignItem.nBONUS_CHEWINGGUM:
  242.             _loc2_ = LevelDesignItem.sLINKAGE_BONUS_CHEWINGGUM;
  243.             break;
  244.          case LevelDesignItem.nBONUS_MAGICWAND:
  245.             _loc2_ = LevelDesignItem.sLINKAGE_BONUS_MAGICWAND;
  246.             break;
  247.          case LevelDesignItem.nPOWERDOWN_PING:
  248.             _loc2_ = LevelDesignItem.sLINKAGE_POWERDOWN_PING;
  249.       }
  250.       this.nItemNum = this.nItemNum + 1;
  251.       var _loc3_ = this.mcRef.attachMovie(_loc2_,"mcItem" + this.nItemNum,LevelManager.nITEMS_DEPTH_START + this.nItemNum);
  252.       _loc3_._x = _nX;
  253.       _loc3_._y = _nY;
  254.       var _loc4_ = new FallingItem(_loc3_,_nItemType);
  255.       this.aItems.push(_loc4_);
  256.    }
  257.    function doAddShootingStar(_mcStar)
  258.    {
  259.       var _loc2_ = new ShootingStar(_mcStar);
  260.       this.aDropDownElements.push({oObj:_loc2_,bMoving:false});
  261.       _loc2_.onHideForDropDown();
  262.       this.aBalls.push(_loc2_);
  263.    }
  264.    function doAddBlock(_mcBlock, _nStepNumber)
  265.    {
  266.       var _loc2_ = new Block(_mcBlock,_nStepNumber);
  267.       this.aDropDownElements.push({oObj:_loc2_,bMoving:false});
  268.       _loc2_.onHideForDropDown();
  269.       this.aBlocks.push(_loc2_);
  270.    }
  271.    function doNewBolt(_nX, _nY)
  272.    {
  273.       this.nItemNum = this.nItemNum + 1;
  274.       var _loc2_ = this.mcRef.attachMovie(LevelManager.sBOLT_LINKAGE,"mcBolt" + this.nItemNum,LevelManager.nITEMS_DEPTH_START + this.nItemNum);
  275.       _loc2_._x = _nX;
  276.       _loc2_._y = _nY;
  277.       var _loc3_ = new Bolt(_loc2_);
  278.       this.aBolts.push(_loc3_);
  279.    }
  280.    function doNewTimmyTrail(_nX, _nY, _sAddonState)
  281.    {
  282.       this.nItemNum = this.nItemNum + 1;
  283.       var _loc2_ = this.mcRef.attachMovie(LevelManager.sTRAIL_TIMMY_LINKAGE,"mcTT" + this.nItemNum,LevelManager.nITEMS_DEPTH_START + this.nItemNum);
  284.       _loc2_._x = _nX;
  285.       _loc2_._y = _nY;
  286.       new TrailTimmy(_loc2_,_sAddonState);
  287.    }
  288.    function doNewTrailStar(_nX, _nY)
  289.    {
  290.       this.nItemNum = this.nItemNum + 1;
  291.       var _loc2_ = this.mcRef.attachMovie(LevelManager.sTRAIL_STARS_LINKAGE,"mcTS" + this.nItemNum,LevelManager.nITEMS_DEPTH_START + this.nItemNum);
  292.       _loc2_._x = _nX;
  293.       _loc2_._y = _nY;
  294.       new TrailStars(_loc2_);
  295.    }
  296.    function doNewEndingWord()
  297.    {
  298.       if(!this.bSentEndingWord)
  299.       {
  300.          this.nItemNum = this.nItemNum + 1;
  301.          var _loc2_ = this.mcRef.attachMovie(LevelManager.sWORDS_LINKAGE,"mcWord" + this.nItemNum,LevelManager.nITEMS_DEPTH_START + this.nItemNum);
  302.          _loc2_._x = LevelManager.nENDING_WORD_X;
  303.          _loc2_._y = LevelManager.nENDING_WORD_Y;
  304.          new EndingWord(_loc2_);
  305.          this.bSentEndingWord = true;
  306.       }
  307.    }
  308.    function getNearPaddlesForObject(_oObject)
  309.    {
  310.       var _loc4_ = new Array();
  311.       var _loc3_ = Library.Utils.MoreMath.getBoundsCenter(_oObject.Bounds);
  312.       for(var _loc6_ in this.aPaddles)
  313.       {
  314.          if(this.aPaddles[_loc6_] != _oObject)
  315.          {
  316.             var _loc2_ = Library.Utils.MoreMath.getBoundsCenter(this.aPaddles[_loc6_].Bounds);
  317.             if(Library.Utils.MoreMath.getManhattanDistance(_loc3_.x,_loc3_.y,_loc2_.x,_loc2_.y) <= LevelManager.nPADDLE_NEAR_DISTANCE)
  318.             {
  319.                _loc4_.push(this.aPaddles[_loc6_]);
  320.             }
  321.          }
  322.       }
  323.       return _loc4_;
  324.    }
  325.    function getNearBallsForObject(_oObject)
  326.    {
  327.       var _loc4_ = new Array();
  328.       var _loc3_ = Library.Utils.MoreMath.getBoundsCenter(_oObject.Bounds);
  329.       for(var _loc6_ in this.aBalls)
  330.       {
  331.          if(this.aBalls[_loc6_] != _oObject)
  332.          {
  333.             var _loc2_ = Library.Utils.MoreMath.getBoundsCenter(this.aBalls[_loc6_].Bounds);
  334.             if(Library.Utils.MoreMath.getManhattanDistance(_loc3_.x,_loc3_.y,_loc2_.x,_loc2_.y) <= LevelManager.nBALLS_NEAR_DISTANCE)
  335.             {
  336.                _loc4_.push(this.aBalls[_loc6_]);
  337.             }
  338.          }
  339.       }
  340.       return _loc4_;
  341.    }
  342.    function getNearBlocksForObject(_oObject)
  343.    {
  344.       var _loc4_ = new Array();
  345.       var _loc3_ = Library.Utils.MoreMath.getBoundsCenter(_oObject.Bounds);
  346.       for(var _loc6_ in this.aBlocks)
  347.       {
  348.          if(this.aBlocks[_loc6_] != _oObject)
  349.          {
  350.             var _loc2_ = Library.Utils.MoreMath.getBoundsCenter(this.aBlocks[_loc6_].Bounds);
  351.             if(Math.abs(_loc3_.y - _loc2_.y) <= LevelManager.nBLOCKS_NEAR_DISTANCE_Y)
  352.             {
  353.                if(Math.abs(_loc3_.x - _loc2_.x) <= LevelManager.nBLOCKS_NEAR_DISTANCE_X)
  354.                {
  355.                   _loc4_.push(this.aBlocks[_loc6_]);
  356.                }
  357.             }
  358.          }
  359.       }
  360.       return _loc4_;
  361.    }
  362.    function onItemLost(_oItem)
  363.    {
  364.       this.doDeleteItem(_oItem);
  365.       if(this.nGameState == LevelManager.nGAME_STATE_WAIT_END_ITEMS_REMAIN)
  366.       {
  367.          this.doCheckLevelEnd();
  368.       }
  369.    }
  370.    function onPlayerCatchItem(_oItem)
  371.    {
  372.       this.doDeleteItem(_oItem);
  373.       var _loc3_ = _oItem.ItemType;
  374.       Game.Instance.onPlayerCatchItem(_loc3_);
  375.       switch(_loc3_)
  376.       {
  377.          case LevelDesignItem.nBONUS_FAIRY_CROWN:
  378.             Game.Instance.Status.onGainLive();
  379.             Game.Instance.Status.onCatchBonus();
  380.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_FairyCrown.mp3",100,1,true);
  381.             break;
  382.          case LevelDesignItem.nBONUS_CC_POWERSUIT:
  383.             this.oMainBall.onGainPassThroughAbility();
  384.             Game.Instance.Status.onCatchBonus();
  385.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_CC_Suit.mp3",100,1,true);
  386.             break;
  387.          case LevelDesignItem.nBONUS_CC_SYMBOL:
  388.             Game.Instance.Status.onCatchBonus();
  389.             Game.Instance.Status.doAddPoints(LevelDesignItem.nBONUS_CC_SYMBOL_POINTS);
  390.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_CC_Points.mp3",100,1,true);
  391.             break;
  392.          case LevelDesignItem.nPOWERDOWN_ROCKET:
  393.             if(!this.bBallSpeedUp)
  394.             {
  395.                for(var _loc2_ in this.aBalls)
  396.                {
  397.                   this.aBalls[_loc2_].doAffectSpeed(LevelDesignItem.nPOWERDOWN_ROCKET_SPEED);
  398.                }
  399.             }
  400.             this.bBallSpeedUp = true;
  401.             this.oBallSpeedUpTimer = new Library.Utils.Timer();
  402.             this.oBallSpeedUpTimer.Method = Library.Utils.Timer.TIMER_COUNT_DOWN;
  403.             this.doAddListener(this.oBallSpeedUpTimer);
  404.             this.oBallSpeedUpTimer.setTime(LevelDesignItem.nPOWERDOWN_ROCKET_TIME);
  405.             this.oBallSpeedUpTimer.doStartTimer();
  406.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_Rocket.mp3",100,1,true);
  407.             break;
  408.          case LevelDesignItem.nBONUS_TRAMPOLINE:
  409.             Game.Instance.Status.onCatchBonus();
  410.             this.oMainPaddle.onPaddleResize(PlayerPaddle.sPADDLE_STATE_LARGE);
  411.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_Trampoline.mp3",100,1,true);
  412.             break;
  413.          case LevelDesignItem.nPOWERDOWN_JACKBOX:
  414.             this.oMainPaddle.onPaddleResize(PlayerPaddle.sPADDLE_STATE_SHORT);
  415.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_JackBox.mp3",100,1,true);
  416.             break;
  417.          case LevelDesignItem.nBONUS_CHEWINGGUM:
  418.             Game.Instance.Status.onCatchBonus();
  419.             this.oMainPaddle.onChewingGumCatch();
  420.             this.oMainBall.onChewingGumCatch();
  421.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_BubbleGum.mp3",100,1,true);
  422.             break;
  423.          case LevelDesignItem.nBONUS_MAGICWAND:
  424.             Game.Instance.Status.onCatchBonus();
  425.             this.oMainPaddle.onMagicWandCatch();
  426.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_MagicWand.mp3",100,1,true);
  427.             break;
  428.          case LevelDesignItem.nPOWERDOWN_PING:
  429.             this.doCreatePixies();
  430.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Catch_Ping.mp3",100,1,true);
  431.       }
  432.       if(this.nGameState == LevelManager.nGAME_STATE_WAIT_END_ITEMS_REMAIN)
  433.       {
  434.          this.doCheckLevelEnd();
  435.       }
  436.    }
  437.    function onChewingGumEnd()
  438.    {
  439.       this.oMainBall.onChewingGumEnd();
  440.    }
  441.    function onBlockCrushed(_oBlock)
  442.    {
  443.       this.doDeleteBlock(_oBlock);
  444.       this.doCheckLevelEnd();
  445.    }
  446.    function onBallLost(_oBall)
  447.    {
  448.       this.doDeleteBall(_oBall);
  449.       _oBall.doDestroy();
  450.       if(this.nGameState == LevelManager.nGAME_STATE_PLAYING)
  451.       {
  452.          if(_oBall == this.oMainBall)
  453.          {
  454.             Game.Instance.Status.onLoseLive();
  455.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Lose_Life.mp3");
  456.             this.oMainPaddle.onChewingGumEnd();
  457.             if(Game.Instance.Status.getPlayerCanContinue())
  458.             {
  459.                delete this.oMainBall;
  460.                this.oMainPaddle.doGetBall();
  461.             }
  462.             else
  463.             {
  464.                this.nGameState = LevelManager.nGAME_STATE_END_LOSE_COUNTDOWN;
  465.                this.nEndCountDown = LevelManager.nEND_COUNTDOWN;
  466.             }
  467.          }
  468.       }
  469.    }
  470.    function getNewBall()
  471.    {
  472.       this.nBallNum = this.nBallNum + 1;
  473.       var _loc2_ = this.GameStage.attachMovie(LevelManager.sLINKAGE_MAIN_BALL,"mcBall" + this.nBallNum,LevelManager.nBALL_DEPTH_START + this.nBallNum);
  474.       this.oMainBall = new MainBall(_loc2_);
  475.       if(this.bBallSpeedUp)
  476.       {
  477.          this.oMainBall.doAffectSpeed(LevelDesignItem.nPOWERDOWN_ROCKET_SPEED);
  478.       }
  479.       this.aBalls.push(this.oMainBall);
  480.       return this.oMainBall;
  481.    }
  482.    function onLevelEnded()
  483.    {
  484.       this.nGameState = LevelManager.nGAME_STATE_END_EXPLOSION;
  485.       this.bLevelEnded = true;
  486.       this.nPreventiveEndDelay = 150;
  487.       for(var _loc4_ in this.aBalls)
  488.       {
  489.          this.aEndLevelElements.push({oObj:this.aBalls[_loc4_],bExploded:false});
  490.          this.aBalls[_loc4_].onLevelEnded();
  491.          this.aBalls.splice(Number(_loc4_),1);
  492.       }
  493.       for(_loc4_ in this.aBlocks)
  494.       {
  495.          this.aEndLevelElements.push({oObj:this.aBlocks[_loc4_],bExploded:false});
  496.          this.aBlocks[_loc4_].onLevelEnded();
  497.          this.aBlocks.splice(Number(_loc4_),1);
  498.       }
  499.       this.bPaddleEndMoveComplete = false;
  500.       this.oMainPaddle.onLevelEnded();
  501.       this.oPixies.doHide();
  502.    }
  503.    function doPutInFront(_mc)
  504.    {
  505.       do
  506.       {
  507.          this.nNextFrontDepth = this.nNextFrontDepth + 1;
  508.          if(this.nNextFrontDepth > LevelManager.nDEPTH_FRONT_MAX)
  509.          {
  510.             this.nNextFrontDepth = LevelManager.nDEPTH_FRONT_MIN;
  511.          }
  512.       }
  513.       while(_mc._parent.getInstanceAtDepth(this.nNextFrontDepth) != undefined);
  514.       
  515.       _mc.swapDepths(this.nNextFrontDepth);
  516.    }
  517.    function doDestroy()
  518.    {
  519.       for(var _loc2_ in this.aBalls)
  520.       {
  521.          this.aBalls[_loc2_].doDestroy();
  522.          this.aBalls.splice(Number(_loc2_),1);
  523.       }
  524.       for(_loc2_ in this.aBlocks)
  525.       {
  526.          this.aBlocks[_loc2_].doDestroy();
  527.          this.aBlocks.splice(Number(_loc2_),1);
  528.       }
  529.       delete this.aBalls;
  530.       delete this.aBlocks;
  531.       delete LevelManager.oCtrl;
  532.       this.oMainPaddle.doDestroy();
  533.       delete this.oMainPaddle;
  534.       this.oMainBall.doDestroy();
  535.       delete this.oMainBall;
  536.       this.oPixies.doDestroy();
  537.       delete this.oPixies;
  538.       Game.Instance.doRemoveListener(this);
  539.    }
  540.    function get GameStarted()
  541.    {
  542.       return this.nGameState == LevelManager.nGAME_STATE_PLAYING;
  543.    }
  544.    function get Blocks()
  545.    {
  546.       return Library.Utils.Tools.doCopyArray(this.aBlocks);
  547.    }
  548.    function get MainPaddle()
  549.    {
  550.       return this.oMainPaddle;
  551.    }
  552.    function get GameStage()
  553.    {
  554.       return this.mcRef;
  555.    }
  556.    function get RemoveDepth()
  557.    {
  558.       do
  559.       {
  560.          this.nNextRemoveDepth = this.nNextRemoveDepth + 1;
  561.          if(this.nNextRemoveDepth > LevelManager.nDEPTH_REMOVE_MAX)
  562.          {
  563.             this.nNextRemoveDepth = LevelManager.nDEPTH_REMOVE_MIN;
  564.          }
  565.       }
  566.       while(this.mcRef.getInstanceAtDepth(this.nNextRemoveDepth) != undefined);
  567.       
  568.       return this.nNextRemoveDepth;
  569.    }
  570.    function onDropDownComplete()
  571.    {
  572.       this.nGameState = LevelManager.nGAME_STATE_PLAYING;
  573.       this.oMainPaddle.doGetBall();
  574.    }
  575.    function doLevelEndExplode()
  576.    {
  577.       if(this.aEndLevelElements.length > 0)
  578.       {
  579.          var _loc2_ = new Array();
  580.          for(var _loc3_ in this.aEndLevelElements)
  581.          {
  582.             if(!this.aEndLevelElements[_loc3_].bExploded)
  583.             {
  584.                _loc2_.push(this.aEndLevelElements[_loc3_]);
  585.             }
  586.          }
  587.          var _loc5_ = Library.Utils.MoreMath.getRandomRange(0,_loc2_.length - 1);
  588.          var _loc4_ = _loc2_[_loc5_];
  589.          if(_loc4_ != undefined)
  590.          {
  591.             _loc4_.oObj.doLevelEndedAnim();
  592.             _loc4_.bExploded = true;
  593.          }
  594.       }
  595.    }
  596.    function doDropDownMotion()
  597.    {
  598.       if(this.aDropDownElements.length > 0)
  599.       {
  600.          var _loc3_ = new Array();
  601.          var _loc2_ = -Infinity;
  602.          for(var _loc4_ in this.aDropDownElements)
  603.          {
  604.             if(!this.aDropDownElements[_loc4_].bMoving)
  605.             {
  606.                if(this.aDropDownElements[_loc4_].oObj.Bounds.yMax > _loc2_)
  607.                {
  608.                   _loc2_ = this.aDropDownElements[_loc4_].oObj.Bounds.yMax;
  609.                }
  610.             }
  611.          }
  612.          for(_loc4_ in this.aDropDownElements)
  613.          {
  614.             if(!this.aDropDownElements[_loc4_].bMoving)
  615.             {
  616.                if(Math.abs(this.aDropDownElements[_loc4_].oObj.Bounds.yMax - _loc2_) <= LevelManager.nDROPDOWN_LINE_BUFFER)
  617.                {
  618.                   _loc3_.push(this.aDropDownElements[_loc4_]);
  619.                }
  620.             }
  621.          }
  622.          var _loc6_ = Library.Utils.MoreMath.getRandomRange(0,_loc3_.length - 1);
  623.          var _loc5_ = _loc3_[_loc6_];
  624.          if(_loc5_ != undefined)
  625.          {
  626.             _loc5_.oObj.onStartDropDownMove();
  627.             _loc5_.bMoving = true;
  628.          }
  629.          else
  630.          {
  631.             this.bDropDownMotion = false;
  632.          }
  633.       }
  634.       else
  635.       {
  636.          this.bDropDownMotion = false;
  637.       }
  638.    }
  639.    function doCreatePixies()
  640.    {
  641.       this.oPixies.doShow();
  642.       this.bPixiesVisible = true;
  643.       this.oPixiesVisibleTimer = new Library.Utils.Timer();
  644.       this.oPixiesVisibleTimer.Method = Library.Utils.Timer.TIMER_COUNT_DOWN;
  645.       this.doAddListener(this.oPixiesVisibleTimer);
  646.       this.oPixiesVisibleTimer.setTime(LevelDesignItem.nPOWERDOWN_PIXIES_TIME);
  647.       this.oPixiesVisibleTimer.doStartTimer();
  648.    }
  649.    function doCheckLevelEnd()
  650.    {
  651.       var _loc2_ = true;
  652.       for(var _loc3_ in this.aBlocks)
  653.       {
  654.          if(!this.aBlocks[_loc3_].NeverDies)
  655.          {
  656.             _loc2_ = false;
  657.          }
  658.       }
  659.       if(_loc2_)
  660.       {
  661.          if(this.aItems.length <= 0)
  662.          {
  663.             this.nGameState = LevelManager.nGAME_STATE_END_WON_COUNTDOWN;
  664.             this.nEndCountDown = LevelManager.nEND_COUNTDOWN;
  665.             this.doNewEndingWord();
  666.          }
  667.          else
  668.          {
  669.             this.nGameState = LevelManager.nGAME_STATE_WAIT_END_ITEMS_REMAIN;
  670.          }
  671.       }
  672.    }
  673.    function doDeleteBlock(_oBlock)
  674.    {
  675.       for(var _loc2_ in this.aBlocks)
  676.       {
  677.          if(this.aBlocks[_loc2_] == _oBlock)
  678.          {
  679.             delete this.aBlocks[_loc2_];
  680.             this.aBlocks.splice(Number(_loc2_),1);
  681.          }
  682.       }
  683.    }
  684.    function doDeleteBall(_oBall)
  685.    {
  686.       for(var _loc3_ in this.aBalls)
  687.       {
  688.          if(this.aBalls[_loc3_] == _oBall)
  689.          {
  690.             this.aBalls.splice(Number(_loc3_),1);
  691.          }
  692.       }
  693.    }
  694.    function doDeleteItem(_oItem)
  695.    {
  696.       for(var _loc3_ in this.aItems)
  697.       {
  698.          if(this.aItems[_loc3_] == _oItem)
  699.          {
  700.             delete this.aItems[_loc3_];
  701.             this.aItems.splice(Number(_loc3_),1);
  702.          }
  703.       }
  704.    }
  705.    function doCheckActiveModifiers()
  706.    {
  707.       if(this.bBallSpeedUp)
  708.       {
  709.          if(this.oBallSpeedUpTimer.Time <= 0)
  710.          {
  711.             this.bBallSpeedUp = false;
  712.             this.doRemoveListener(this.oBallSpeedUpTimer);
  713.             delete this.oBallSpeedUpTimer;
  714.             for(var _loc2_ in this.aBalls)
  715.             {
  716.                this.aBalls[_loc2_].doAffectSpeed(- LevelDesignItem.nPOWERDOWN_ROCKET_SPEED);
  717.             }
  718.          }
  719.       }
  720.       if(this.bPixiesVisible)
  721.       {
  722.          if(this.oPixiesVisibleTimer.Time <= 0)
  723.          {
  724.             this.bPixiesVisible = false;
  725.             this.doRemoveListener(this.oPixiesVisibleTimer);
  726.             delete this.oPixiesVisibleTimer;
  727.             this.oPixies.doHide();
  728.          }
  729.       }
  730.    }
  731.    function onInitLevel()
  732.    {
  733.       this.nGameState = LevelManager.nGAME_STATE_DROP_DOWN_MOTION;
  734.       var _loc2_ = this.GameStage.attachMovie("mcPaddle","mcPaddle",LevelManager.nMAIN_PADDLE_DEPTH);
  735.       _loc2_._x = LevelManager.nMAIN_PADDLE_START_X;
  736.       _loc2_._y = LevelManager.nMAIN_PADDLE_START_Y;
  737.       this.oMainPaddle = new PlayerPaddle(_loc2_);
  738.       this.aPaddles.push(this.oMainPaddle);
  739.       var _loc4_ = this.mcRef.attachMovie("mcPixies_1","mcPixies_1",LevelManager.nPIXIES_DEPTH_START);
  740.       var _loc3_ = this.mcRef.attachMovie("mcPixies_2","mcPixies_2",LevelManager.nPIXIES_DEPTH_START + 1);
  741.       this.oPixies = new PixiesGroup(_loc4_,_loc3_);
  742.    }
  743. }
  744.