home *** CD-ROM | disk | FTP | other *** search
- class Main extends Library.DispatcherBase
- {
- var mcRef;
- var oHS;
- var nLatestScore;
- var bHSScrolling;
- var oTransition;
- var oHSInGame;
- var oHSWin;
- var oHSLose;
- var nHSScrollChange;
- var bGameFromReset;
- var bHSFromTitle;
- var bHSAlreadySubmitted;
- var oGame;
- var sCurrentSection;
- var sTargetSection;
- var oMusicPack;
- var oIntroManager;
- var oTitleManager;
- static var oCtrl;
- static var nSOUND_VOL_SOUND = 100;
- static var nSOUND_VOL_MUSIC = 35;
- static var sSOUND_CAT_SOUND = "SFX";
- static var sSOUND_CAT_MUSIC = "Music";
- static var nFRAME_RATE = 36;
- static var sSECTION_INTRO = "Intro";
- static var sSECTION_TITLE = "Title";
- static var sSECTION_GAME = "Game";
- static var sSECTION_GAMERESET = "GameReset";
- function Main(_mcRef)
- {
- super();
- this.mcRef = _mcRef;
- Main.oCtrl = this;
- this.oHS = new NickHS("fop_break",true,false);
- this.nLatestScore = 0;
- this.bHSScrolling = false;
- this.mcRef.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
- Library.Sound.SoundManager.doInit(this.mcRef);
- Library.Sound.SoundManager.setCategoryVolume(Main.sSOUND_CAT_SOUND,Main.nSOUND_VOL_SOUND);
- Library.Sound.SoundManager.setCategoryVolume(Main.sSOUND_CAT_MUSIC,Main.nSOUND_VOL_MUSIC);
- this.doStartPackMusic();
- this.oTransition = new Library.Transition(this.mcRef.mcTransition);
- this.oTransition.Listener = this;
- this.doAddListener(this.oTransition);
- this.oHSInGame = new Library.BasicPopUp(this.mcRef.mcHighScoresNormal,true);
- this.oHSInGame.Listener = this;
- this.doAddListener(this.oHSInGame);
- this.oHSWin = new Library.BasicPopUp(this.mcRef.mcHighScoresWin,true);
- this.oHSWin.Listener = this;
- this.doAddListener(this.oHSWin);
- this.oHSLose = new Library.BasicPopUp(this.mcRef.mcHighScoresLose,true);
- this.oHSLose.Listener = this;
- this.doAddListener(this.oHSLose);
- this.doStartPackMusic();
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Game_Start.wav");
- this.doSetSection(Main.sSECTION_INTRO);
- }
- static function get Instance()
- {
- return Main.oCtrl;
- }
- function get StageRoot()
- {
- return this.mcRef;
- }
- function doEnterFrame()
- {
- super.doEnterFrame();
- if(this.bHSScrolling)
- {
- this.oHSInGame.Ref.mcHS.txtHSNumber.scroll = this.oHSInGame.Ref.mcHS.txtHSNumber.scroll + this.nHSScrollChange;
- this.oHSInGame.Ref.mcHS.txtHSName.scroll = this.oHSInGame.Ref.mcHS.txtHSName.scroll + this.nHSScrollChange;
- this.oHSInGame.Ref.mcHS.txtHSScore.scroll = this.oHSInGame.Ref.mcHS.txtHSScore.scroll + this.nHSScrollChange;
- this.oHSWin.Ref.mcHS.txtHSNumber.scroll = this.oHSWin.Ref.mcHS.txtHSNumber.scroll + this.nHSScrollChange;
- this.oHSWin.Ref.mcHS.txtHSName.scroll = this.oHSWin.Ref.mcHS.txtHSName.scroll + this.nHSScrollChange;
- this.oHSWin.Ref.mcHS.txtHSScore.scroll = this.oHSWin.Ref.mcHS.txtHSScore.scroll + this.nHSScrollChange;
- this.oHSLose.Ref.mcHS.txtHSNumber.scroll = this.oHSLose.Ref.mcHS.txtHSNumber.scroll + this.nHSScrollChange;
- this.oHSLose.Ref.mcHS.txtHSName.scroll = this.oHSLose.Ref.mcHS.txtHSName.scroll + this.nHSScrollChange;
- this.oHSLose.Ref.mcHS.txtHSScore.scroll = this.oHSLose.Ref.mcHS.txtHSScore.scroll + this.nHSScrollChange;
- }
- }
- function doCloseHSIfOpen()
- {
- if(this.oHSInGame.CurrentState == "Idle")
- {
- this.doResumeFromInGameHS();
- }
- }
- function onIntroFirstPartOver()
- {
- this.doTransitionTo(Main.sSECTION_TITLE);
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Transition.mp3",60);
- }
- function onTitleCardComplete()
- {
- this.bGameFromReset = false;
- this.doSetSection(Main.sSECTION_GAME);
- }
- function doRollSound()
- {
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Mouse_Rollover.mp3",55,1,true);
- }
- function doClickSound()
- {
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Mouse_Click.mp3",60,1,true);
- }
- function onPlayerLose()
- {
- this.bHSFromTitle = false;
- this.bHSAlreadySubmitted = false;
- this.nLatestScore = this.oGame.Status.Score;
- _root.micro = this.nLatestScore;
- this.oGame.doPause();
- this.oHSLose.doOpen();
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Transition.mp3",60);
- this.doStartPackMusic();
- Game.Instance.doStopMusic();
- }
- function onPlayerWin()
- {
- this.bHSFromTitle = false;
- this.bHSAlreadySubmitted = false;
- this.nLatestScore = this.oGame.Status.Score;
- _root.micro = this.nLatestScore;
- this.oGame.doPause();
- this.oHSWin.doOpen();
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Transition.mp3",60);
- this.doStartPackMusic();
- Game.Instance.doStopMusic();
- }
- function onTransitionEvent(_nEvent, _oTransition)
- {
- switch(_nEvent)
- {
- case Library.Transition.TRANSITION_SCREEN_COVERED:
- this.doUnloadSection(this.sCurrentSection);
- this.doSetSection(this.sTargetSection);
- break;
- case Library.Transition.TRANSITION_COMPLETE:
- }
- }
- function onPopUpEvent(_nEvent, _oPopUp)
- {
- var _loc0_ = null;
- if((_loc0_ = _nEvent) === Library.BasicPopUp.NEED_UPDATE)
- {
- switch(_oPopUp)
- {
- case this.oHSInGame:
- this.doUpdateInGameHS();
- break;
- case this.oHSLose:
- this.doUpdateLoseHS();
- break;
- case this.oHSWin:
- this.doUpdateWinHS();
- }
- }
- }
- function doSubmitScoreFromLose()
- {
- _root.micro = this.nLatestScore;
- this.oHS.bSubmitHS = false;
- this.oHS.submitScore(this.nLatestScore);
- this.bHSAlreadySubmitted = true;
- this.oHSLose.Ref.mcButtons.btnSubmitHS._visible = true;
- }
- function doSubmitScoreFromWin()
- {
- _root.micro = this.nLatestScore;
- this.oHS.bSubmitHS = false;
- this.oHS.submitScore(this.nLatestScore);
- this.bHSAlreadySubmitted = true;
- this.oHSWin.Ref.mcButtons.btnSubmitHS._visible = true;
- }
- function doPlayAgainFromLose()
- {
- this.oHSLose.doClose();
- this.doUnloadSection(Main.sSECTION_GAME);
- this.doSetSection(Main.sSECTION_GAMERESET);
- }
- function doPlayAgainFromWin()
- {
- this.oHSWin.doClose();
- this.doUnloadSection(Main.sSECTION_GAME);
- this.doSetSection(Main.sSECTION_GAMERESET);
- }
- function doResumeFromInGameHS()
- {
- this.oHSInGame.doClose();
- }
- function doShowInGameHS()
- {
- this.bHSFromTitle = true;
- this.oHSInGame.doOpen();
- }
- function doStopScrollHsList()
- {
- this.bHSScrolling = false;
- }
- function doStartScrollHsList(_nChange)
- {
- this.bHSScrolling = true;
- this.nHSScrollChange = _nChange;
- }
- function doSoundEvent(__nEvent, __oSound)
- {
- var _loc0_ = null;
- if((_loc0_ = __nEvent) === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
- {
- if(__oSound == this.oMusicPack)
- {
- delete this.oMusicPack;
- }
- }
- }
- function doStartPackMusic()
- {
- if(this.oMusicPack == undefined)
- {
- this.oMusicPack = Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_MUSIC,"Music_Pack.wav",0,999999);
- this.oMusicPack.doAddListener(this);
- }
- this.oMusicPack.doFadeTo(100);
- }
- function doStopPackMusic()
- {
- if(this.oMusicPack != undefined)
- {
- this.oMusicPack.doFadeTo(0);
- }
- }
- function doSetUpSharedHS(_mcRef, _oOriginHS)
- {
- this.oHS.setHSBoard(_mcRef.mcHS);
- if(_oOriginHS.CurrentState == "Idle")
- {
- this.oHS.getScores();
- }
- _mcRef.btnHaut.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,-1);
- _mcRef.btnBas.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,1);
- _mcRef.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
- _mcRef.btnHaut.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
- _mcRef.btnHaut.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
- _mcRef.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
- _mcRef.btnBas.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
- _mcRef.btnBas.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
- _mcRef.mcScore.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nLatestScore,6);
- }
- function doUpdateInGameHS()
- {
- this.doSetUpSharedHS(this.oHSInGame.Ref,this.oHSInGame);
- this.oHSInGame.Ref.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doResumeFromInGameHS);
- }
- function doUpdateLoseHS()
- {
- this.doSetUpSharedHS(this.oHSLose.Ref,this.oHSLose);
- this.oHSLose.Ref.mcButtons.btnSubmitHS._visible = this.oHS.getIsLoggedIn() && !this.bHSAlreadySubmitted;
- this.oHSLose.Ref.mcButtons.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitScoreFromLose);
- this.oHSLose.Ref.mcButtons.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doPlayAgainFromLose);
- }
- function doUpdateWinHS()
- {
- this.doSetUpSharedHS(this.oHSWin.Ref,this.oHSWin);
- this.oHSWin.Ref.mcButtons.btnSubmitHS._visible = this.oHS.getIsLoggedIn() && !this.bHSAlreadySubmitted;
- this.oHSWin.Ref.mcButtons.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitScoreFromWin);
- this.oHSWin.Ref.mcButtons.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doPlayAgainFromWin);
- }
- function doCreateGame()
- {
- this.oGame = new Game(this.mcRef.mcGameScreen);
- }
- function doUnloadGame()
- {
- this.oGame.doDestroy();
- }
- function doSetSection(_sSection)
- {
- this.sCurrentSection = _sSection;
- this.mcRef.gotoAndStop(this.sCurrentSection);
- switch(this.sCurrentSection)
- {
- case Main.sSECTION_INTRO:
- this.oIntroManager = new Intro(this.mcRef.mcState);
- break;
- case Main.sSECTION_TITLE:
- this.oTitleManager = new TitleCard(this.mcRef.mcState);
- this.doCreateGame();
- this.bGameFromReset = false;
- break;
- case Main.sSECTION_GAMERESET:
- this.bGameFromReset = true;
- this.doSetSection(Main.sSECTION_GAME);
- break;
- case Main.sSECTION_GAME:
- if(this.bGameFromReset)
- {
- this.doCreateGame();
- }
- this.oGame.onBeginGame();
- }
- }
- function doUnloadSection(_sSection)
- {
- switch(_sSection)
- {
- case Main.sSECTION_INTRO:
- delete this.oIntroManager;
- break;
- case Main.sSECTION_GAME:
- this.doUnloadGame();
- break;
- case Main.sSECTION_TITLE:
- delete this.oTitleManager;
- }
- }
- function doTransitionTo(_sSection)
- {
- this.sTargetSection = _sSection;
- this.oTransition.doStart();
- }
- }
-