home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / eolica.swf / scripts / frame_15 / DoAction.as
Encoding:
Text File  |  2005-07-26  |  3.8 KB  |  179 lines

  1. EnergyMeter = function(mc)
  2. {
  3.    this.mc = mc;
  4.    this.mc.obj = this;
  5.    this.dots = new Array(false);
  6.    this.mc.onEnterComplete = function()
  7.    {
  8.       this.obj.onEnterComplete();
  9.    };
  10.    GAME.addListener(this);
  11.    GAME.fiveGameFrames.addListener(this);
  12. };
  13. t = EnergyMeter.prototype;
  14. t.onEnterComplete = function()
  15. {
  16. };
  17. t.startDraw = function()
  18. {
  19.    this.mc.onEnterFrame = function()
  20.    {
  21.       this.obj.drawLoop();
  22.    };
  23. };
  24. t.startTrack = function()
  25. {
  26.    this.stopLoop();
  27.    this.tracking = true;
  28. };
  29. t.stopTrack = function()
  30. {
  31.    this.tracking = false;
  32.    this.stopLoop();
  33. };
  34. t.startLoop = function()
  35. {
  36.    this.mc.onEnterFrame = function()
  37.    {
  38.       this.obj.loop();
  39.    };
  40. };
  41. t.stopLoop = function()
  42. {
  43.    delete this.mc.onEnterFrame;
  44. };
  45. t.trackLoop = function()
  46. {
  47.    this.destEnergy += GAME.getCurEnergyOutput() / 6.2;
  48.    this.perEnergy = this.destEnergy / this.totalEnergyRequired;
  49.    this.mc.per_out = this.perEnergy;
  50.    this.draw();
  51.    if(this.perEnergy >= 1)
  52.    {
  53.       this.mc.goal_dot.show();
  54.       this.stopTrack();
  55.       GAME.curLevelComplete();
  56.    }
  57. };
  58. t.drawLoop = function()
  59. {
  60.    this.perEnergy *= 0.8;
  61.    this.mc.per_out = this.perEnergy;
  62.    this.draw();
  63. };
  64. t.draw = function()
  65. {
  66.    var _loc5_ = this.curDot;
  67.    this.curDot = Math.floor(this.perEnergy * this.dots.length);
  68.    this.mc.dot_out = this.curDot;
  69.    if(this.curDot > _loc5_)
  70.    {
  71.       this.fillDots(_loc5_ + 1,this.curDot);
  72.    }
  73.    else if(this.curDot < _loc5_)
  74.    {
  75.       this.removeDots(this.curDot,_loc5_);
  76.    }
  77.    var _loc6_ = GAME.lights.length;
  78.    var _loc4_ = Math.floor(_loc6_ * this.perEnergy);
  79.    var _loc3_ = GAME.lights._on.length;
  80.    _root.light_out = "total:" + _loc6_ + ", dest on:" + _loc4_ + ", are on:" + _loc3_;
  81.    if(_loc3_ < _loc4_)
  82.    {
  83.       _root.light_out += "  ON";
  84.       this.turnLightsOn(_loc4_ - _loc3_);
  85.    }
  86.    else if(_loc3_ > _loc4_)
  87.    {
  88.       _root.light_out += "  OFF";
  89.       this.turnLightsOff(_loc3_ - _loc4_);
  90.    }
  91. };
  92. t.fillDots = function(from, to)
  93. {
  94.    var _loc2_ = from;
  95.    while(_loc2_ <= to)
  96.    {
  97.       var _loc3_ = this.dots[_loc2_];
  98.       Audio.play("geo_wind_energyup_1_snd");
  99.       _loc3_.gotoAndPlay("poweron");
  100.       _loc2_ = _loc2_ + 1;
  101.    }
  102. };
  103. t.removeDots = function(from, to)
  104. {
  105.    var _loc2_ = from;
  106.    while(_loc2_ <= to)
  107.    {
  108.       var _loc3_ = this.dots[_loc2_];
  109.       _loc3_.gotoAndPlay("poweroff");
  110.       _loc2_ = _loc2_ + 1;
  111.    }
  112. };
  113. t.addDot = function(mc)
  114. {
  115.    this.dots.push(mc);
  116. };
  117. t.turnLightsOn = function(num)
  118. {
  119.    var _loc3_ = 0;
  120.    while(_loc3_ < num)
  121.    {
  122.       var _loc2_ = Math.floor(Math.random() * GAME.lights._off.length);
  123.       var _loc1_ = GAME.lights._off[_loc2_];
  124.       _loc1_.gotoAndPlay("poweron");
  125.       GAME.lights._on.push(_loc1_);
  126.       GAME.lights._off.splice(_loc2_,1);
  127.       _loc3_ = _loc3_ + 1;
  128.    }
  129. };
  130. t.turnLightsOff = function(num)
  131. {
  132.    var _loc3_ = 0;
  133.    while(_loc3_ < num)
  134.    {
  135.       var _loc2_ = Math.floor(Math.random() * GAME.lights._on.length);
  136.       var _loc1_ = GAME.lights._on[_loc2_];
  137.       _loc1_.gotoAndPlay("poweroff");
  138.       GAME.lights._off.push(_loc1_);
  139.       GAME.lights._on.splice(_loc2_,1);
  140.       _loc3_ = _loc3_ + 1;
  141.    }
  142. };
  143. t.reset = function()
  144. {
  145.    this.destEnergy = 0;
  146.    this.startDraw();
  147. };
  148. t.onLevelReset = function()
  149. {
  150.    this.mc.goal_dot.reset();
  151.    this.reset();
  152. };
  153. t.onLevelEnter = function()
  154. {
  155.    this.mc.goal_dot.reset();
  156.    this.reset();
  157. };
  158. t.onLevelStart = function(level)
  159. {
  160.    this.mc.goal_dot.reset();
  161.    this.totalEnergyRequired = level.totalEnergyRequired;
  162.    this.startTrack();
  163. };
  164. t.onFiveGameFrames = function()
  165. {
  166.    if(this.tracking)
  167.    {
  168.       this.trackLoop();
  169.    }
  170. };
  171. t.tracking = false;
  172. t.dots = false;
  173. t.totalEnergyRequired;
  174. t.perEnergy = 0;
  175. t.curDot = 0;
  176. t.destEnergy = 0;
  177. t.curEnergy = 0;
  178. t.mc = false;
  179.