home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / VenusMission.swf / scripts / __Packages / GameManager.as next >
Encoding:
Text File  |  2008-09-23  |  13.9 KB  |  386 lines

  1. class GameManager extends games.GManager
  2. {
  3.    var MC;
  4.    var logosMC;
  5.    var menuMC;
  6.    var pauseMC;
  7.    var gameMC;
  8.    var levelMC;
  9.    var gameoverMC;
  10.    var creditsMC;
  11.    var instructionMC;
  12.    var timer;
  13.    var keyboard;
  14.    var gameId;
  15.    var gameName;
  16.    var gameYear;
  17.    var keyDownEventList;
  18.    var keyUpEventList;
  19.    var game;
  20.    var soundman;
  21.    var call_getMore;
  22.    var call_startGame;
  23.    var call_rollOverSound;
  24.    var call_add2site;
  25.    var eventsKeysList;
  26.    var externalmethods;
  27.    var call_saveScore;
  28.    var call_download;
  29.    var localmethods;
  30.    var call_comments;
  31.    var call_instruction;
  32.    var call_credits;
  33.    var call_backToMenu;
  34.    var call_tryAgain;
  35.    var call_newLevel;
  36.    var call_gameOver;
  37.    var _lastPlayerScore;
  38.    var do_afterNewLevel;
  39.    var FPS;
  40.    static var instance;
  41.    var _playerName = "Your NickName";
  42.    var _playerDefaultNick = "Your NickName";
  43.    function GameManager(_MC)
  44.    {
  45.       super();
  46.       this.MC = _MC;
  47.       this.logosMC = this.MC.logosMC;
  48.       this.menuMC = this.MC.menuMC;
  49.       this.pauseMC = this.MC.pauseMC;
  50.       this.gameMC = this.MC.gameMC;
  51.       this.levelMC = this.MC.levelMC;
  52.       this.gameoverMC = this.MC.gameoverMC;
  53.       this.creditsMC = this.MC.creditsMC;
  54.       this.instructionMC = this.MC.instructionMC;
  55.       GameManager.instance = this;
  56.       this.timer = system.Timer.getInstance(this.MC);
  57.       this.keyboard = keyboardPackage.Keyboard.getInstance();
  58.       this.MC.FPSchecker._visible = false;
  59.       this.setSoundObjects();
  60.       this.keyboard.addListener(this);
  61.       Mouse.addListener(this);
  62.       this.gameId = this.MC.gameId;
  63.       this.gameName = this.MC.gameName;
  64.       this.gameYear = this.MC.gameYear;
  65.       AsBroadcaster.initialize(this);
  66.       this.addListener(this);
  67.       var mochi = new games.MochiClass(this.MC,this.MC.mochiNumbers);
  68.       this.setCalls();
  69.       this.setMenu();
  70.       this.setGameOverScreen();
  71.       this.hideClips();
  72.       this.showLogos();
  73.    }
  74.    function sendEvent(ev, val)
  75.    {
  76.       this.broadcastMessage(ev,val);
  77.    }
  78.    function onKeyDown(keycode)
  79.    {
  80.       var key = this.keyboard.getKeyName(keycode);
  81.       var eventObject = this.keyDownEventList[key];
  82.       if(eventObject != undefined)
  83.       {
  84.          this.sendEvent(eventObject.event,eventObject.param);
  85.       }
  86.    }
  87.    function onMouseDown()
  88.    {
  89.       var key = "mouse";
  90.       var eventObject = this.keyDownEventList[key];
  91.       if(eventObject != undefined)
  92.       {
  93.          this.sendEvent(this.keyDownEventList.mouse.event,this.keyDownEventList.mouse.param);
  94.       }
  95.    }
  96.    function onKeyUp(keycode)
  97.    {
  98.       var key = this.keyboard.getKeyName(keycode);
  99.       var eventObject = this.keyUpEventList[key];
  100.       if(eventObject != undefined)
  101.       {
  102.          this.sendEvent(eventObject.event,eventObject.param);
  103.       }
  104.    }
  105.    function onMouseUp()
  106.    {
  107.       if(this.keyUpEventList.mouse.event != undefined)
  108.       {
  109.          this.sendEvent(this.keyUpEventList.mouse.event,this.keyUpEventList.mouse.param);
  110.       }
  111.    }
  112.    function pauseGame(doPause)
  113.    {
  114.       this.pauseMC._visible = this.game != undefined;
  115.       doPause = doPause == true;
  116.       if(doPause)
  117.       {
  118.          this.removeKeyEvent("mouse");
  119.          this.removeKeyEvent("SPACE");
  120.       }
  121.       else
  122.       {
  123.          this.pauseMC.gotoAndStop("play");
  124.          this.pauseMC.p_pause.gotoAndStop("rollOut");
  125.          this.setKeyDownEvent("SPACE","onBonusUse","Use Bonus",1);
  126.       }
  127.       new extensions.movieclip.SimpleButton(this.pauseMC,system.Delegate.create(this,this.sendEvent,"pauseGame",!doPause));
  128.       this.setKeyDownEvent("P","pauseGame","Pause Game",!doPause);
  129.    }
  130.    function enableSound(doEnable)
  131.    {
  132.       if(doEnable)
  133.       {
  134.          this.soundman.mute();
  135.          this.MC.p_enableSND._visible = false;
  136.       }
  137.       else
  138.       {
  139.          this.soundman.enable();
  140.          this.MC.p_enableSND._visible = true;
  141.       }
  142.       this.MC.p_disableSND._visible = !this.MC.p_enableSND._visible;
  143.       this.setKeyDownEvent("S","enableSound",(!doEnable ? "Enable" : "Disable") + " Sound",!doEnable);
  144.    }
  145.    function showGameCredits(v)
  146.    {
  147.       this.creditsMC._visible = v;
  148.    }
  149.    function showInstruction(v)
  150.    {
  151.       this.instructionMC._visible = v;
  152.       if(v == true)
  153.       {
  154.          this.instructionMC.gotoAndPlay("start");
  155.          this.instructionMC.showMenu = system.Delegate.create(this,this.showMenu);
  156.          this.instructionMC.bg.onRelease = function()
  157.          {
  158.          };
  159.          this.instructionMC.bg.useHandCursor = false;
  160.       }
  161.    }
  162.    function getMore()
  163.    {
  164.       this.call_getMore();
  165.    }
  166.    function setMenu()
  167.    {
  168.       new extensions.movieclip.SimpleButton(this.menuMC.p_play,this.call_startGame,this.call_rollOverSound);
  169.       new extensions.movieclip.SimpleButton(this.menuMC.p_logo,this.call_getMore,this.call_rollOverSound);
  170.       new extensions.movieclip.SimpleButton(this.menuMC.p_add2site,this.call_add2site,this.call_rollOverSound);
  171.       new extensions.movieclip.SimpleButton(this.menuMC.p_howto,system.Delegate.create(this,this.showInstruction,true),this.call_rollOverSound);
  172.       new extensions.movieclip.SimpleButton(this.menuMC.p_credits,system.Delegate.create(this,this.showGameCredits,true),this.call_rollOverSound);
  173.       new extensions.movieclip.SimpleButton(this.creditsMC,system.Delegate.create(this,this.showGameCredits,false),this.call_rollOverSound);
  174.       new extensions.movieclip.SimpleButton(this.MC.p_enableSND,system.Delegate.create(this,this.sendEvent,"enableSound",true));
  175.       new extensions.movieclip.SimpleButton(this.MC.p_disableSND,system.Delegate.create(this,this.sendEvent,"enableSound",false));
  176.       new extensions.movieclip.SimpleButton(this.pauseMC,system.Delegate.create(this,this.sendEvent,"pauseGame",true));
  177.       this.pauseMC.hitArea = this.pauseMC.p_pause.p_hit;
  178.    }
  179.    function showMenu(ingame)
  180.    {
  181.       this.enableSound(false);
  182.       this.playMusic("loop_menu");
  183.       this.hideClips();
  184.       this.setKeyDownEvent("ENTER","startGame","Start Game",null);
  185.       this.showGameCredits(false);
  186.       this.showInstruction(false);
  187.       this.menuMC._visible = true;
  188.    }
  189.    function showLogos()
  190.    {
  191.       this.logosMC._visible = true;
  192.       this.logosMC.gotoAndPlay("start");
  193.    }
  194.    function playFX(fxname)
  195.    {
  196.       this.soundman.play(fxname);
  197.    }
  198.    function stopFX(fxname)
  199.    {
  200.       this.soundman.stop(fxname);
  201.    }
  202.    function playMusic(music)
  203.    {
  204.       this.soundman.play(music,true);
  205.    }
  206.    function stopMusic(music)
  207.    {
  208.       this.soundman.stop(music);
  209.    }
  210.    function hideClips()
  211.    {
  212.       this.menuMC._visible = false;
  213.       this.pauseMC._visible = false;
  214.       this.gameMC._visible = false;
  215.       this.levelMC._visible = false;
  216.       this.gameoverMC._visible = false;
  217.       this.creditsMC._visible = false;
  218.       this.MC.p_enableSND._visible = false;
  219.       this.MC.p_disableSND._visible = false;
  220.       this.MC.logosMC._visible = false;
  221.    }
  222.    function setKeyDownEvent(key, ev, ev_name, param)
  223.    {
  224.       this.keyDownEventList[key] = {event:ev,eventName:ev_name,param:param};
  225.       this.eventsKeysList[ev] = key;
  226.    }
  227.    function setKeyUpEvent(key, ev, ev_name, param)
  228.    {
  229.       this.keyUpEventList[key] = {event:ev,eventName:ev_name,param:param};
  230.       this.eventsKeysList[ev] = key;
  231.    }
  232.    function removeKeyEvent(key)
  233.    {
  234.       if(this.keyUpEventList[key] != undefined)
  235.       {
  236.          delete this.keyUpEventList[key];
  237.       }
  238.       if(this.keyDownEventList[key] != undefined)
  239.       {
  240.          delete this.keyUpEventList[key];
  241.       }
  242.    }
  243.    function setEvents()
  244.    {
  245.       this.keyUpEventList = new Array();
  246.       this.keyDownEventList = new Array();
  247.       this.eventsKeysList = new Array();
  248.       this.setKeyDownEvent("SPACE","onBonusUse","Use Bonus",1);
  249.       this.setKeyDownEvent("P","pauseGame","Pause Game",true);
  250.       this.setKeyDownEvent("N","nextLevel","Go to next level",null);
  251.       this.setKeyDownEvent("M","enableMusic","Disable music",false);
  252.       this.setKeyDownEvent("S","enableSounds","Disable Sounds",false);
  253.       this.setKeyDownEvent("F","enableFX","Disable FX",false);
  254.       this.setKeyDownEvent("LEFT ARROW","onKeysMove","Move Left",{_x:-1});
  255.       this.setKeyDownEvent("RIGHT ARROW","onKeysMove","Move Right",{_x:1});
  256.       this.setKeyUpEvent("LEFT ARROW","onKeysMove","Stop Moving",{_x:0});
  257.       this.setKeyUpEvent("RIGHT ARROW","onKeysMove","Stop Moving",{_x:0});
  258.       this.setKeyDownEvent("UP ARROW","onKeysMove","Move Up",{_y:-1});
  259.       this.setKeyDownEvent("DOWN ARROW","onKeysMove","Move Down",{_y:1});
  260.       this.setKeyUpEvent("UP ARROW","onKeysMove","Stop Moving Up",{_y:0});
  261.       this.setKeyUpEvent("DOWN ARROW","onKeysMove","Stop Moving Dn",{_y:0});
  262.    }
  263.    function setCalls()
  264.    {
  265.       this.externalmethods = new games.externalmethods.AGameSendMethods(this.MC.externalId,this);
  266.       this.call_saveScore = system.Delegate.create(this.externalmethods,this.externalmethods.saveScore);
  267.       this.call_getMore = system.Delegate.create(this.externalmethods,this.externalmethods.getMore);
  268.       this.call_download = system.Delegate.create(this.externalmethods,this.externalmethods.downloadGame);
  269.       this.call_add2site = system.Delegate.create(this.externalmethods,this.externalmethods.addToSite);
  270.       this.localmethods = new games.externalmethods.PastelPortalMethods(this.gameId,this.gameName,this.gameYear);
  271.       this.call_comments = system.Delegate.create(this.localmethods,this.localmethods.getComments);
  272.       this.localmethods.setFooter(this.MC.footerMC,false);
  273.       this.call_instruction = system.Delegate.create(this,this.showInstruction);
  274.       this.call_credits = system.Delegate.create(this,this.showGameCredits);
  275.       this.call_backToMenu = system.Delegate.create(this,this.showMenu);
  276.       this.call_tryAgain = system.Delegate.create(this,this.startGame);
  277.       this.call_startGame = system.Delegate.create(this,this.startGame);
  278.       this.call_newLevel = system.Delegate.create(this,this.startNewLevel);
  279.       this.call_gameOver = system.Delegate.create(this,this.showGameOver);
  280.       this.call_rollOverSound = system.Delegate.create(this,this.playRollOverSound);
  281.    }
  282.    function setSoundObjects()
  283.    {
  284.       this.soundman = SoundManager.getInstance(this.MC);
  285.       new extensions.movieclip.SimpleButton(this.MC.p_enableSND,system.Delegate.create(this,this.enableSound,false));
  286.       new extensions.movieclip.SimpleButton(this.MC.p_disableSND,system.Delegate.create(this,this.enableSound,true));
  287.       this.enableSound(true);
  288.    }
  289.    function playRollOverSound()
  290.    {
  291.       this.playFX("snd_rollover");
  292.    }
  293.    function startGame()
  294.    {
  295.       this.stopMusic("loop_menu");
  296.       this.setEvents();
  297.       this.hideClips();
  298.       this.removeKeyEvent("ENTER");
  299.       this.setKeyDownEvent("ESC","endGame","End Game","You break the game...");
  300.       this.gameMC._visible = true;
  301.       this.game = new Venus_game(this.gameMC,550,400,this);
  302.       this.enableSound(false);
  303.       this.pauseGame(false);
  304.    }
  305.    function promptAboutPlayerName(z, focused)
  306.    {
  307.       var tMC = this.gameoverMC.nick;
  308.       if(tMC.nickname == this._playerDefaultNick && focused == true)
  309.       {
  310.          tMC.nickname = "";
  311.          this.setKeyDownEvent("ENTER","saveScore","Save Score");
  312.          tMC.TF.onKillFocus = system.Delegate.create(this,this.removeKeyEvent,"ENTER");
  313.       }
  314.       else if(tMC.nickname == this._playerDefaultNick || tMC.nickname == "")
  315.       {
  316.          tMC.nickname = this._playerDefaultNick;
  317.          var a = new flash.geom.ColorTransform(1,1,1,1,255,255,255,0);
  318.          var b = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
  319.          var fader = new effects.Fader(this.gameMC);
  320.          fader.fadeIt(tMC,a,0,null);
  321.          fader.fadeIt(tMC,b,30,null);
  322.       }
  323.       else
  324.       {
  325.          this.saveScore();
  326.       }
  327.    }
  328.    function saveScore()
  329.    {
  330.       var tMC = this.gameoverMC.nick;
  331.       this._playerName = tMC.nickname;
  332.       this.call_saveScore();
  333.    }
  334.    function showGameOver(currentscore, info)
  335.    {
  336.       var tMC = this.gameoverMC;
  337.       this._lastPlayerScore = currentscore;
  338.       this.removeKeyEvent("mouse");
  339.       this.removeKeyEvent("SPACE");
  340.       this.hideClips();
  341.       this.playFX("snd_gameover");
  342.       tMC._visible = true;
  343.       tMC.endtext.info = info;
  344.       tMC.nick.nickname = this._playerName;
  345.       tMC.score.info = "You score is " + currentscore + " points";
  346.       tMC.nick.TF.onSetFocus = system.Delegate.create(this,this.promptAboutPlayerName,true);
  347.    }
  348.    function setGameOverScreen()
  349.    {
  350.       var tMC = this.gameoverMC;
  351.       new extensions.movieclip.SimpleButton(tMC.p_menu,this.call_backToMenu,this.call_rollOverSound);
  352.       new extensions.movieclip.SimpleButton(tMC.p_tryagain,this.call_tryAgain,this.call_rollOverSound);
  353.       new extensions.movieclip.SimpleButton(tMC.p_logo,this.call_getMore,this.call_rollOverSound);
  354.    }
  355.    function afterNewLevel()
  356.    {
  357.       this.pauseMC._visible = true;
  358.       this.levelMC._visible = false;
  359.       this.setKeyDownEvent("P","pauseGame","Pause Game",true);
  360.       this.do_afterNewLevel();
  361.    }
  362.    function startNewLevel(levelname, leveltitle, levelinfo, levelbutton, aftertime, fn_doafter)
  363.    {
  364.       this.removeKeyEvent("P");
  365.       this.pauseMC._visible = false;
  366.       this.levelMC._visible = true;
  367.       this.levelMC.levelfield.info = levelname;
  368.       this.levelMC.titlefield.info = leveltitle;
  369.       this.levelMC.instructionfield.info = levelinfo;
  370.       this.do_afterNewLevel = fn_doafter;
  371.       if(aftertime == 0)
  372.       {
  373.          this.levelMC.levelBTN.info = levelname;
  374.          new extensions.movieclip.SimpleButton(this.levelMC.levelBTN,system.Delegate.create(this,this.afterNewLevel));
  375.       }
  376.       else
  377.       {
  378.          this.timer.addListener(this.levelMC,aftertime,system.Delegate.create(this,this.afterNewLevel),1);
  379.       }
  380.    }
  381.    function showFPS()
  382.    {
  383.       this.MC.FPSchecker.FPStext.text = this.FPS.getFPStime();
  384.    }
  385. }
  386.