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

  1. WindMill = function(mc)
  2. {
  3.    this.mc = mc;
  4.    this.id = this.mc._name;
  5.    this.mc.obj = this;
  6.    var _loc3_ = GAME.mapScreenToGame(this.mc._x,this.mc._y);
  7.    this.game_x = _loc3_.game_x;
  8.    this.game_y = _loc3_.game_y;
  9.    this.minGust = this.min_game_x - this.game_x;
  10.    this.mc.min_power_marker = this.mc.hit_area;
  11.    this.maxPowerRadius = this.mc.max_power_marker._width / (100 / this.mc._xscale) / 2;
  12.    this.minPowerRadius = this.mc.min_power_marker._width / (100 / this.mc._xscale) / 2;
  13.    this.difPowerRadius = this.maxPowerRadius - this.minPowerRadius;
  14.    var _loc2_ = GAME.regLimbo[this.id + "_gauge"];
  15.    if(_loc2_ != undefined)
  16.    {
  17.       this.gauge_mc = _loc2_;
  18.    }
  19.    GAME.addListener(this);
  20.    GAME.gameFrame.addListener(this);
  21. };
  22. t = WindMill.prototype;
  23. t.hitByWindGust = function(windGust)
  24. {
  25.    if(this.status < 2)
  26.    {
  27.       return false;
  28.    }
  29.    var _loc3_ = Math.abs(windGust.game_x - this.game_x);
  30.    var _loc2_ = (_loc3_ - this.minPowerRadius) / this.difPowerRadius;
  31.    if(_loc2_ > 1)
  32.    {
  33.       _loc2_ = 1;
  34.    }
  35.    if(_loc2_ < 0)
  36.    {
  37.       _loc2_ = 0;
  38.    }
  39.    this.increaseSpeed(windGust.power * _loc2_);
  40.    GAME.adjustScore("hitWindMill",this);
  41. };
  42. t.increaseSpeed = function(speed)
  43. {
  44.    if(this.status < 2)
  45.    {
  46.       return false;
  47.    }
  48.    this.destSpeed += speed;
  49. };
  50. t.stopLoop = function()
  51. {
  52.    delete this.mc.onEnterFrame;
  53. };
  54. t.shutDown = function()
  55. {
  56.    this.status = 0;
  57.    this.friction = 0.93;
  58.    this.mc.onEnterFrame = function()
  59.    {
  60.       this.obj.shutDownLoop();
  61.    };
  62.    this.mc.gotoAndStop("idle");
  63. };
  64. t.overLoad = function()
  65. {
  66.    GAME.adjustScore("windMillOverload",this);
  67.    this.status = 1;
  68.    this.friction = 0.95;
  69.    this.shutDownTime = getTimer();
  70.    this.mc.gotoAndPlay("overload");
  71.    this.mc.half_circle.gotoAndPlay("powerdown");
  72.    this.gauge_mc.gotoAndPlay("overload");
  73. };
  74. t.startUp = function()
  75. {
  76.    this.onGameFrame = function()
  77.    {
  78.       this.loop();
  79.    };
  80.    this.friction = GAME.parameters.globalFriction;
  81.    this.status = 2;
  82. };
  83. t.reStartUp = function()
  84. {
  85.    this.startUp();
  86.    this.gauge_mc.gotoAndPlay("ready");
  87.    this.mc.gotoAndPlay("ready");
  88. };
  89. t.loop = function()
  90. {
  91.    this.adjustSpeed();
  92.    this.energyOutput = 0;
  93.    switch(this.status)
  94.    {
  95.       case 0:
  96.          this.drawGauge();
  97.          break;
  98.       case 1:
  99.          if(getTimer() - this.shutDownTime > this.maxShutDownTime)
  100.          {
  101.             this.reStartUp();
  102.          }
  103.          break;
  104.       case 2:
  105.          if(this.energyPer > 0)
  106.          {
  107.             this.status = 3;
  108.             this.mc.half_circle.gotoAndPlay("powerup");
  109.          }
  110.          break;
  111.       case 3:
  112.          if(this.energyPer <= 0)
  113.          {
  114.             this.status = 2;
  115.             break;
  116.          }
  117.          if(this.energyPer > 1)
  118.          {
  119.             this.overLoad();
  120.             break;
  121.          }
  122.          this.energyOutput = this.maxEnergyOutput * this.energyPer;
  123.          this.drawGauge();
  124.          break;
  125.    }
  126.    this.drawContents();
  127.    this.mc.speed_out = this.speed;
  128. };
  129. t.shutDownLoop = function()
  130. {
  131.    this.destSpeed *= this.friction;
  132.    this.speed += (this.destSpeed - this.speed) * 0.1;
  133.    this.energyPer = (this.speed - this.minSpeed) / this.difSpeed;
  134.    if(this.energyPer < 0)
  135.    {
  136.       this.energyPer = 0;
  137.    }
  138.    this.drawContents();
  139.    this.drawGauge();
  140. };
  141. t.adjustSpeed = function()
  142. {
  143.    this.destSpeed += this.baseWind;
  144.    this.destSpeed *= this.friction;
  145.    this.speed += (this.destSpeed - this.speed) * 0.1;
  146.    this.energyPer = (this.speed - this.minSpeed) / this.difSpeed;
  147. };
  148. t.drawContents = function()
  149. {
  150.    var _loc2_ = this.speed * 0.25;
  151.    this.mc.blades._rotation += _loc2_;
  152.    this.mc.shad.blades._rotation = this.mc.blades._rotation;
  153. };
  154. t.drawGauge = function()
  155. {
  156.    var _loc2_ = Math.floor(this.speed);
  157.    if(_loc2_ < 10)
  158.    {
  159.       _loc2_ = "0" + _loc2_;
  160.    }
  161.    this.gauge_mc.display_mph = _loc2_;
  162.    var _loc3_ = Math.round(this.gauge_mc.first_frame + this.energyPer * 100);
  163.    this.gauge_mc.gotoAndStop(_loc3_);
  164. };
  165. t.adjustSound = function()
  166. {
  167.    var _loc2_ = "";
  168.    if(this.speed > 40)
  169.    {
  170.       _loc2_ = "geo_windmill_hi_snd";
  171.    }
  172.    else if(this.speed > 20)
  173.    {
  174.       _loc2_ = "geo_windmill_med_snd";
  175.    }
  176.    else if(this.speed > 10)
  177.    {
  178.       _loc2_ = "geo_windmill_lo_snd";
  179.    }
  180.    else
  181.    {
  182.       _loc2_ = "none";
  183.    }
  184.    if(this.curSound != _loc2_)
  185.    {
  186.       Audio.stop(this.curSound);
  187.       this.curSound = _loc2_;
  188.       Audio.play(this.curSound);
  189.    }
  190. };
  191. t.onLevelStart = function()
  192. {
  193.    if(this.status == 0)
  194.    {
  195.       this.startUp();
  196.    }
  197. };
  198. t.onLevelComplete = function()
  199. {
  200.    this.shutDown();
  201. };
  202. t.onLevelIncomplete = function()
  203. {
  204.    this.shutDown();
  205. };
  206. t.shutDownTime = false;
  207. t.minGust = 0;
  208. t.maxShutDownTime = 5000;
  209. t.destSpeed = 0;
  210. t.speed = 0;
  211. t.rotationSpeed = 0;
  212. t.energyOutput = 0;
  213. t.energyPer = 0;
  214. t.baseWind = 0.01;
  215. t.maxEnergyOutput = GAME.parameters.maxEnergyPerWindMill;
  216. t.status = 0;
  217. t.friction = GAME.parameters.globalFriction;
  218. t.gauge_mc = false;
  219. t.game_x = 0;
  220. t.game_y = 0;
  221. t.min_game_x = 0;
  222. t.max_game_x = 0;
  223. t.id = "";
  224. t.minHalfCircleScale = 75;
  225. t.maxHalfCircleScale = 100;
  226. t.difHalfCircleScale = t.maxHalfCircleScale - t.minHalfCircleScale;
  227. t.minSpeed = GAME.parameters.minWindMillMPH;
  228. t.maxSpeed = GAME.parameters.maxWindMillMPH;
  229. t.difSpeed = GAME.parameters.maxWindMillMPH - GAME.parameters.minWindMillMPH;
  230. t.maxPowerRadius = 0;
  231. t.minPowerRadius = 0;
  232. t.difPowerRadius = 0;
  233. t.toString = function()
  234. {
  235.    return "[WindMill " + this.game_x + "," + this.game_y + "]";
  236. };
  237.