home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / attention_hog.swf / scripts / __Packages / com / leadpipe / attentionhog / Game.as < prev    next >
Encoding:
Text File  |  2008-09-22  |  10.0 KB  |  318 lines

  1. class com.leadpipe.attentionhog.Game
  2. {
  3.    var isPaused;
  4.    var so;
  5.    var itemMax;
  6.    var roundMax;
  7.    var isSoundOn;
  8.    var isMusicOn;
  9.    var music;
  10.    var start;
  11.    var itemsUnlocked;
  12.    var loveInc;
  13.    var gaugeMain;
  14.    var heartsCurrNum;
  15.    var heartsTargetNum;
  16.    var proxThreshold;
  17.    var roundNum;
  18.    var loveFadeRate;
  19.    var playerDepthInit;
  20.    var ghostDepthInit;
  21.    var peopleDepthInit;
  22.    var itemDepthInit;
  23.    var itemCntr;
  24.    var timerBonus;
  25.    var timerBacon;
  26.    var winTimeoutID;
  27.    var personSP;
  28.    static var score;
  29.    static var highScore;
  30.    static var scoreMultiplier;
  31.    static var scoreBase;
  32.    static var instance = null;
  33.    var gaugeSlop = new Array();
  34.    function Game()
  35.    {
  36.       this.isPaused = true;
  37.       com.leadpipe.attentionhog.Game.score = 0;
  38.       com.leadpipe.attentionhog.Game.highScore = 0;
  39.       com.leadpipe.attentionhog.Game.scoreMultiplier = 1;
  40.       this.so = SharedObject.getLocal("userHighScore");
  41.       this.itemMax = 50;
  42.       com.leadpipe.attentionhog.Game.scoreBase = 100;
  43.       this.roundMax = 6;
  44.       this.isSoundOn = true;
  45.       this.isMusicOn = true;
  46.       this.music = new Sound(_root.music_mc);
  47.       this.music.attachSound("music");
  48.       this.music.onSoundComplete = function()
  49.       {
  50.          this.start(0,1);
  51.       };
  52.    }
  53.    function getItemsUnlocked()
  54.    {
  55.       return this.itemsUnlocked;
  56.    }
  57.    function soundOn(s)
  58.    {
  59.       this.isSoundOn = s;
  60.       com.leadpipe.attentionhog.Player.instance.soundOn(this.isSoundOn);
  61.       com.leadpipe.attentionhog.Person.soundOnAll(this.isSoundOn);
  62.    }
  63.    function musicOn(m)
  64.    {
  65.       this.isMusicOn = m;
  66.       if(this.isMusicOn)
  67.       {
  68.          this.music.setVolume(60);
  69.       }
  70.       else
  71.       {
  72.          this.music.setVolume(0);
  73.       }
  74.    }
  75.    function getScore()
  76.    {
  77.       return com.leadpipe.attentionhog.Game.score;
  78.    }
  79.    function getHighScore()
  80.    {
  81.       return com.leadpipe.attentionhog.Game.highScore;
  82.    }
  83.    function setScore(s)
  84.    {
  85.       com.leadpipe.attentionhog.Game.score += Math.pow(s,2) * com.leadpipe.attentionhog.Game.scoreBase;
  86.       this.loveInc = 0;
  87.       var _loc3_ = 0;
  88.       while(_loc3_ < Math.pow(s,2))
  89.       {
  90.          this.loveInc += this.gaugeMain.getIncSpeed();
  91.          _loc3_ = _loc3_ + 1;
  92.       }
  93.       this.gaugeMain.setLevel(this.gaugeMain.getLevel() + this.loveInc);
  94.       _root.score = com.leadpipe.attentionhog.Game.score;
  95.    }
  96.    function captureHeart()
  97.    {
  98.       this.heartsCurrNum = this.heartsCurrNum + 1;
  99.       _root.hud_mc.hearts_txt.text = this.heartsCurrNum + " / " + this.heartsTargetNum;
  100.       if(this.heartsCurrNum >= this.heartsTargetNum)
  101.       {
  102.          this.endRound();
  103.       }
  104.    }
  105.    function setScoreMultiplier(s)
  106.    {
  107.       com.leadpipe.attentionhog.Game.scoreMultiplier = s;
  108.    }
  109.    function setup()
  110.    {
  111.       com.leadpipe.attentionhog.Game.score = 0;
  112.       this.proxThreshold = 75;
  113.       this.roundNum = 0;
  114.       _root.gotoAndStop("start_game");
  115.       _root.attachMovie("hud_mc","hud_mc",50000,{_y:0});
  116.       _root.attachMovie("infoBox" + this.roundNum,"infoBox" + this.roundNum,50001,{_x:200,_y:205});
  117.       this.gaugeMain = new com.leadpipe.attentionhog.Gauge();
  118.       this.loveFadeRate = 0.2;
  119.       this.gaugeMain.setSpeed(0.015,this.loveFadeRate);
  120.       this.gaugeMain.initMask(_root.hud_mc.gaugeMainMask_mc);
  121.       var _loc3_ = 0;
  122.       while(_loc3_ < 6)
  123.       {
  124.          this.gaugeSlop.push(new com.leadpipe.attentionhog.Gauge());
  125.          this.gaugeSlop[_loc3_].setLevel(0);
  126.          this.gaugeSlop[_loc3_].setSpeed(20,0.5);
  127.          this.gaugeSlop[_loc3_].initMask(_root.hud_mc["gauge" + _loc3_].mask_mc);
  128.          _root.hud_mc["gauge" + _loc3_]._alpha = 0;
  129.          _loc3_ = _loc3_ + 1;
  130.       }
  131.       _root.score = 0;
  132.       this.heartsTargetNum = (this.roundNum + 1) * 10;
  133.       this.heartsCurrNum = 0;
  134.       _root.hud_mc.hearts_txt.text = this.heartsCurrNum + " / " + this.heartsTargetNum;
  135.       this.setupHandlers();
  136.       this.pause(true);
  137.       this.musicOn(this.isMusicOn);
  138.       this.soundOn(this.isSoundOn);
  139.    }
  140.    function startRound()
  141.    {
  142.       this.gaugeMain.setLevel(100);
  143.       if(this.roundNum > 6)
  144.       {
  145.          this.itemsUnlocked = this.roundNum - 6;
  146.       }
  147.       else
  148.       {
  149.          this.itemsUnlocked = this.roundNum;
  150.       }
  151.       this.heartsTargetNum = (this.roundNum + 1) * 10;
  152.       this.loveFadeRate += 0.05;
  153.       this.gaugeMain.setSpeed(0.015,this.loveFadeRate);
  154.       this.heartsCurrNum = 0;
  155.       _root.hud_mc.hearts_txt.text = this.heartsCurrNum + " / " + this.heartsTargetNum;
  156.       this.playerDepthInit = 5000;
  157.       _root.attachMovie("player_mc","player_mc",this.playerDepthInit);
  158.       this.ghostDepthInit = 10000;
  159.       this.peopleDepthInit = 15000;
  160.       this.createPeople("person_mc",9,false);
  161.       this.itemDepthInit = 20000;
  162.       this.itemCntr = 0;
  163.       if(this.roundNum > 0)
  164.       {
  165.          _root.hud_mc["gauge" + (this.itemsUnlocked - 1)]._alpha = 100;
  166.          this.timerBonus = new com.leadpipe.attentionhog.Timer(this,"newBonus",2000,4000);
  167.          this.timerBonus.start();
  168.       }
  169.       this.timerBacon = new com.leadpipe.attentionhog.Timer(this,"newBacon",7000,14000);
  170.       this.timerBacon.start();
  171.       _root["infoBox" + this.roundNum].removeMovieClip();
  172.       this.music.start(0,1);
  173.       this.pause(false);
  174.    }
  175.    function endRound()
  176.    {
  177.       this.roundNum = this.roundNum + 1;
  178.       this.pause(true);
  179.       com.leadpipe.attentionhog.Person.destroyAll();
  180.       com.leadpipe.attentionhog.Item.destroyAll();
  181.       com.leadpipe.attentionhog.Timer.destroyAll();
  182.       com.leadpipe.attentionhog.Ghost.destroyAll();
  183.       com.leadpipe.attentionhog.Player.instance.destroy();
  184.       com.leadpipe.attentionhog.Ability.stopPowerUpAll();
  185.       this.music.stop("music");
  186.       _root.attachMovie("infoBox" + this.roundNum,"infoBox" + this.roundNum,50001,{_x:200,_y:205});
  187.       _root.hud_mc["gauge" + this.itemsUnlocked]._alpha = 100;
  188.       if(this.roundNum > this.roundMax)
  189.       {
  190.          if(this.winTimeoutID != null)
  191.          {
  192.             clearTimeout(this.winTimeoutID);
  193.          }
  194.          this.winTimeoutID = setTimeout(this,"gameOverWin",3500);
  195.       }
  196.    }
  197.    function go()
  198.    {
  199.       if(this.isPaused)
  200.       {
  201.          return undefined;
  202.       }
  203.       com.leadpipe.attentionhog.Player.getInstance().go();
  204.       com.leadpipe.attentionhog.Person.goAll();
  205.    }
  206.    function bonus()
  207.    {
  208.       if(random(150) < 2)
  209.       {
  210.          this.newBonus();
  211.       }
  212.       if(random(350) < 1)
  213.       {
  214.          this.newBacon();
  215.       }
  216.    }
  217.    function pause(p)
  218.    {
  219.       this.isPaused = p;
  220.       com.leadpipe.attentionhog.Player.getInstance().pause(this.isPaused);
  221.    }
  222.    function setupHandlers()
  223.    {
  224.       var game = this;
  225.       _root.onEnterFrame = function()
  226.       {
  227.          game.go();
  228.       };
  229.    }
  230.    function restart()
  231.    {
  232.       _root.gotoAndStop("menu");
  233.    }
  234.    function gameOver()
  235.    {
  236.       com.leadpipe.attentionhog.Person.destroyAll();
  237.       com.leadpipe.attentionhog.Item.destroyAll();
  238.       com.leadpipe.attentionhog.Timer.destroyAll();
  239.       com.leadpipe.attentionhog.Ghost.destroyAll();
  240.       com.leadpipe.attentionhog.Player.instance.destroy();
  241.       _root.hud_mc.removeMovieClip();
  242.       if(this.so.data.highScore == undefined)
  243.       {
  244.          this.so.data.highScore = 0;
  245.          this.so.flush();
  246.       }
  247.       com.leadpipe.attentionhog.Game.highScore = this.so.data.highScore;
  248.       if(com.leadpipe.attentionhog.Game.score > com.leadpipe.attentionhog.Game.highScore)
  249.       {
  250.          com.leadpipe.attentionhog.Game.highScore = com.leadpipe.attentionhog.Game.score;
  251.          this.so.data.highScore = com.leadpipe.attentionhog.Game.highScore;
  252.          this.so.flush();
  253.       }
  254.       _root.gotoAndStop("game_over");
  255.       stop();
  256.       _root.scoreFinal_txt.text = com.leadpipe.attentionhog.Game.score;
  257.       _root.scoreHigh_txt.text = com.leadpipe.attentionhog.Game.highScore;
  258.    }
  259.    function gameOverWin()
  260.    {
  261.       this.music.stop("music");
  262.       _root.hud_mc.removeMovieClip();
  263.       _root.infoBox7.removeMovieClip();
  264.       if(com.leadpipe.attentionhog.Game.score > com.leadpipe.attentionhog.Game.highScore)
  265.       {
  266.          com.leadpipe.attentionhog.Game.highScore = com.leadpipe.attentionhog.Game.score;
  267.       }
  268.       _root.gotoAndStop("game_over");
  269.       stop();
  270.       _root.scoreFinal_txt.text = com.leadpipe.attentionhog.Game.score;
  271.       _root.scoreHigh_txt.text = com.leadpipe.attentionhog.Game.highScore;
  272.    }
  273.    function die()
  274.    {
  275.       this.music.stop("music");
  276.    }
  277.    function createPeople(na, nu, ons)
  278.    {
  279.       var _loc3_ = 0;
  280.       while(_loc3_ < nu)
  281.       {
  282.          var _loc4_ = this.peopleDepthInit + _loc3_;
  283.          _root.attachMovie(na,"person" + _loc3_,_loc4_);
  284.          com.leadpipe.attentionhog.Person.instanceList[_loc3_].body_mc.gotoAndStop(random(com.leadpipe.attentionhog.Person.instanceList[_loc3_].body_mc._totalframes) + 1);
  285.          this.personSP = new flash.geom.Point(random(Stage.width),random(Stage.height));
  286.          if(ons)
  287.          {
  288.             com.leadpipe.attentionhog.Person.instanceList[_loc3_].startOnScreen();
  289.          }
  290.          else
  291.          {
  292.             com.leadpipe.attentionhog.Person.instanceList[_loc3_].startOffScreen();
  293.          }
  294.          _loc3_ = _loc3_ + 1;
  295.       }
  296.    }
  297.    static function getInstance()
  298.    {
  299.       if(com.leadpipe.attentionhog.Game.instance == null)
  300.       {
  301.          com.leadpipe.attentionhog.Game.instance = new com.leadpipe.attentionhog.Game();
  302.       }
  303.       return com.leadpipe.attentionhog.Game.instance;
  304.    }
  305.    function newBonus()
  306.    {
  307.       var _loc3_ = this.itemDepthInit + this.itemCntr;
  308.       _root.attachMovie("item_mc","item" + this.itemCntr,_loc3_);
  309.       this.itemCntr = (this.itemCntr + 1) % this.itemMax;
  310.    }
  311.    function newBacon()
  312.    {
  313.       var _loc3_ = this.itemDepthInit + this.itemCntr;
  314.       _root.attachMovie("bacon_mc","item" + this.itemCntr,_loc3_);
  315.       this.itemCntr = (this.itemCntr + 1) % this.itemMax;
  316.    }
  317. }
  318.