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

  1. class Main extends Library.DispatcherBase
  2. {
  3.    var mcRef;
  4.    var oHS;
  5.    var nLatestScore;
  6.    var bHSScrolling;
  7.    var oTransition;
  8.    var oHSInGame;
  9.    var oHSWin;
  10.    var oHSLose;
  11.    var nHSScrollChange;
  12.    var bGameFromReset;
  13.    var bHSFromTitle;
  14.    var bHSAlreadySubmitted;
  15.    var oGame;
  16.    var sCurrentSection;
  17.    var sTargetSection;
  18.    var oMusicPack;
  19.    var oIntroManager;
  20.    var oTitleManager;
  21.    static var oCtrl;
  22.    static var nSOUND_VOL_SOUND = 100;
  23.    static var nSOUND_VOL_MUSIC = 35;
  24.    static var sSOUND_CAT_SOUND = "SFX";
  25.    static var sSOUND_CAT_MUSIC = "Music";
  26.    static var nFRAME_RATE = 36;
  27.    static var sSECTION_INTRO = "Intro";
  28.    static var sSECTION_TITLE = "Title";
  29.    static var sSECTION_GAME = "Game";
  30.    static var sSECTION_GAMERESET = "GameReset";
  31.    function Main(_mcRef)
  32.    {
  33.       super();
  34.       this.mcRef = _mcRef;
  35.       Main.oCtrl = this;
  36.       this.oHS = new NickHS("fop_break",true,false);
  37.       this.nLatestScore = 0;
  38.       this.bHSScrolling = false;
  39.       this.mcRef.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
  40.       Library.Sound.SoundManager.doInit(this.mcRef);
  41.       Library.Sound.SoundManager.setCategoryVolume(Main.sSOUND_CAT_SOUND,Main.nSOUND_VOL_SOUND);
  42.       Library.Sound.SoundManager.setCategoryVolume(Main.sSOUND_CAT_MUSIC,Main.nSOUND_VOL_MUSIC);
  43.       this.doStartPackMusic();
  44.       this.oTransition = new Library.Transition(this.mcRef.mcTransition);
  45.       this.oTransition.Listener = this;
  46.       this.doAddListener(this.oTransition);
  47.       this.oHSInGame = new Library.BasicPopUp(this.mcRef.mcHighScoresNormal,true);
  48.       this.oHSInGame.Listener = this;
  49.       this.doAddListener(this.oHSInGame);
  50.       this.oHSWin = new Library.BasicPopUp(this.mcRef.mcHighScoresWin,true);
  51.       this.oHSWin.Listener = this;
  52.       this.doAddListener(this.oHSWin);
  53.       this.oHSLose = new Library.BasicPopUp(this.mcRef.mcHighScoresLose,true);
  54.       this.oHSLose.Listener = this;
  55.       this.doAddListener(this.oHSLose);
  56.       this.doStartPackMusic();
  57.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Game_Start.wav");
  58.       this.doSetSection(Main.sSECTION_INTRO);
  59.    }
  60.    static function get Instance()
  61.    {
  62.       return Main.oCtrl;
  63.    }
  64.    function get StageRoot()
  65.    {
  66.       return this.mcRef;
  67.    }
  68.    function doEnterFrame()
  69.    {
  70.       super.doEnterFrame();
  71.       if(this.bHSScrolling)
  72.       {
  73.          this.oHSInGame.Ref.mcHS.txtHSNumber.scroll = this.oHSInGame.Ref.mcHS.txtHSNumber.scroll + this.nHSScrollChange;
  74.          this.oHSInGame.Ref.mcHS.txtHSName.scroll = this.oHSInGame.Ref.mcHS.txtHSName.scroll + this.nHSScrollChange;
  75.          this.oHSInGame.Ref.mcHS.txtHSScore.scroll = this.oHSInGame.Ref.mcHS.txtHSScore.scroll + this.nHSScrollChange;
  76.          this.oHSWin.Ref.mcHS.txtHSNumber.scroll = this.oHSWin.Ref.mcHS.txtHSNumber.scroll + this.nHSScrollChange;
  77.          this.oHSWin.Ref.mcHS.txtHSName.scroll = this.oHSWin.Ref.mcHS.txtHSName.scroll + this.nHSScrollChange;
  78.          this.oHSWin.Ref.mcHS.txtHSScore.scroll = this.oHSWin.Ref.mcHS.txtHSScore.scroll + this.nHSScrollChange;
  79.          this.oHSLose.Ref.mcHS.txtHSNumber.scroll = this.oHSLose.Ref.mcHS.txtHSNumber.scroll + this.nHSScrollChange;
  80.          this.oHSLose.Ref.mcHS.txtHSName.scroll = this.oHSLose.Ref.mcHS.txtHSName.scroll + this.nHSScrollChange;
  81.          this.oHSLose.Ref.mcHS.txtHSScore.scroll = this.oHSLose.Ref.mcHS.txtHSScore.scroll + this.nHSScrollChange;
  82.       }
  83.    }
  84.    function doCloseHSIfOpen()
  85.    {
  86.       if(this.oHSInGame.CurrentState == "Idle")
  87.       {
  88.          this.doResumeFromInGameHS();
  89.       }
  90.    }
  91.    function onIntroFirstPartOver()
  92.    {
  93.       this.doTransitionTo(Main.sSECTION_TITLE);
  94.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Transition.mp3",60);
  95.    }
  96.    function onTitleCardComplete()
  97.    {
  98.       this.bGameFromReset = false;
  99.       this.doSetSection(Main.sSECTION_GAME);
  100.    }
  101.    function doRollSound()
  102.    {
  103.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Mouse_Rollover.mp3",55,1,true);
  104.    }
  105.    function doClickSound()
  106.    {
  107.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Mouse_Click.mp3",60,1,true);
  108.    }
  109.    function onPlayerLose()
  110.    {
  111.       this.bHSFromTitle = false;
  112.       this.bHSAlreadySubmitted = false;
  113.       this.nLatestScore = this.oGame.Status.Score;
  114.       _root.micro = this.nLatestScore;
  115.       this.oGame.doPause();
  116.       this.oHSLose.doOpen();
  117.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Transition.mp3",60);
  118.       this.doStartPackMusic();
  119.       Game.Instance.doStopMusic();
  120.    }
  121.    function onPlayerWin()
  122.    {
  123.       this.bHSFromTitle = false;
  124.       this.bHSAlreadySubmitted = false;
  125.       this.nLatestScore = this.oGame.Status.Score;
  126.       _root.micro = this.nLatestScore;
  127.       this.oGame.doPause();
  128.       this.oHSWin.doOpen();
  129.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Transition.mp3",60);
  130.       this.doStartPackMusic();
  131.       Game.Instance.doStopMusic();
  132.    }
  133.    function onTransitionEvent(_nEvent, _oTransition)
  134.    {
  135.       switch(_nEvent)
  136.       {
  137.          case Library.Transition.TRANSITION_SCREEN_COVERED:
  138.             this.doUnloadSection(this.sCurrentSection);
  139.             this.doSetSection(this.sTargetSection);
  140.             break;
  141.          case Library.Transition.TRANSITION_COMPLETE:
  142.       }
  143.    }
  144.    function onPopUpEvent(_nEvent, _oPopUp)
  145.    {
  146.       var _loc0_ = null;
  147.       if((_loc0_ = _nEvent) === Library.BasicPopUp.NEED_UPDATE)
  148.       {
  149.          switch(_oPopUp)
  150.          {
  151.             case this.oHSInGame:
  152.                this.doUpdateInGameHS();
  153.                break;
  154.             case this.oHSLose:
  155.                this.doUpdateLoseHS();
  156.                break;
  157.             case this.oHSWin:
  158.                this.doUpdateWinHS();
  159.          }
  160.       }
  161.    }
  162.    function doSubmitScoreFromLose()
  163.    {
  164.       _root.micro = this.nLatestScore;
  165.       this.oHS.bSubmitHS = false;
  166.       this.oHS.submitScore(this.nLatestScore);
  167.       this.bHSAlreadySubmitted = true;
  168.       this.oHSLose.Ref.mcButtons.btnSubmitHS._visible = true;
  169.    }
  170.    function doSubmitScoreFromWin()
  171.    {
  172.       _root.micro = this.nLatestScore;
  173.       this.oHS.bSubmitHS = false;
  174.       this.oHS.submitScore(this.nLatestScore);
  175.       this.bHSAlreadySubmitted = true;
  176.       this.oHSWin.Ref.mcButtons.btnSubmitHS._visible = true;
  177.    }
  178.    function doPlayAgainFromLose()
  179.    {
  180.       this.oHSLose.doClose();
  181.       this.doUnloadSection(Main.sSECTION_GAME);
  182.       this.doSetSection(Main.sSECTION_GAMERESET);
  183.    }
  184.    function doPlayAgainFromWin()
  185.    {
  186.       this.oHSWin.doClose();
  187.       this.doUnloadSection(Main.sSECTION_GAME);
  188.       this.doSetSection(Main.sSECTION_GAMERESET);
  189.    }
  190.    function doResumeFromInGameHS()
  191.    {
  192.       this.oHSInGame.doClose();
  193.    }
  194.    function doShowInGameHS()
  195.    {
  196.       this.bHSFromTitle = true;
  197.       this.oHSInGame.doOpen();
  198.    }
  199.    function doStopScrollHsList()
  200.    {
  201.       this.bHSScrolling = false;
  202.    }
  203.    function doStartScrollHsList(_nChange)
  204.    {
  205.       this.bHSScrolling = true;
  206.       this.nHSScrollChange = _nChange;
  207.    }
  208.    function doSoundEvent(__nEvent, __oSound)
  209.    {
  210.       var _loc0_ = null;
  211.       if((_loc0_ = __nEvent) === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  212.       {
  213.          if(__oSound == this.oMusicPack)
  214.          {
  215.             delete this.oMusicPack;
  216.          }
  217.       }
  218.    }
  219.    function doStartPackMusic()
  220.    {
  221.       if(this.oMusicPack == undefined)
  222.       {
  223.          this.oMusicPack = Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_MUSIC,"Music_Pack.wav",0,999999);
  224.          this.oMusicPack.doAddListener(this);
  225.       }
  226.       this.oMusicPack.doFadeTo(100);
  227.    }
  228.    function doStopPackMusic()
  229.    {
  230.       if(this.oMusicPack != undefined)
  231.       {
  232.          this.oMusicPack.doFadeTo(0);
  233.       }
  234.    }
  235.    function doSetUpSharedHS(_mcRef, _oOriginHS)
  236.    {
  237.       this.oHS.setHSBoard(_mcRef.mcHS);
  238.       if(_oOriginHS.CurrentState == "Idle")
  239.       {
  240.          this.oHS.getScores();
  241.       }
  242.       _mcRef.btnHaut.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,-1);
  243.       _mcRef.btnBas.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,1);
  244.       _mcRef.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  245.       _mcRef.btnHaut.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  246.       _mcRef.btnHaut.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  247.       _mcRef.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  248.       _mcRef.btnBas.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  249.       _mcRef.btnBas.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  250.       _mcRef.mcScore.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nLatestScore,6);
  251.    }
  252.    function doUpdateInGameHS()
  253.    {
  254.       this.doSetUpSharedHS(this.oHSInGame.Ref,this.oHSInGame);
  255.       this.oHSInGame.Ref.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doResumeFromInGameHS);
  256.    }
  257.    function doUpdateLoseHS()
  258.    {
  259.       this.doSetUpSharedHS(this.oHSLose.Ref,this.oHSLose);
  260.       this.oHSLose.Ref.mcButtons.btnSubmitHS._visible = this.oHS.getIsLoggedIn() && !this.bHSAlreadySubmitted;
  261.       this.oHSLose.Ref.mcButtons.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitScoreFromLose);
  262.       this.oHSLose.Ref.mcButtons.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doPlayAgainFromLose);
  263.    }
  264.    function doUpdateWinHS()
  265.    {
  266.       this.doSetUpSharedHS(this.oHSWin.Ref,this.oHSWin);
  267.       this.oHSWin.Ref.mcButtons.btnSubmitHS._visible = this.oHS.getIsLoggedIn() && !this.bHSAlreadySubmitted;
  268.       this.oHSWin.Ref.mcButtons.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitScoreFromWin);
  269.       this.oHSWin.Ref.mcButtons.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doPlayAgainFromWin);
  270.    }
  271.    function doCreateGame()
  272.    {
  273.       this.oGame = new Game(this.mcRef.mcGameScreen);
  274.    }
  275.    function doUnloadGame()
  276.    {
  277.       this.oGame.doDestroy();
  278.    }
  279.    function doSetSection(_sSection)
  280.    {
  281.       this.sCurrentSection = _sSection;
  282.       this.mcRef.gotoAndStop(this.sCurrentSection);
  283.       switch(this.sCurrentSection)
  284.       {
  285.          case Main.sSECTION_INTRO:
  286.             this.oIntroManager = new Intro(this.mcRef.mcState);
  287.             break;
  288.          case Main.sSECTION_TITLE:
  289.             this.oTitleManager = new TitleCard(this.mcRef.mcState);
  290.             this.doCreateGame();
  291.             this.bGameFromReset = false;
  292.             break;
  293.          case Main.sSECTION_GAMERESET:
  294.             this.bGameFromReset = true;
  295.             this.doSetSection(Main.sSECTION_GAME);
  296.             break;
  297.          case Main.sSECTION_GAME:
  298.             if(this.bGameFromReset)
  299.             {
  300.                this.doCreateGame();
  301.             }
  302.             this.oGame.onBeginGame();
  303.       }
  304.    }
  305.    function doUnloadSection(_sSection)
  306.    {
  307.       switch(_sSection)
  308.       {
  309.          case Main.sSECTION_INTRO:
  310.             delete this.oIntroManager;
  311.             break;
  312.          case Main.sSECTION_GAME:
  313.             this.doUnloadGame();
  314.             break;
  315.          case Main.sSECTION_TITLE:
  316.             delete this.oTitleManager;
  317.       }
  318.    }
  319.    function doTransitionTo(_sSection)
  320.    {
  321.       this.sTargetSection = _sSection;
  322.       this.oTransition.doStart();
  323.    }
  324. }
  325.