home *** CD-ROM | disk | FTP | other *** search
- Generator = function(mc, type)
- {
- this.mc = mc;
- this.type = type;
- this.mc.obj = this;
- var _loc2_ = mc.frequency_p.split("-");
- this.minTime = Number(_loc2_[0]);
- this.maxTime = Number(_loc2_[1]);
- if(isNaN(this.maxTime) || this.maxTime == undefined)
- {
- this.maxTime = this.minTime;
- }
- this.difTime = this.maxTime - this.minTime;
- this.setNextTime();
- this.maxItems = Number(this.mc.max_p);
- if(this.maxItems == -1)
- {
- this.maxItems = 1000;
- }
- this.lastTime = GAME.gameTimeElapsed;
- this.timeElapsed = 0;
- this.spawn_areas = new Array(this.mc);
- GAME.addListener(this);
- GAME.tenGameFrames.addListener(this);
- };
- t = Generator.prototype;
- t.mc = false;
- t.id = "";
- t.type = "";
- t.spawn_areas = false;
- t.minTime = 0;
- t.maxTime = 0;
- t.nextTime = 0;
- t.lastTime = 0;
- t.itemsGenerated = 0;
- t.maxItems = 0;
- t.loop = function()
- {
- if(this.spawn_areas[0]._name == undefined)
- {
- this.remove();
- }
- this.timeElapsed = GAME.gameTimeElapsed - this.lastTime;
- this.mc.time_out = this.timeElapsed;
- if(this.timeElapsed >= this.nextTime)
- {
- this.generateItem();
- }
- };
- t.stopLoop = function()
- {
- GAME.tenGameFrames.removeListener(this);
- };
- t.generateItem = function()
- {
- var _loc2_ = this.spawn_areas[Math.round(Math.random() * (this.spawn_areas.length - 1))];
- var _loc4_ = _loc2_._x + Math.random() * _loc2_._xscale;
- var _loc5_ = _loc2_._y + Math.random() * _loc2_._yscale;
- var _loc3_ = GAME.mapScreenToGame(_loc4_,_loc5_);
- var _loc7_ = _loc3_.game_x;
- var _loc6_ = _loc3_.game_y;
- var _loc8_ = _loc2_.flip_p;
- GAME.createGeoCitizen(this.type,_loc7_,_loc6_,_loc8_);
- this.itemsGenerated = this.itemsGenerated + 1;
- if(this.itemsGenerated >= this.maxItems)
- {
- this.stopLoop();
- }
- this.lastTime = GAME.gameTimeElapsed;
- this.setNextTime();
- };
- t.setNextTime = function()
- {
- this.nextTime = this.minTime + this.difTime * Math.random();
- };
- t.addSlave = function(slave)
- {
- this.spawn_areas.push(slave);
- };
- t.remove = function()
- {
- GAME.tenGameFrames.removeListener(this);
- removeMovieClip(this.mc);
- };
- t.onLevelStart = function()
- {
- };
- t.onLevelComplete = function()
- {
- this.remove();
- };
- t.onLevelIncomplete = function()
- {
- };
- t.onTenGameFrames = function()
- {
- this.loop();
- };
-