home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / eolica.swf / scripts / frame_13 / DoAction.as < prev   
Encoding:
Text File  |  2005-07-26  |  2.3 KB  |  99 lines

  1. Generator = function(mc, type)
  2. {
  3.    this.mc = mc;
  4.    this.type = type;
  5.    this.mc.obj = this;
  6.    var _loc2_ = mc.frequency_p.split("-");
  7.    this.minTime = Number(_loc2_[0]);
  8.    this.maxTime = Number(_loc2_[1]);
  9.    if(isNaN(this.maxTime) || this.maxTime == undefined)
  10.    {
  11.       this.maxTime = this.minTime;
  12.    }
  13.    this.difTime = this.maxTime - this.minTime;
  14.    this.setNextTime();
  15.    this.maxItems = Number(this.mc.max_p);
  16.    if(this.maxItems == -1)
  17.    {
  18.       this.maxItems = 1000;
  19.    }
  20.    this.lastTime = GAME.gameTimeElapsed;
  21.    this.timeElapsed = 0;
  22.    this.spawn_areas = new Array(this.mc);
  23.    GAME.addListener(this);
  24.    GAME.tenGameFrames.addListener(this);
  25. };
  26. t = Generator.prototype;
  27. t.mc = false;
  28. t.id = "";
  29. t.type = "";
  30. t.spawn_areas = false;
  31. t.minTime = 0;
  32. t.maxTime = 0;
  33. t.nextTime = 0;
  34. t.lastTime = 0;
  35. t.itemsGenerated = 0;
  36. t.maxItems = 0;
  37. t.loop = function()
  38. {
  39.    if(this.spawn_areas[0]._name == undefined)
  40.    {
  41.       this.remove();
  42.    }
  43.    this.timeElapsed = GAME.gameTimeElapsed - this.lastTime;
  44.    this.mc.time_out = this.timeElapsed;
  45.    if(this.timeElapsed >= this.nextTime)
  46.    {
  47.       this.generateItem();
  48.    }
  49. };
  50. t.stopLoop = function()
  51. {
  52.    GAME.tenGameFrames.removeListener(this);
  53. };
  54. t.generateItem = function()
  55. {
  56.    var _loc2_ = this.spawn_areas[Math.round(Math.random() * (this.spawn_areas.length - 1))];
  57.    var _loc4_ = _loc2_._x + Math.random() * _loc2_._xscale;
  58.    var _loc5_ = _loc2_._y + Math.random() * _loc2_._yscale;
  59.    var _loc3_ = GAME.mapScreenToGame(_loc4_,_loc5_);
  60.    var _loc7_ = _loc3_.game_x;
  61.    var _loc6_ = _loc3_.game_y;
  62.    var _loc8_ = _loc2_.flip_p;
  63.    GAME.createGeoCitizen(this.type,_loc7_,_loc6_,_loc8_);
  64.    this.itemsGenerated = this.itemsGenerated + 1;
  65.    if(this.itemsGenerated >= this.maxItems)
  66.    {
  67.       this.stopLoop();
  68.    }
  69.    this.lastTime = GAME.gameTimeElapsed;
  70.    this.setNextTime();
  71. };
  72. t.setNextTime = function()
  73. {
  74.    this.nextTime = this.minTime + this.difTime * Math.random();
  75. };
  76. t.addSlave = function(slave)
  77. {
  78.    this.spawn_areas.push(slave);
  79. };
  80. t.remove = function()
  81. {
  82.    GAME.tenGameFrames.removeListener(this);
  83.    removeMovieClip(this.mc);
  84. };
  85. t.onLevelStart = function()
  86. {
  87. };
  88. t.onLevelComplete = function()
  89. {
  90.    this.remove();
  91. };
  92. t.onLevelIncomplete = function()
  93. {
  94. };
  95. t.onTenGameFrames = function()
  96. {
  97.    this.loop();
  98. };
  99.