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

  1. GAME = new Object();
  2. GAME.mc = false;
  3. GAME.interface_mc = this;
  4. AsBroadcaster.initialize(GAME);
  5. _global.WM_GAME = GAME;
  6. t = GAME;
  7. t.init = function()
  8. {
  9.    this.curGrid = new Grid(1,24,1000,50,GAME.interface_mc.grid_mc);
  10.    this.changeWindDirection(0);
  11.    this.init3D();
  12.    this.mc = this.interface_mc.viewport_mc;
  13.    this.broadcastMessage("onGameInit");
  14.    this.gotoLevel(1);
  15.    this.gameSecond.addListener(this);
  16. };
  17. t.loop = function()
  18. {
  19.    switch(this.status)
  20.    {
  21.       case 0:
  22.       case 1:
  23.          break;
  24.       case 2:
  25.          this.gameTimeElapsed += (getTimer() - this.lastTime) / 1000;
  26.          this.gameFramesElapsed = this.gameFramesElapsed + 1;
  27.          this.interface_mc.timeelasped_out = this.gameTimeElapsed;
  28.          this.lastTime = getTimer();
  29.          this.checkTimers();
  30.          this.cleanListener();
  31.    }
  32. };
  33. t.deathMarker = 0;
  34. t.cleanListener = function()
  35. {
  36.    if(this.deathMarker >= this._listeners.length)
  37.    {
  38.       this.deathMarker = 0;
  39.    }
  40.    var _loc3_ = this._listeners[this.deathMarker];
  41.    if(_loc3_ == undefined || typeof _loc3_ == "movieclip" && _loc3_._name == undefined || _loc3_.markedForDeath)
  42.    {
  43.       this._listeners.splice(this.deathMarker,1);
  44.    }
  45.    else
  46.    {
  47.       this.deathMarker = this.deathMarker + 1;
  48.    }
  49.    _root.test_num_listeners = this._listeners.length;
  50. };
  51. t.mouseDownHandler = function()
  52. {
  53.    if(this.status == 2)
  54.    {
  55.       this.curBellows.blowWindGust();
  56.       this.broadcastMessage("onGameMouseDown");
  57.    }
  58. };
  59. t.mouseUpHandler = function()
  60. {
  61.    if(this.status == 2)
  62.    {
  63.       this.broadcastMessage("onGameMouseUp");
  64.    }
  65. };
  66. t.mouseOverHandler = function()
  67. {
  68.    this.isMouseOver = true;
  69.    if(this.status == 3)
  70.    {
  71.    }
  72.    if(this.status == 2)
  73.    {
  74.       this.broadcastMessage("onGameMouseOver");
  75.    }
  76. };
  77. t.mouseOutHandler = function()
  78. {
  79.    this.isMouseOver = false;
  80.    if(this.status == 2)
  81.    {
  82.       this.broadcastMessage("onGameMouseOut");
  83.    }
  84. };
  85. t.curBellows = false;
  86. t.hitObjects = new Array();
  87. t.windGusts = new Array();
  88. t.windMills = new Array();
  89. t.lights = new Array();
  90. t.lights._off = new Array();
  91. t.lights._on = new Array();
  92. t.regBellows = function(mc)
  93. {
  94.    if(this.curBellows == false)
  95.    {
  96.       this.curBellows = new Bellows(mc);
  97.    }
  98. };
  99. t.regWindMill = function(mc)
  100. {
  101.    var _loc2_ = new WindMill(mc);
  102.    this.windMills.push(_loc2_);
  103.    this.addHitObject(_loc2_);
  104. };
  105. t.curGenerators = new Array();
  106. t.regGenerator = function(mc, type)
  107. {
  108.    if(mc.mode_p.toLowerCase() == "slave")
  109.    {
  110.       var _loc3_ = this.curGenerators[type];
  111.       if(_loc3_ == undefined)
  112.       {
  113.          this.regLimbo[type + "_slave"];
  114.       }
  115.       else
  116.       {
  117.          _loc3_.addSlave(mc);
  118.       }
  119.    }
  120.    else
  121.    {
  122.       _loc3_ = new Generator(mc,type);
  123.       this.curGenerators[type] = _loc3_;
  124.       var _loc4_ = this.regLimbo[type + "_slave"];
  125.       if(_loc4_ != undefined)
  126.       {
  127.          _loc3_.addSlave(_loc4_);
  128.       }
  129.    }
  130. };
  131. t.clearGenerators = function()
  132. {
  133.    while(this.curGenerators.length > 0)
  134.    {
  135.       var _loc2_ = this.curGenerators.pop();
  136.       _loc2_.remove();
  137.    }
  138. };
  139. t.curWindGenerator = false;
  140. t.regWindGenerator = function(mc)
  141. {
  142.    var _loc1_ = new WindGenerator(mc);
  143. };
  144. t.createJetStreamIcon = function(game_x, game_y)
  145. {
  146.    var _loc2_ = new JetStreamIcon(game_x,game_y);
  147.    this.addHitObject(_loc2_);
  148. };
  149. t.regGeoCitizen = function(type, mc)
  150. {
  151.    var _loc2_ = new GeoCitizen(type,mc);
  152.    this.addHitObject(_loc2_);
  153. };
  154. t.createGeoCitizen = function(type, game_x, game_y, isFlipped)
  155. {
  156.    var _loc2_ = new GeoCitizen(type,game_x,game_y,isFlipped);
  157.    this.addHitObject(_loc2_);
  158. };
  159. t.regLight = function(mc)
  160. {
  161.    this.lights.push(mc);
  162.    this.lights._off.push(mc);
  163. };
  164. t.addHitObject = function(obj)
  165. {
  166.    var _loc4_ = this.hitObjects.push(obj) - 1;
  167.    this.hitObjects[obj.id] = _loc4_;
  168.    this.curGrid.placeInGrid(obj,obj.game_x,obj.game_y);
  169.    var _loc3_ = obj.mc.hit_area.getBounds(this.mc);
  170.    obj.min_game_x = _loc3_.xMin;
  171.    obj.max_game_x = _loc3_.xMax;
  172. };
  173. t.removeHitObject = function(obj)
  174. {
  175.    var _loc3_ = this.hitObjects[obj.id];
  176.    this.hitObjects.splice(_loc3_,1);
  177.    this.curGrid.removeFromGrid(obj);
  178.    delete this.hitObjects[obj.id];
  179. };
  180. t.curEnergyMeter = false;
  181. t.curTimer = false;
  182. t.curWindGauge = false;
  183. t.curScoreDisplay = false;
  184. t.curJetStreamTimer = false;
  185. t.curLevelDisplay = false;
  186. t.regWindMillGauge = function(mc)
  187. {
  188.    var _loc4_ = mc._name.substring(0,mc._name.indexOf("_gauge"));
  189.    var _loc3_ = this.mc[_loc4_].obj;
  190.    if(_loc3_ != undefined)
  191.    {
  192.       _loc3_.gauge_mc = mc;
  193.    }
  194.    else
  195.    {
  196.       this.regLimbo[mc._name] = mc;
  197.    }
  198. };
  199. t.regWindGauge = function(mc)
  200. {
  201.    this.curWindGauge = new WindGauge(mc);
  202. };
  203. t.regEnergyMeter = function(mc)
  204. {
  205.    this.curEnergyMeter = new EnergyMeter(mc);
  206. };
  207. t.regTimer = function(mc)
  208. {
  209.    this.curTimer = new Timer(mc);
  210. };
  211. t.regScoreDisplay = function(mc)
  212. {
  213.    this.curScoreDisplay = new ScoreDisplay(mc);
  214. };
  215. t.regJetStreamTimer = function(mc)
  216. {
  217.    this.curJetStreamTimer = new JetStreamTimer(mc);
  218. };
  219. t.regLevelDisplay = function(mc)
  220. {
  221.    this.curLevelDisplay = mc;
  222. };
  223. t.jetStreamEnabled = false;
  224. t.turnOnJetStream = function()
  225. {
  226.    this.jetStreamEnabled = true;
  227.    this.curBellows.turnOnJetStream();
  228.    this.curJetStreamTimer.start(5);
  229. };
  230. t.turnOffJetStream = function()
  231. {
  232.    this.jetStreamEnabled = false;
  233.    this.curBellows.turnOffJetStream();
  234.    this.curJetStreamTimer.stop();
  235. };
  236. t.windDirection = 0;
  237. t.windSpeed = 4;
  238. t.windAdjustX = 0;
  239. t.windAdjustY = 0;
  240. t.changeWindDirection = function(direction)
  241. {
  242.    this.windDirection = Number(direction);
  243.    var _loc2_ = direction / 57.29577951308232;
  244.    this.windAdjustX = Math.sin(_loc2_) * this.windSpeed;
  245.    this.windAdjustY = Math.cos(_loc2_) * this.windSpeed;
  246.    this.broadcastMessage("onWindDirectionChange",this.windDirection);
  247. };
  248. t.score = 0;
  249. t.setScore = function(amount)
  250. {
  251.    this.score = amount;
  252.    this.curScoreDisplay.showScore(this.score);
  253. };
  254. t.adjustScore = function(amount, caller)
  255. {
  256.    if(typeof amount == "string")
  257.    {
  258.       amount = this.parameters.points[amount];
  259.    }
  260.    this.score += amount;
  261.    if(this.score < 0)
  262.    {
  263.       this.score = 0;
  264.    }
  265.    this.curScoreDisplay.showScore(this.score);
  266.    this.checkScore();
  267.    if(caller != undefined)
  268.    {
  269.       this.showPoints(amount,caller);
  270.    }
  271. };
  272. t.showPoints = function(amount, caller)
  273. {
  274.    var _loc5_ = amount <= 0 ? "neg" : "pos";
  275.    this.interface_mc.point_dest.attachMovie("point_" + _loc5_ + "_ani","p" + GAME.drawIndex,GAME.drawIndex);
  276.    var _loc4_ = this.interface_mc.point_dest["p" + GAME.drawIndex];
  277.    GAME.drawIndex = GAME.drawIndex + 1;
  278.    _loc4_.text = _loc5_ != "pos" ? "" : "+";
  279.    _loc4_.text += String(amount);
  280.    if(caller.mc.point_marker != undefined)
  281.    {
  282.       var _loc3_ = {x:caller.mc.point_marker._x,y:caller.mc.point_marker._y};
  283.       caller.mc.localToGlobal(_loc3_);
  284.       GAME.mc.localToGlobal(_loc3_);
  285.       var _loc7_ = _loc3_.x;
  286.       var _loc6_ = _loc3_.y;
  287.    }
  288.    else
  289.    {
  290.       _loc7_ = caller.mc._x;
  291.       _loc6_ = caller.mc._y;
  292.    }
  293.    _loc4_._x = _loc7_;
  294.    _loc4_._y = _loc6_;
  295. };
  296. t.checkScore = function()
  297. {
  298. };
  299. t.levels = new Array(false);
  300. t.curLevel = false;
  301. t.onCurLevelEnterComplete = function()
  302. {
  303.    this.broadcastMessage("onLevelEnter",this.curLevel);
  304.    this.interface_mc.ready_set_mc.gotoAndPlay("show");
  305. };
  306. t.curLevelStart = function()
  307. {
  308.    this.setStatus(2);
  309.    this.broadcastMessage("onLevelStart",this.curLevel);
  310. };
  311. t.addLevel = function(a)
  312. {
  313.    var _loc2_ = new Level(a);
  314.    var _loc3_ = this.levels.push(_loc2_) - 1;
  315.    this.levels[a.id] = _loc2_;
  316.    _loc2_.num = _loc3_;
  317. };
  318. t.gotoLevel = function(id)
  319. {
  320.    this.curLevel = this.levels[id];
  321.    this.clearGenerators();
  322.    this.mc.gotoAndPlay(this.curLevel.id);
  323.    this.setStatus(1);
  324.    this.broadcastMessage("onLevelEnterStart",this.curLevel);
  325.    this.curLevelDisplay.gotoAndPlay(this.curLevel.id);
  326. };
  327. t.restartCurLevel = function()
  328. {
  329.    this.curPower = 0;
  330.    this.interface_mc.ready_set_mc.gotoAndPlay("show");
  331.    _global.gChangeLevel = false;
  332.    this.setStatus(1);
  333.    this.broadcastMessage("onLevelRestart",this.curLevel);
  334.    this.broadcastMessage("onLevelEnter",this.curLevel);
  335. };
  336. t.repeatLevel = t.restartCurLevel;
  337. t.nextLevel = function()
  338. {
  339.    this.gotoLevel(this.curLevel.num + 1);
  340.    this.broadcastMessage("onNextLevel");
  341. };
  342. t.curLevelComplete = function()
  343. {
  344.    Audio.play("geo_wind_levelup_1_snd");
  345.    this.broadcastMessage("onLevelComplete",this.curLevel);
  346.    if(STAND_ALONE)
  347.    {
  348.       this.interface_mc.temp_completer.gotoAndPlay("show");
  349.    }
  350.    else
  351.    {
  352.       _global.gUser.geoscore = parseInt(_global.gUser.geoscore,10) + parseInt(this.score,10);
  353.       _global.gChangeLevel = true;
  354.       _global.gGameLevelIsComplete = true;
  355.       if(this.curLevel.id == "level5")
  356.       {
  357.          _global.trackNavClick("Island.Game2.Gamecomplete");
  358.       }
  359.       else
  360.       {
  361.          _global.trackNavClick("Island.Game2.Levelcomplete");
  362.       }
  363.    }
  364.    this.setScore(0);
  365.    this.setStatus(1);
  366. };
  367. t.timeOut = function()
  368. {
  369.    this.broadcastMessage("onLevelIncomplete",this.curLevel);
  370.    if(STAND_ALONE)
  371.    {
  372.       this.interface_mc.temp_incompleter.gotoAndPlay("show");
  373.    }
  374.    else
  375.    {
  376.       _global.gChangeLevel = true;
  377.       _global.gGameLevelIsComplete = false;
  378.       _global.trackNavClick("Island.Game2.Timesup");
  379.    }
  380.    this.setScore(0);
  381.    this.setStatus(1);
  382. };
  383. t.isPaused = false;
  384. t.pause = function()
  385. {
  386.    this.setStatus(3);
  387.    this.isPaused = true;
  388.    this.broadcastMessage("onGamePause",this.curLevel);
  389.    this.interface_mc.pauser_mc.gotoAndPlay("show");
  390. };
  391. t.unpause = function()
  392. {
  393.    this.setStatus(2);
  394.    this.isPaused = false;
  395.    this.broadcastMessage("onGameUnpause",this.curLevel);
  396.    this.interface_mc.pauser_mc.gotoAndPlay("hide");
  397. };
  398. t.setYOrigin = function(screen_y)
  399. {
  400.    this.yOrigin = screen_y;
  401. };
  402. t.curEnergy = 0;
  403. t.getCurEnergyOutput = function()
  404. {
  405.    var _loc4_ = 0;
  406.    var _loc2_ = 0;
  407.    while(_loc2_ < this.windMills.length)
  408.    {
  409.       var _loc3_ = this.windMills[_loc2_];
  410.       _loc4_ += _loc3_.energyOutput;
  411.       _loc2_ = _loc2_ + 1;
  412.    }
  413.    return _loc4_;
  414. };
  415. t.setStatus = function(status)
  416. {
  417.    if(status == 2)
  418.    {
  419.       this.lastTime = getTimer();
  420.    }
  421.    this.status = status;
  422. };
  423. t.removeObject = function(obj)
  424. {
  425.    this.removeHitObject(this);
  426.    removeMovieClip(obj.mc);
  427. };
  428. t.drawIndex = 1;
  429. t.yArray = false;
  430. t.maxWindGusts = 0;
  431. t.yOrigin = 0;
  432. t.curGrid = false;
  433. t.isMouseOver = false;
  434. t.lastTime = getTimer();
  435. t.gameTimeElapsed = 0;
  436. t.gameFramesElapsed = 0;
  437. t.status = 0;
  438. t.regLimbo = new Object();
  439. t.parameters = {minWindMillMPH:15,maxWindMillMPH:55,maxEnergyPerWindMill:4,globalFriction:0.998,energyConversion:1,windGustTooFarY:1200,points:{hitWindMill:100,windMillOverload:-200,timerSecond:20,hitGeoCitizen_picknicker:-200,hitGeoCitizen_windboarder:200,hitGeoCitizen_hangglider:200,hitGeoCitizen_kiteflyer:-200}};
  440.