• Content Count

  • Joined

  • Last visited

  1. Hey Parasyte, The if statement was indeed the issue, thanks for looking through the code :). Also thanks for all the other tips and heads up i really appreciate it. The playing field is for now a maximum of 100px by 100px so that will reduce the total amount of plants to 10k. Now this is working as intended my goal is to build a simple "creature" which feeds of the grass (removing energy and adding it to itself)and moves around/multiplies as needed. For v1 the goal is that the attributes of the creature and the plants have a chance to be randomly a little bit bigger or smaller than it's parent, in other words trying to simulate evolution. Let me say again, Thanks for your time and help
  2. Hello all, I have been working on a little simulator having defeated a few issues i am now at a point where i am guessing where the issue is. Probably it's something i missed somewhere else but i am not able to get it resolved, any help would be great I am trying to have a plant reproduce itself realy basic and it kinda works. But after it has reproduced the plant should be able to do it a few more times before it is out of seeds. At this point the plant reproduces once and it's child also reproduce once and so on. But i want the parent plant to reproduce another x times. So for basic code this is what happens: GAME.JS In the game.JS in the loaded function i place my plant in the pool me.pool.register("basicPlant", game.BasicPlant); PLAY.JS I intialize my plantmanager which holds some logic for all the plants in the onResetEvent this.plantManager = new game.PlantManager(); Then for the whole shabang this is the plantmanager. In the initializer the first plant is generated with the seed function. game.PlantManager = me.Container.extend({ init: function () { plantMap = this.CreatePlantMap( this.seed() return true }, CreatePlantMap: function(rows) { var arr = []; for (var i=0;i<rows;i++) { arr[i] = this.CreatePlantTiles(i,rows); } return arr; }, CreatePlantTiles: function(x,size) { var arr = []; for(var i=0;i<size;i++){ arr.push({x:x, y:i, plant:false}) } return arr }, collectTiles: function(x,y) { return [ plantMap[x+1][y], plantMap[x+1][y+1], plantMap[x+1][y-1], plantMap[x][y+1], plantMap[x][y-1], plantMap[x-1][y], plantMap[x-1][y+1], plantMap[x-1][y-1] ] }, getGrowthLocation: function(array) { plantlocation ={if(!a.plant){return a}}) clean = plantlocation.filter(function(a){ return a != undefined }) random = clean[Math.floor(Math.random() * clean.length)] return random }, createPlant: function (parrent) { x = parrent.pos.x y = parrent.pos.y growthLocation = this.getGrowthLocation(this.collectTiles(x,y)) if(growthLocation && !plantMap[x][y].plant){ plantMap[x][y].plant = true plant = me.pool.pull("basicPlant", growthLocation.x, growthLocation.y);, 1); }; return true }, removePlant: function (plant) {; plantMap[plant.pos.x][plant.pos.y].plant = false return true }, seed: function(){ this.createPlant({pos:{x:50,y:50}}) return true }, }); And finaly the plant itself game.BasicPlant = me.Entity.extend({ init:function (x, y) { this._super(me.Entity, "init", [x, y, { image: "green", width: 1, height: 1, }]); = [x,y] = 100 this.seeds = 5 this.max_age = 1500 this.age = 0 return true }, update: function (dt) { this._super(me.Entity, "update", [dt]); this.age++ if( == 0 || this.age == this.max_age){ this.die() } if( > 150 && this.seeds > 0){ this.multiply() this.seeds = this.seeds - 1 } return true; }, multiply : function(){ -= 100 game.playScreen.plantManager.createPlant(this) return true }, die : function(){ game.playScreen.plantManager.removePlant(this); return true } });