home *** CD-ROM | disk | FTP | other *** search
- class com.leadpipe.attentionhog.Game
- {
- var isPaused;
- var so;
- var itemMax;
- var roundMax;
- var isSoundOn;
- var isMusicOn;
- var music;
- var start;
- var itemsUnlocked;
- var loveInc;
- var gaugeMain;
- var heartsCurrNum;
- var heartsTargetNum;
- var proxThreshold;
- var roundNum;
- var loveFadeRate;
- var playerDepthInit;
- var ghostDepthInit;
- var peopleDepthInit;
- var itemDepthInit;
- var itemCntr;
- var timerBonus;
- var timerBacon;
- var winTimeoutID;
- var personSP;
- static var score;
- static var highScore;
- static var scoreMultiplier;
- static var scoreBase;
- static var instance = null;
- var gaugeSlop = new Array();
- function Game()
- {
- this.isPaused = true;
- com.leadpipe.attentionhog.Game.score = 0;
- com.leadpipe.attentionhog.Game.highScore = 0;
- com.leadpipe.attentionhog.Game.scoreMultiplier = 1;
- this.so = SharedObject.getLocal("userHighScore");
- this.itemMax = 50;
- com.leadpipe.attentionhog.Game.scoreBase = 100;
- this.roundMax = 6;
- this.isSoundOn = true;
- this.isMusicOn = true;
- this.music = new Sound(_root.music_mc);
- this.music.attachSound("music");
- this.music.onSoundComplete = function()
- {
- this.start(0,1);
- };
- }
- function getItemsUnlocked()
- {
- return this.itemsUnlocked;
- }
- function soundOn(s)
- {
- this.isSoundOn = s;
- com.leadpipe.attentionhog.Player.instance.soundOn(this.isSoundOn);
- com.leadpipe.attentionhog.Person.soundOnAll(this.isSoundOn);
- }
- function musicOn(m)
- {
- this.isMusicOn = m;
- if(this.isMusicOn)
- {
- this.music.setVolume(60);
- }
- else
- {
- this.music.setVolume(0);
- }
- }
- function getScore()
- {
- return com.leadpipe.attentionhog.Game.score;
- }
- function getHighScore()
- {
- return com.leadpipe.attentionhog.Game.highScore;
- }
- function setScore(s)
- {
- com.leadpipe.attentionhog.Game.score += Math.pow(s,2) * com.leadpipe.attentionhog.Game.scoreBase;
- this.loveInc = 0;
- var _loc3_ = 0;
- while(_loc3_ < Math.pow(s,2))
- {
- this.loveInc += this.gaugeMain.getIncSpeed();
- _loc3_ = _loc3_ + 1;
- }
- this.gaugeMain.setLevel(this.gaugeMain.getLevel() + this.loveInc);
- _root.score = com.leadpipe.attentionhog.Game.score;
- }
- function captureHeart()
- {
- this.heartsCurrNum = this.heartsCurrNum + 1;
- _root.hud_mc.hearts_txt.text = this.heartsCurrNum + " / " + this.heartsTargetNum;
- if(this.heartsCurrNum >= this.heartsTargetNum)
- {
- this.endRound();
- }
- }
- function setScoreMultiplier(s)
- {
- com.leadpipe.attentionhog.Game.scoreMultiplier = s;
- }
- function setup()
- {
- com.leadpipe.attentionhog.Game.score = 0;
- this.proxThreshold = 75;
- this.roundNum = 0;
- _root.gotoAndStop("start_game");
- _root.attachMovie("hud_mc","hud_mc",50000,{_y:0});
- _root.attachMovie("infoBox" + this.roundNum,"infoBox" + this.roundNum,50001,{_x:200,_y:205});
- this.gaugeMain = new com.leadpipe.attentionhog.Gauge();
- this.loveFadeRate = 0.2;
- this.gaugeMain.setSpeed(0.015,this.loveFadeRate);
- this.gaugeMain.initMask(_root.hud_mc.gaugeMainMask_mc);
- var _loc3_ = 0;
- while(_loc3_ < 6)
- {
- this.gaugeSlop.push(new com.leadpipe.attentionhog.Gauge());
- this.gaugeSlop[_loc3_].setLevel(0);
- this.gaugeSlop[_loc3_].setSpeed(20,0.5);
- this.gaugeSlop[_loc3_].initMask(_root.hud_mc["gauge" + _loc3_].mask_mc);
- _root.hud_mc["gauge" + _loc3_]._alpha = 0;
- _loc3_ = _loc3_ + 1;
- }
- _root.score = 0;
- this.heartsTargetNum = (this.roundNum + 1) * 10;
- this.heartsCurrNum = 0;
- _root.hud_mc.hearts_txt.text = this.heartsCurrNum + " / " + this.heartsTargetNum;
- this.setupHandlers();
- this.pause(true);
- this.musicOn(this.isMusicOn);
- this.soundOn(this.isSoundOn);
- }
- function startRound()
- {
- this.gaugeMain.setLevel(100);
- if(this.roundNum > 6)
- {
- this.itemsUnlocked = this.roundNum - 6;
- }
- else
- {
- this.itemsUnlocked = this.roundNum;
- }
- this.heartsTargetNum = (this.roundNum + 1) * 10;
- this.loveFadeRate += 0.05;
- this.gaugeMain.setSpeed(0.015,this.loveFadeRate);
- this.heartsCurrNum = 0;
- _root.hud_mc.hearts_txt.text = this.heartsCurrNum + " / " + this.heartsTargetNum;
- this.playerDepthInit = 5000;
- _root.attachMovie("player_mc","player_mc",this.playerDepthInit);
- this.ghostDepthInit = 10000;
- this.peopleDepthInit = 15000;
- this.createPeople("person_mc",9,false);
- this.itemDepthInit = 20000;
- this.itemCntr = 0;
- if(this.roundNum > 0)
- {
- _root.hud_mc["gauge" + (this.itemsUnlocked - 1)]._alpha = 100;
- this.timerBonus = new com.leadpipe.attentionhog.Timer(this,"newBonus",2000,4000);
- this.timerBonus.start();
- }
- this.timerBacon = new com.leadpipe.attentionhog.Timer(this,"newBacon",7000,14000);
- this.timerBacon.start();
- _root["infoBox" + this.roundNum].removeMovieClip();
- this.music.start(0,1);
- this.pause(false);
- }
- function endRound()
- {
- this.roundNum = this.roundNum + 1;
- this.pause(true);
- com.leadpipe.attentionhog.Person.destroyAll();
- com.leadpipe.attentionhog.Item.destroyAll();
- com.leadpipe.attentionhog.Timer.destroyAll();
- com.leadpipe.attentionhog.Ghost.destroyAll();
- com.leadpipe.attentionhog.Player.instance.destroy();
- com.leadpipe.attentionhog.Ability.stopPowerUpAll();
- this.music.stop("music");
- _root.attachMovie("infoBox" + this.roundNum,"infoBox" + this.roundNum,50001,{_x:200,_y:205});
- _root.hud_mc["gauge" + this.itemsUnlocked]._alpha = 100;
- if(this.roundNum > this.roundMax)
- {
- if(this.winTimeoutID != null)
- {
- clearTimeout(this.winTimeoutID);
- }
- this.winTimeoutID = setTimeout(this,"gameOverWin",3500);
- }
- }
- function go()
- {
- if(this.isPaused)
- {
- return undefined;
- }
- com.leadpipe.attentionhog.Player.getInstance().go();
- com.leadpipe.attentionhog.Person.goAll();
- }
- function bonus()
- {
- if(random(150) < 2)
- {
- this.newBonus();
- }
- if(random(350) < 1)
- {
- this.newBacon();
- }
- }
- function pause(p)
- {
- this.isPaused = p;
- com.leadpipe.attentionhog.Player.getInstance().pause(this.isPaused);
- }
- function setupHandlers()
- {
- var game = this;
- _root.onEnterFrame = function()
- {
- game.go();
- };
- }
- function restart()
- {
- _root.gotoAndStop("menu");
- }
- function gameOver()
- {
- com.leadpipe.attentionhog.Person.destroyAll();
- com.leadpipe.attentionhog.Item.destroyAll();
- com.leadpipe.attentionhog.Timer.destroyAll();
- com.leadpipe.attentionhog.Ghost.destroyAll();
- com.leadpipe.attentionhog.Player.instance.destroy();
- _root.hud_mc.removeMovieClip();
- if(this.so.data.highScore == undefined)
- {
- this.so.data.highScore = 0;
- this.so.flush();
- }
- com.leadpipe.attentionhog.Game.highScore = this.so.data.highScore;
- if(com.leadpipe.attentionhog.Game.score > com.leadpipe.attentionhog.Game.highScore)
- {
- com.leadpipe.attentionhog.Game.highScore = com.leadpipe.attentionhog.Game.score;
- this.so.data.highScore = com.leadpipe.attentionhog.Game.highScore;
- this.so.flush();
- }
- _root.gotoAndStop("game_over");
- stop();
- _root.scoreFinal_txt.text = com.leadpipe.attentionhog.Game.score;
- _root.scoreHigh_txt.text = com.leadpipe.attentionhog.Game.highScore;
- }
- function gameOverWin()
- {
- this.music.stop("music");
- _root.hud_mc.removeMovieClip();
- _root.infoBox7.removeMovieClip();
- if(com.leadpipe.attentionhog.Game.score > com.leadpipe.attentionhog.Game.highScore)
- {
- com.leadpipe.attentionhog.Game.highScore = com.leadpipe.attentionhog.Game.score;
- }
- _root.gotoAndStop("game_over");
- stop();
- _root.scoreFinal_txt.text = com.leadpipe.attentionhog.Game.score;
- _root.scoreHigh_txt.text = com.leadpipe.attentionhog.Game.highScore;
- }
- function die()
- {
- this.music.stop("music");
- }
- function createPeople(na, nu, ons)
- {
- var _loc3_ = 0;
- while(_loc3_ < nu)
- {
- var _loc4_ = this.peopleDepthInit + _loc3_;
- _root.attachMovie(na,"person" + _loc3_,_loc4_);
- com.leadpipe.attentionhog.Person.instanceList[_loc3_].body_mc.gotoAndStop(random(com.leadpipe.attentionhog.Person.instanceList[_loc3_].body_mc._totalframes) + 1);
- this.personSP = new flash.geom.Point(random(Stage.width),random(Stage.height));
- if(ons)
- {
- com.leadpipe.attentionhog.Person.instanceList[_loc3_].startOnScreen();
- }
- else
- {
- com.leadpipe.attentionhog.Person.instanceList[_loc3_].startOffScreen();
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- static function getInstance()
- {
- if(com.leadpipe.attentionhog.Game.instance == null)
- {
- com.leadpipe.attentionhog.Game.instance = new com.leadpipe.attentionhog.Game();
- }
- return com.leadpipe.attentionhog.Game.instance;
- }
- function newBonus()
- {
- var _loc3_ = this.itemDepthInit + this.itemCntr;
- _root.attachMovie("item_mc","item" + this.itemCntr,_loc3_);
- this.itemCntr = (this.itemCntr + 1) % this.itemMax;
- }
- function newBacon()
- {
- var _loc3_ = this.itemDepthInit + this.itemCntr;
- _root.attachMovie("bacon_mc","item" + this.itemCntr,_loc3_);
- this.itemCntr = (this.itemCntr + 1) % this.itemMax;
- }
- }
-