home *** CD-ROM | disk | FTP | other *** search
- class Game extends Library.DispatcherBase
- {
- var mcRef;
- var bFirstPlay;
- var bShowHint;
- var nFrameHint;
- var oMenuPopUp;
- var oHelpPopUp;
- var oConfirmPopUp;
- var oHintPopUp;
- var oPlayerStatus;
- var oGameTimer;
- var nBGTargetPosition;
- var bMoveBG;
- var oHelpKeyManager;
- var oEE;
- var nHintHideDelay;
- var oLevel;
- var sCurrentSection;
- var sTargetSection;
- var oMusicGame;
- static var oCtrl;
- static var sSECTION_EMPTY = "Empty";
- static var sSECTION_GAME = "Game";
- static var nHINT_HIDE_DELAY = 75;
- static var nSPEED_BACKGROUND_MOVE = 12;
- function Game(_mcRef)
- {
- super();
- this.mcRef = _mcRef;
- Game.oCtrl = this;
- this.bFirstPlay = true;
- this.bShowHint = true;
- this.nFrameHint = 1;
- this.oMenuPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcMenu,true);
- this.oMenuPopUp.Listener = this;
- Main.Instance.doAddListener(this.oMenuPopUp);
- this.oHelpPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcHelp,true);
- this.oHelpPopUp.Listener = this;
- Main.Instance.doAddListener(this.oHelpPopUp);
- this.oConfirmPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcConfirm,true);
- this.oConfirmPopUp.Listener = this;
- Main.Instance.doAddListener(this.oConfirmPopUp);
- this.oHintPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcHints,false);
- this.oHintPopUp.Listener = this;
- this.doAddListener(this.oHintPopUp);
- this.oHintPopUp.doHide();
- this.oPlayerStatus = new PlayerStatus();
- this.oPlayerStatus.setHud(this.mcRef.mcHud);
- this.oGameTimer = new Library.Utils.Timer();
- this.oGameTimer.FrameRate = Main.nFRAME_RATE;
- this.oGameTimer.Method = Library.Utils.Timer.TIMER_COUNT_UP;
- this.doAddListener(this.oGameTimer);
- Main.Instance.doAddListener(this);
- this.nBGTargetPosition = this.mcRef.mcBackgrounds._y;
- this.bMoveBG = false;
- this.oHelpKeyManager = new Library.Utils.KeysManager();
- this.oHelpKeyManager.setListenerForKey(this,32);
- this.oHelpKeyManager.setListenerForKey(this,69);
- this.oEE = new EE(this.mcRef.mcEE);
- this.doSetSection(Game.sSECTION_EMPTY);
- }
- static function get Instance()
- {
- return Game.oCtrl;
- }
- function onKeyManagerEvent(_nEvent, _nCode)
- {
- switch(_nEvent)
- {
- case Library.Utils.KeysManager.EVENT_KEY_DOWN:
- if(_nCode !== 32)
- {
- }
- break;
- case Library.Utils.KeysManager.EVENT_KEY_UP:
- switch(_nCode)
- {
- case 69:
- this.oEE.doStart();
- break;
- case 32:
- if(this.oHelpPopUp.CurrentState == "Idle")
- {
- this.doCloseHelp();
- }
- Main.Instance.doCloseHSIfOpen();
- }
- }
- }
- function doEnterFrame()
- {
- super.doEnterFrame();
- this.nHintHideDelay = this.nHintHideDelay - 1;
- if(this.nHintHideDelay == 0)
- {
- this.oHintPopUp.doClose();
- }
- if(this.bMoveBG)
- {
- this.doMoveBG();
- }
- }
- function onPlayerCatchItem(_nItemFrame)
- {
- this.nFrameHint = _nItemFrame;
- this.oHintPopUp.Ref.gotoAndStop(this.nFrameHint);
- if(this.oHintPopUp.CurrentState != "Idle" && this.bShowHint)
- {
- this.oHintPopUp.doOpen();
- }
- this.nHintHideDelay = Game.nHINT_HIDE_DELAY;
- }
- function onBeginGame()
- {
- this.doSetSection(Game.sSECTION_GAME);
- }
- function onConfirmAnswer(_bAnswer)
- {
- if(_bAnswer)
- {
- Main.Instance.onPlayerLose();
- }
- this.oConfirmPopUp.doClose();
- }
- function doLevelEnd(_bWon)
- {
- this.oGameTimer.doStopTimer();
- this.oLevel.doPause();
- if(_bWon)
- {
- Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Level_Completed.mp3",125);
- this.oPlayerStatus.onPlayerCompleteLevel(this.oGameTimer.Time);
- if(this.oPlayerStatus.getIsMoreLevelToPlay())
- {
- this.doSetSection(Game.sSECTION_EMPTY);
- }
- else
- {
- Main.Instance.onPlayerWin();
- }
- }
- else
- {
- Main.Instance.onPlayerLose();
- }
- }
- 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)
- {
- if(_nEvent === Library.BasicPopUp.NEED_UPDATE)
- {
- switch(_oPopUp)
- {
- case this.oHelpPopUp:
- this.doUpdateHelpPopUp();
- break;
- case this.oHintPopUp:
- this.oHintPopUp.Ref.gotoAndStop(this.nFrameHint);
- break;
- case this.oMenuPopUp:
- this.doUpdateMenuPopUp();
- break;
- case this.oConfirmPopUp:
- this.doUpdateConfirmPopUp();
- }
- }
- }
- function doSoundEvent(_nEvent, _oSound)
- {
- if(_nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
- {
- if(_oSound == this.oMusicGame)
- {
- delete this.oMusicGame;
- }
- }
- }
- function doToggleShowHint()
- {
- this.bShowHint = !this.bShowHint;
- this.doUpdateHintGroups();
- if(!this.bShowHint && this.oHintPopUp.CurrentState != "Hidden")
- {
- this.oHintPopUp.doClose();
- }
- }
- function doToggleMuteFor(_sCategory)
- {
- if(Library.Sound.SoundManager.isCategoryMuted(_sCategory))
- {
- Library.Sound.SoundManager.doUnMuteCategory(_sCategory);
- }
- else
- {
- Library.Sound.SoundManager.doMuteCategory(_sCategory);
- }
- this.doUpdateMenuSoundGroups();
- }
- function doShowMenu()
- {
- this.oLevel.doPause();
- this.oMenuPopUp.doOpen();
- this.oGameTimer.doStopTimer();
- }
- function doCloseMenu()
- {
- this.oLevel.doResume();
- this.oMenuPopUp.doClose();
- this.oGameTimer.doStartTimer();
- }
- function doCloseHelp()
- {
- this.oHelpPopUp.doClose();
- }
- function doShowHelp()
- {
- this.oHelpPopUp.doOpen();
- }
- function doViewHS()
- {
- Main.Instance.doShowInGameHS();
- }
- function doQuitGame()
- {
- this.oConfirmPopUp.doOpen();
- }
- function doDestroy()
- {
- this.oLevel.doDestroy();
- delete this.oLevel;
- Main.Instance.doRemoveListener(this);
- delete this.oGameTimer;
- this.oMenuPopUp.doHide();
- this.oMenuPopUp.doDestroy();
- delete this.oMenuPopUp;
- this.oHelpPopUp.doDestroy();
- delete this.oHelpPopUp;
- this.oHintPopUp.doDestroy();
- delete this.oHintPopUp;
- this.oConfirmPopUp.doDestroy();
- delete this.oConfirmPopUp;
- this.oHelpKeyManager.doDestroy();
- delete this.oHelpKeyManager;
- this.doStopMusic();
- Main.Instance.doStartPackMusic();
- this.oMusicGame.doDestroy();
- delete Game.oCtrl;
- this.oPlayerStatus;
- }
- function get Status()
- {
- return this.oPlayerStatus;
- }
- function doUpdateHelpPopUp()
- {
- this.oHelpPopUp.Ref.btnResume.onRelease = Library.Utils.Delegate.create(this,this.doCloseHelp);
- }
- function doUpdateConfirmPopUp()
- {
- this.oConfirmPopUp.Ref.btnYes.onRelease = Library.Utils.Delegate.create(this,this.onConfirmAnswer,true);
- this.oConfirmPopUp.Ref.btnNo.onRelease = Library.Utils.Delegate.create(this,this.onConfirmAnswer,false);
- }
- function doUpdateMenuPopUp()
- {
- this.oMenuPopUp.Ref.btnViewHS.onRelease = Library.Utils.Delegate.create(this,this.doViewHS);
- this.oMenuPopUp.Ref.btnResume.onRelease = Library.Utils.Delegate.create(this,this.doCloseMenu);
- this.oMenuPopUp.Ref.btnHelp.onRelease = Library.Utils.Delegate.create(this,this.doShowHelp);
- this.oMenuPopUp.Ref.btnQuit.onRelease = Library.Utils.Delegate.create(this,this.doQuitGame);
- this.doUpdateMenuSoundGroups();
- this.doUpdateHintGroups();
- }
- function doUpdateHintGroups()
- {
- var _loc2_ = "On";
- if(!this.bShowHint)
- {
- _loc2_ = "Off";
- }
- this.oMenuPopUp.Ref.mcHintToggle.gotoAndStop(_loc2_);
- this.oMenuPopUp.Ref.mcHintToggle.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.doToggleShowHint);
- }
- function doUpdateMenuSoundGroups()
- {
- var _loc2_ = "On";
- if(Library.Sound.SoundManager.isCategoryMuted(Main.sSOUND_CAT_SOUND))
- {
- _loc2_ = "Off";
- }
- var _loc3_ = "On";
- if(Library.Sound.SoundManager.isCategoryMuted(Main.sSOUND_CAT_MUSIC))
- {
- _loc3_ = "Off";
- }
- this.oMenuPopUp.Ref.mcSoundToggle.gotoAndStop(_loc2_);
- this.oMenuPopUp.Ref.mcMusicToggle.gotoAndStop(_loc3_);
- this.oMenuPopUp.Ref.mcSoundToggle.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.doToggleMuteFor,Main.sSOUND_CAT_SOUND);
- this.oMenuPopUp.Ref.mcMusicToggle.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.doToggleMuteFor,Main.sSOUND_CAT_MUSIC);
- }
- function doCreateLevel()
- {
- var _loc2_ = this.oPlayerStatus.getLevelToPlay();
- this.doSetBGPosition(_loc2_);
- _loc2_ += 1;
- this.oLevel = new LevelManager(this.mcRef.mcGame,_loc2_);
- this.mcRef.mcHud.btnMenu.onRelease = Library.Utils.Delegate.create(this,this.doShowMenu);
- this.oGameTimer.setTime(PlayerStatus.nTIME_FOR_EXTRA_POINTS);
- this.oGameTimer.doStartTimer();
- Main.Instance.doStopPackMusic();
- this.doStartMusic();
- if(this.bFirstPlay)
- {
- this.oHelpPopUp.doOpen();
- }
- this.bFirstPlay = false;
- }
- function doStartMusic()
- {
- if(this.oMusicGame == undefined)
- {
- this.oMusicGame = Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_MUSIC,"Music_Game.wav",0,999999);
- this.oMusicGame.doAddListener(this);
- this.oMusicGame.setFadeRate(8);
- }
- this.oMusicGame.doFadeTo(100);
- }
- function doStopMusic()
- {
- if(this.oMusicGame != undefined)
- {
- this.oMusicGame.setFadeRate(8);
- this.oMusicGame.doFadeTo(0);
- }
- }
- function doSetBGPosition(_nLevelToPlay)
- {
- var _loc2_ = undefined;
- switch(_nLevelToPlay)
- {
- case 1:
- case 2:
- case 3:
- _loc2_ = -3998;
- break;
- case 4:
- case 5:
- _loc2_ = -3500;
- break;
- case 6:
- case 7:
- _loc2_ = -3040;
- break;
- case 8:
- case 9:
- _loc2_ = -2680;
- break;
- case 10:
- case 11:
- _loc2_ = -2220;
- break;
- case 12:
- case 13:
- _loc2_ = -1700;
- break;
- case 14:
- case 15:
- _loc2_ = -1220;
- break;
- case 16:
- case 17:
- _loc2_ = -490;
- break;
- case 18:
- case 19:
- case 20:
- _loc2_ = -10;
- }
- if(this.nBGTargetPosition != _loc2_)
- {
- this.nBGTargetPosition = _loc2_;
- this.bMoveBG = true;
- }
- }
- function doMoveBG()
- {
- var _loc2_ = this.nBGTargetPosition - this.mcRef.mcBackgrounds._y;
- var _loc3_ = Library.Utils.MoreMath.getPolarity(_loc2_);
- if(Math.abs(_loc2_) > Game.nSPEED_BACKGROUND_MOVE)
- {
- var _loc4_ = _loc3_ * Game.nSPEED_BACKGROUND_MOVE;
- this.mcRef.mcBackgrounds._y += _loc4_;
- }
- else
- {
- this.mcRef.mcBackgrounds._y = this.nBGTargetPosition;
- }
- }
- function doUnloadLevel()
- {
- this.oLevel.doDestroy();
- delete this.oLevel;
- }
- function doSetSection(_sSection)
- {
- this.sCurrentSection = _sSection;
- this.mcRef.gotoAndStop(this.sCurrentSection);
- switch(this.sCurrentSection)
- {
- case Game.sSECTION_GAME:
- this.doCreateLevel();
- break;
- case Game.sSECTION_EMPTY:
- if(!this.bFirstPlay)
- {
- this.doSetSection(Game.sSECTION_GAME);
- }
- }
- }
- function doUnloadSection(_sSection)
- {
- if(_sSection === Game.sSECTION_GAME)
- {
- this.doUnloadLevel();
- }
- }
- }
-