home *** CD-ROM | disk | FTP | other *** search
- class Block extends BaseObject
- {
- var nCurrentStep;
- var aItems;
- var nNeverDiesMaxStep;
- var bLevelEnded;
- var mcRef;
- static var sSTATE_IDLE = "Idle";
- static var sSTATE_OUT = "Out";
- static var nBLOCK_BOUNCE_AMPLITUDE = 35;
- static var nNEVER_DIE_MAX_STEPS = 6;
- function Block(_mcRef, _nSteps)
- {
- super(_mcRef);
- this.nCurrentStep = _nSteps;
- this.aItems = new Array();
- if(!this.NeverDies)
- {
- this.setState(Block.sSTATE_IDLE + this.nCurrentStep);
- }
- else
- {
- this.nNeverDiesMaxStep = Block.nNEVER_DIE_MAX_STEPS;
- this.setState("Idle");
- }
- LevelManager.Instance.doAddListener(this);
- }
- function doEnterFrame()
- {
- super.doEnterFrame();
- }
- function onBoltHit()
- {
- if(!this.bLevelEnded)
- {
- this.onCrushed();
- }
- }
- function onBallHit(_oBall, _nSideUsedForHit)
- {
- if(!this.NeverDies)
- {
- this.nCurrentStep = this.nCurrentStep - 1;
- if(this.nCurrentStep > 0)
- {
- this.setState(Block.sSTATE_IDLE + this.nCurrentStep);
- this.doBounce(Block.nBLOCK_BOUNCE_AMPLITUDE,Block.nBLOCK_BOUNCE_AMPLITUDE);
- var _loc2_ = Library.Sound.SoundManager.isSoundPlaying("Block_Hit.mp3");
- if(_loc2_.bPlaying)
- {
- _loc2_.oSound.doStop();
- _loc2_.oSound.doStart();
- }
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Block_Hit.mp3",100,1,true);
- Game.Instance.Status.onBlockHit();
- }
- else
- {
- this.onCrushed();
- }
- }
- else if(!(_oBall instanceof ShootingStar))
- {
- this.nNeverDiesMaxStep = this.nNeverDiesMaxStep - 1;
- if(this.nNeverDiesMaxStep > 0)
- {
- this.doBounce(Block.nBLOCK_BOUNCE_AMPLITUDE,Block.nBLOCK_BOUNCE_AMPLITUDE);
- _loc2_ = Library.Sound.SoundManager.isSoundPlaying("Block_NeverDies_Hit.mp3");
- if(_loc2_.bPlaying)
- {
- _loc2_.oSound.doStop();
- _loc2_.oSound.doStart();
- }
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Block_NeverDies_Hit.mp3",100,1,true);
- }
- else
- {
- this.onCrushed();
- }
- }
- }
- function doAddItem(_nItemType)
- {
- this.aItems.push(_nItemType);
- }
- function doDestroy()
- {
- LevelManager.Instance.doRemoveListener(this);
- super.doDestroy();
- }
- function get NeverDies()
- {
- return this.nCurrentStep == Infinity;
- }
- function get StillAlive()
- {
- return this.nCurrentStep > 0;
- }
- function get BonusAssigned()
- {
- return this.aItems.length != 0;
- }
- function doOut()
- {
- if(this.isStateComplete())
- {
- this.doDestroy();
- }
- }
- function onCrushed()
- {
- LevelManager.Instance.doPutInFront(this.mcRef);
- this.setState(Block.sSTATE_OUT);
- var _loc2_ = Library.Sound.SoundManager.isSoundPlaying("Block_Break.mp3");
- if(_loc2_.bPlaying)
- {
- _loc2_.oSound.doStop();
- _loc2_.oSound.doStart();
- }
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Block_Break.mp3",40,1,true);
- this.onReleaseBonuses();
- Game.Instance.Status.onBlockCrushed();
- LevelManager.Instance.onBlockCrushed(this);
- }
- function onReleaseBonuses()
- {
- if(this.aItems.length > 0)
- {
- for(var _loc3_ in this.aItems)
- {
- var _loc2_ = this.aItems[_loc3_];
- LevelManager.Instance.doAddItemAt(this.Ref._x,this.Ref._y,_loc2_);
- }
- var _loc4_ = Library.Sound.SoundManager.isSoundPlaying("Bonus_Release.mp3");
- if(_loc4_.bPlaying)
- {
- _loc4_.oSound.doStop();
- }
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bonus_Release.mp3",100,1,true);
- }
- }
- }
-