home *** CD-ROM | disk | FTP | other *** search
- class GameManager extends games.GManager
- {
- var MC;
- var logosMC;
- var menuMC;
- var pauseMC;
- var gameMC;
- var levelMC;
- var gameoverMC;
- var creditsMC;
- var instructionMC;
- var timer;
- var keyboard;
- var gameId;
- var gameName;
- var gameYear;
- var keyDownEventList;
- var keyUpEventList;
- var game;
- var soundman;
- var call_getMore;
- var call_startGame;
- var call_rollOverSound;
- var call_add2site;
- var eventsKeysList;
- var externalmethods;
- var call_saveScore;
- var call_download;
- var localmethods;
- var call_comments;
- var call_instruction;
- var call_credits;
- var call_backToMenu;
- var call_tryAgain;
- var call_newLevel;
- var call_gameOver;
- var _lastPlayerScore;
- var do_afterNewLevel;
- var FPS;
- static var instance;
- var _playerName = "Your NickName";
- var _playerDefaultNick = "Your NickName";
- function GameManager(_MC)
- {
- super();
- this.MC = _MC;
- this.logosMC = this.MC.logosMC;
- this.menuMC = this.MC.menuMC;
- this.pauseMC = this.MC.pauseMC;
- this.gameMC = this.MC.gameMC;
- this.levelMC = this.MC.levelMC;
- this.gameoverMC = this.MC.gameoverMC;
- this.creditsMC = this.MC.creditsMC;
- this.instructionMC = this.MC.instructionMC;
- GameManager.instance = this;
- this.timer = system.Timer.getInstance(this.MC);
- this.keyboard = keyboardPackage.Keyboard.getInstance();
- this.MC.FPSchecker._visible = false;
- this.setSoundObjects();
- this.keyboard.addListener(this);
- Mouse.addListener(this);
- this.gameId = this.MC.gameId;
- this.gameName = this.MC.gameName;
- this.gameYear = this.MC.gameYear;
- AsBroadcaster.initialize(this);
- this.addListener(this);
- var mochi = new games.MochiClass(this.MC,this.MC.mochiNumbers);
- this.setCalls();
- this.setMenu();
- this.setGameOverScreen();
- this.hideClips();
- this.showLogos();
- }
- function sendEvent(ev, val)
- {
- this.broadcastMessage(ev,val);
- }
- function onKeyDown(keycode)
- {
- var key = this.keyboard.getKeyName(keycode);
- var eventObject = this.keyDownEventList[key];
- if(eventObject != undefined)
- {
- this.sendEvent(eventObject.event,eventObject.param);
- }
- }
- function onMouseDown()
- {
- var key = "mouse";
- var eventObject = this.keyDownEventList[key];
- if(eventObject != undefined)
- {
- this.sendEvent(this.keyDownEventList.mouse.event,this.keyDownEventList.mouse.param);
- }
- }
- function onKeyUp(keycode)
- {
- var key = this.keyboard.getKeyName(keycode);
- var eventObject = this.keyUpEventList[key];
- if(eventObject != undefined)
- {
- this.sendEvent(eventObject.event,eventObject.param);
- }
- }
- function onMouseUp()
- {
- if(this.keyUpEventList.mouse.event != undefined)
- {
- this.sendEvent(this.keyUpEventList.mouse.event,this.keyUpEventList.mouse.param);
- }
- }
- function pauseGame(doPause)
- {
- this.pauseMC._visible = this.game != undefined;
- doPause = doPause == true;
- if(doPause)
- {
- this.removeKeyEvent("mouse");
- this.removeKeyEvent("SPACE");
- }
- else
- {
- this.pauseMC.gotoAndStop("play");
- this.pauseMC.p_pause.gotoAndStop("rollOut");
- this.setKeyDownEvent("SPACE","onBonusUse","Use Bonus",1);
- }
- new extensions.movieclip.SimpleButton(this.pauseMC,system.Delegate.create(this,this.sendEvent,"pauseGame",!doPause));
- this.setKeyDownEvent("P","pauseGame","Pause Game",!doPause);
- }
- function enableSound(doEnable)
- {
- if(doEnable)
- {
- this.soundman.mute();
- this.MC.p_enableSND._visible = false;
- }
- else
- {
- this.soundman.enable();
- this.MC.p_enableSND._visible = true;
- }
- this.MC.p_disableSND._visible = !this.MC.p_enableSND._visible;
- this.setKeyDownEvent("S","enableSound",(!doEnable ? "Enable" : "Disable") + " Sound",!doEnable);
- }
- function showGameCredits(v)
- {
- this.creditsMC._visible = v;
- }
- function showInstruction(v)
- {
- this.instructionMC._visible = v;
- if(v == true)
- {
- this.instructionMC.gotoAndPlay("start");
- this.instructionMC.showMenu = system.Delegate.create(this,this.showMenu);
- this.instructionMC.bg.onRelease = function()
- {
- };
- this.instructionMC.bg.useHandCursor = false;
- }
- }
- function getMore()
- {
- this.call_getMore();
- }
- function setMenu()
- {
- new extensions.movieclip.SimpleButton(this.menuMC.p_play,this.call_startGame,this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(this.menuMC.p_logo,this.call_getMore,this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(this.menuMC.p_add2site,this.call_add2site,this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(this.menuMC.p_howto,system.Delegate.create(this,this.showInstruction,true),this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(this.menuMC.p_credits,system.Delegate.create(this,this.showGameCredits,true),this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(this.creditsMC,system.Delegate.create(this,this.showGameCredits,false),this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(this.MC.p_enableSND,system.Delegate.create(this,this.sendEvent,"enableSound",true));
- new extensions.movieclip.SimpleButton(this.MC.p_disableSND,system.Delegate.create(this,this.sendEvent,"enableSound",false));
- new extensions.movieclip.SimpleButton(this.pauseMC,system.Delegate.create(this,this.sendEvent,"pauseGame",true));
- this.pauseMC.hitArea = this.pauseMC.p_pause.p_hit;
- }
- function showMenu(ingame)
- {
- this.enableSound(false);
- this.playMusic("loop_menu");
- this.hideClips();
- this.setKeyDownEvent("ENTER","startGame","Start Game",null);
- this.showGameCredits(false);
- this.showInstruction(false);
- this.menuMC._visible = true;
- }
- function showLogos()
- {
- this.logosMC._visible = true;
- this.logosMC.gotoAndPlay("start");
- }
- function playFX(fxname)
- {
- this.soundman.play(fxname);
- }
- function stopFX(fxname)
- {
- this.soundman.stop(fxname);
- }
- function playMusic(music)
- {
- this.soundman.play(music,true);
- }
- function stopMusic(music)
- {
- this.soundman.stop(music);
- }
- function hideClips()
- {
- this.menuMC._visible = false;
- this.pauseMC._visible = false;
- this.gameMC._visible = false;
- this.levelMC._visible = false;
- this.gameoverMC._visible = false;
- this.creditsMC._visible = false;
- this.MC.p_enableSND._visible = false;
- this.MC.p_disableSND._visible = false;
- this.MC.logosMC._visible = false;
- }
- function setKeyDownEvent(key, ev, ev_name, param)
- {
- this.keyDownEventList[key] = {event:ev,eventName:ev_name,param:param};
- this.eventsKeysList[ev] = key;
- }
- function setKeyUpEvent(key, ev, ev_name, param)
- {
- this.keyUpEventList[key] = {event:ev,eventName:ev_name,param:param};
- this.eventsKeysList[ev] = key;
- }
- function removeKeyEvent(key)
- {
- if(this.keyUpEventList[key] != undefined)
- {
- delete this.keyUpEventList[key];
- }
- if(this.keyDownEventList[key] != undefined)
- {
- delete this.keyUpEventList[key];
- }
- }
- function setEvents()
- {
- this.keyUpEventList = new Array();
- this.keyDownEventList = new Array();
- this.eventsKeysList = new Array();
- this.setKeyDownEvent("SPACE","onBonusUse","Use Bonus",1);
- this.setKeyDownEvent("P","pauseGame","Pause Game",true);
- this.setKeyDownEvent("N","nextLevel","Go to next level",null);
- this.setKeyDownEvent("M","enableMusic","Disable music",false);
- this.setKeyDownEvent("S","enableSounds","Disable Sounds",false);
- this.setKeyDownEvent("F","enableFX","Disable FX",false);
- this.setKeyDownEvent("LEFT ARROW","onKeysMove","Move Left",{_x:-1});
- this.setKeyDownEvent("RIGHT ARROW","onKeysMove","Move Right",{_x:1});
- this.setKeyUpEvent("LEFT ARROW","onKeysMove","Stop Moving",{_x:0});
- this.setKeyUpEvent("RIGHT ARROW","onKeysMove","Stop Moving",{_x:0});
- this.setKeyDownEvent("UP ARROW","onKeysMove","Move Up",{_y:-1});
- this.setKeyDownEvent("DOWN ARROW","onKeysMove","Move Down",{_y:1});
- this.setKeyUpEvent("UP ARROW","onKeysMove","Stop Moving Up",{_y:0});
- this.setKeyUpEvent("DOWN ARROW","onKeysMove","Stop Moving Dn",{_y:0});
- }
- function setCalls()
- {
- this.externalmethods = new games.externalmethods.AGameSendMethods(this.MC.externalId,this);
- this.call_saveScore = system.Delegate.create(this.externalmethods,this.externalmethods.saveScore);
- this.call_getMore = system.Delegate.create(this.externalmethods,this.externalmethods.getMore);
- this.call_download = system.Delegate.create(this.externalmethods,this.externalmethods.downloadGame);
- this.call_add2site = system.Delegate.create(this.externalmethods,this.externalmethods.addToSite);
- this.localmethods = new games.externalmethods.PastelPortalMethods(this.gameId,this.gameName,this.gameYear);
- this.call_comments = system.Delegate.create(this.localmethods,this.localmethods.getComments);
- this.localmethods.setFooter(this.MC.footerMC,false);
- this.call_instruction = system.Delegate.create(this,this.showInstruction);
- this.call_credits = system.Delegate.create(this,this.showGameCredits);
- this.call_backToMenu = system.Delegate.create(this,this.showMenu);
- this.call_tryAgain = system.Delegate.create(this,this.startGame);
- this.call_startGame = system.Delegate.create(this,this.startGame);
- this.call_newLevel = system.Delegate.create(this,this.startNewLevel);
- this.call_gameOver = system.Delegate.create(this,this.showGameOver);
- this.call_rollOverSound = system.Delegate.create(this,this.playRollOverSound);
- }
- function setSoundObjects()
- {
- this.soundman = SoundManager.getInstance(this.MC);
- new extensions.movieclip.SimpleButton(this.MC.p_enableSND,system.Delegate.create(this,this.enableSound,false));
- new extensions.movieclip.SimpleButton(this.MC.p_disableSND,system.Delegate.create(this,this.enableSound,true));
- this.enableSound(true);
- }
- function playRollOverSound()
- {
- this.playFX("snd_rollover");
- }
- function startGame()
- {
- this.stopMusic("loop_menu");
- this.setEvents();
- this.hideClips();
- this.removeKeyEvent("ENTER");
- this.setKeyDownEvent("ESC","endGame","End Game","You break the game...");
- this.gameMC._visible = true;
- this.game = new Venus_game(this.gameMC,550,400,this);
- this.enableSound(false);
- this.pauseGame(false);
- }
- function promptAboutPlayerName(z, focused)
- {
- var tMC = this.gameoverMC.nick;
- if(tMC.nickname == this._playerDefaultNick && focused == true)
- {
- tMC.nickname = "";
- this.setKeyDownEvent("ENTER","saveScore","Save Score");
- tMC.TF.onKillFocus = system.Delegate.create(this,this.removeKeyEvent,"ENTER");
- }
- else if(tMC.nickname == this._playerDefaultNick || tMC.nickname == "")
- {
- tMC.nickname = this._playerDefaultNick;
- var a = new flash.geom.ColorTransform(1,1,1,1,255,255,255,0);
- var b = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
- var fader = new effects.Fader(this.gameMC);
- fader.fadeIt(tMC,a,0,null);
- fader.fadeIt(tMC,b,30,null);
- }
- else
- {
- this.saveScore();
- }
- }
- function saveScore()
- {
- var tMC = this.gameoverMC.nick;
- this._playerName = tMC.nickname;
- this.call_saveScore();
- }
- function showGameOver(currentscore, info)
- {
- var tMC = this.gameoverMC;
- this._lastPlayerScore = currentscore;
- this.removeKeyEvent("mouse");
- this.removeKeyEvent("SPACE");
- this.hideClips();
- this.playFX("snd_gameover");
- tMC._visible = true;
- tMC.endtext.info = info;
- tMC.nick.nickname = this._playerName;
- tMC.score.info = "You score is " + currentscore + " points";
- tMC.nick.TF.onSetFocus = system.Delegate.create(this,this.promptAboutPlayerName,true);
- }
- function setGameOverScreen()
- {
- var tMC = this.gameoverMC;
- new extensions.movieclip.SimpleButton(tMC.p_menu,this.call_backToMenu,this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(tMC.p_tryagain,this.call_tryAgain,this.call_rollOverSound);
- new extensions.movieclip.SimpleButton(tMC.p_logo,this.call_getMore,this.call_rollOverSound);
- }
- function afterNewLevel()
- {
- this.pauseMC._visible = true;
- this.levelMC._visible = false;
- this.setKeyDownEvent("P","pauseGame","Pause Game",true);
- this.do_afterNewLevel();
- }
- function startNewLevel(levelname, leveltitle, levelinfo, levelbutton, aftertime, fn_doafter)
- {
- this.removeKeyEvent("P");
- this.pauseMC._visible = false;
- this.levelMC._visible = true;
- this.levelMC.levelfield.info = levelname;
- this.levelMC.titlefield.info = leveltitle;
- this.levelMC.instructionfield.info = levelinfo;
- this.do_afterNewLevel = fn_doafter;
- if(aftertime == 0)
- {
- this.levelMC.levelBTN.info = levelname;
- new extensions.movieclip.SimpleButton(this.levelMC.levelBTN,system.Delegate.create(this,this.afterNewLevel));
- }
- else
- {
- this.timer.addListener(this.levelMC,aftertime,system.Delegate.create(this,this.afterNewLevel),1);
- }
- }
- function showFPS()
- {
- this.MC.FPSchecker.FPStext.text = this.FPS.getFPStime();
- }
- }
-