variable ranges of banana growth
This commit is contained in:
parent
f82f3412ae
commit
bd778da8ca
|
|
@ -2,6 +2,10 @@ var modName = "mods/human_edit.js";
|
||||||
var onTryMoveIntoMod = "mods/onTryMoveInto.js";
|
var onTryMoveIntoMod = "mods/onTryMoveInto.js";
|
||||||
|
|
||||||
if(enabledMods.includes(onTryMoveIntoMod)) {
|
if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
|
randomNumberFromOneToThree = function() {
|
||||||
|
return 1 + Math.floor(Math.random() * 3)
|
||||||
|
};
|
||||||
|
|
||||||
debugSpeedGrowth = false;
|
debugSpeedGrowth = false;
|
||||||
logLeaves = false;
|
logLeaves = false;
|
||||||
bananaAttachWhitelist = ["banana_pseudostem","banana_peduncle_1","banana_peduncle_2","petal","banana_leaf","banana_plant_top","banana"];
|
bananaAttachWhitelist = ["banana_pseudostem","banana_peduncle_1","banana_peduncle_2","petal","banana_leaf","banana_plant_top","banana"];
|
||||||
|
|
@ -12,7 +16,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
||||||
};
|
};
|
||||||
|
|
||||||
bananaDirtElements = ["dirt","mud","sand","wet_sand","clay_soil","mycelium"];
|
bananaDirtElements = ["dirt","mud","sand","wet_sand","clay_soil","mycelium","grass"];
|
||||||
|
|
||||||
function logPixelCoords(pixel) {
|
function logPixelCoords(pixel) {
|
||||||
return `(${pixel.x}, ${pixel.y})`
|
return `(${pixel.x}, ${pixel.y})`
|
||||||
|
|
@ -36,6 +40,10 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
elements.banana_seed = {
|
elements.banana_seed = {
|
||||||
color: "#3b3b2e",
|
color: "#3b3b2e",
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
|
if(pixel.bananaRange === null) {
|
||||||
|
pixel.bananaRange = randomNumberFromOneToThree();
|
||||||
|
};
|
||||||
|
|
||||||
if (isEmpty(pixel.x,pixel.y+1)) {
|
if (isEmpty(pixel.x,pixel.y+1)) {
|
||||||
movePixel(pixel,pixel.x,pixel.y+1);
|
movePixel(pixel,pixel.x,pixel.y+1);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -49,6 +57,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
if (isEmpty(pixel.x,pixel.y-1)) {
|
if (isEmpty(pixel.x,pixel.y-1)) {
|
||||||
movePixel(pixel,pixel.x,pixel.y-1);
|
movePixel(pixel,pixel.x,pixel.y-1);
|
||||||
createPixel("banana_pseudostem",pixel.x,pixel.y+1);
|
createPixel("banana_pseudostem",pixel.x,pixel.y+1);
|
||||||
|
pixelMap[pixel.x][pixel.y+1].bananaRange = pixel.bananaRange; //pass banana range down to pseudostem
|
||||||
};
|
};
|
||||||
} else if (pixel.age > (debugSpeedGrowth ? 500 : 1000)) {
|
} else if (pixel.age > (debugSpeedGrowth ? 500 : 1000)) {
|
||||||
changePixel(pixel,"banana_plant_top");
|
changePixel(pixel,"banana_plant_top");
|
||||||
|
|
@ -61,7 +70,9 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
doDefaults(pixel);
|
doDefaults(pixel);
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
"age":0
|
"age": 0,
|
||||||
|
//"bananaRange": null, //apparently this is suddenly, in an illogical, never-before-seen, completely new, unprecedented incident of bad behavior, evaluated before being put into the property database, so RNG has to be done in tick
|
||||||
|
"bananaRange": null,
|
||||||
},
|
},
|
||||||
tempHigh: 100,
|
tempHigh: 100,
|
||||||
stateHigh: "dead_plant",
|
stateHigh: "dead_plant",
|
||||||
|
|
@ -80,6 +91,10 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
color: "#d5e39f",
|
color: "#d5e39f",
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
|
if(pixel.bananaRange === null) {
|
||||||
|
pixel.bananaRange = randomNumberFromOneToThree();
|
||||||
|
};
|
||||||
|
|
||||||
if (pixel.age > 60 && pixel.temp < 100 && !pixel.grewPeduncle) {
|
if (pixel.age > 60 && pixel.temp < 100 && !pixel.grewPeduncle) {
|
||||||
var peduncleOffsets = [-1, 1]; //placed to the left, placed to the right
|
var peduncleOffsets = [-1, 1]; //placed to the left, placed to the right
|
||||||
for(i = 0; i < peduncleOffsets.length; i++) {
|
for(i = 0; i < peduncleOffsets.length; i++) {
|
||||||
|
|
@ -87,7 +102,8 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
if (Math.random() < 0.005) {
|
if (Math.random() < 0.005) {
|
||||||
createPixel("banana_peduncle_1",pixel.x+peduncleOffsets[i],pixel.y);
|
createPixel("banana_peduncle_1",pixel.x+peduncleOffsets[i],pixel.y);
|
||||||
pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].dir = Math.sign(peduncleOffsets[i]);
|
pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].dir = Math.sign(peduncleOffsets[i]);
|
||||||
pixel.grewPeduncle = true;
|
pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].bananaRange = pixel.bananaRange; //pass banana range down to peduncle
|
||||||
|
if(Math.random() < 0.8) { pixel.grewPeduncle = true; } //20% chance to not mark as true, allowing for a chance to try another peduncle
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -98,6 +114,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
properties: {
|
properties: {
|
||||||
"age": 0,
|
"age": 0,
|
||||||
"grewPeduncle": false,
|
"grewPeduncle": false,
|
||||||
|
"bananaRange": null,
|
||||||
},
|
},
|
||||||
tempHigh: 100,
|
tempHigh: 100,
|
||||||
stateHigh: "dead_plant",
|
stateHigh: "dead_plant",
|
||||||
|
|
@ -181,6 +198,10 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
name: "banana peduncle (offshoot)",
|
name: "banana peduncle (offshoot)",
|
||||||
color: "#acb55b",
|
color: "#acb55b",
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
|
if(pixel.bananaRange === null) {
|
||||||
|
pixel.bananaRange = randomNumberFromOneToThree();
|
||||||
|
};
|
||||||
|
|
||||||
if (pixel.age > 20 && pixel.temp < 100) {
|
if (pixel.age > 20 && pixel.temp < 100) {
|
||||||
var peduncleCoords1 = [pixel.x + pixel.dir, pixel.y];
|
var peduncleCoords1 = [pixel.x + pixel.dir, pixel.y];
|
||||||
var peduncleCoords2 = [pixel.x + pixel.dir, pixel.y + 1];
|
var peduncleCoords2 = [pixel.x + pixel.dir, pixel.y + 1];
|
||||||
|
|
@ -188,8 +209,10 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
if(Math.random() < 0.5) {
|
if(Math.random() < 0.5) {
|
||||||
createPixel(pixel.element,peduncleCoords1[0],peduncleCoords1[1]);
|
createPixel(pixel.element,peduncleCoords1[0],peduncleCoords1[1]);
|
||||||
pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].dir = pixel.dir;
|
pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].dir = pixel.dir;
|
||||||
|
pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].bananaRange = pixel.bananaRange; //pass banana range down to next pixel of peduncle horizontal
|
||||||
} else {
|
} else {
|
||||||
createPixel("banana_peduncle_2",peduncleCoords2[0],peduncleCoords2[1]);
|
createPixel("banana_peduncle_2",peduncleCoords2[0],peduncleCoords2[1]);
|
||||||
|
pixelMap[peduncleCoords2[0]][peduncleCoords2[1]].bananaRange = pixel.bananaRange; //pass banana range down to diagonal offshoot
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -199,6 +222,8 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
properties: {
|
properties: {
|
||||||
"dir": (!Math.floor(Math.random() * 2)) ? 1 : -1,
|
"dir": (!Math.floor(Math.random() * 2)) ? 1 : -1,
|
||||||
"age": 0,
|
"age": 0,
|
||||||
|
//"bananaRange": (1 + (Math.floor(Math.random() * 3))), //1-3
|
||||||
|
"bananaRange": null,
|
||||||
},
|
},
|
||||||
tempHigh: 100,
|
tempHigh: 100,
|
||||||
stateHigh: "dead_plant",
|
stateHigh: "dead_plant",
|
||||||
|
|
@ -217,12 +242,17 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
name: "banana peduncle (hanging)",
|
name: "banana peduncle (hanging)",
|
||||||
color: "#9bad51",
|
color: "#9bad51",
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
|
if(pixel.bananaRange === null) {
|
||||||
|
pixel.bananaRange = randomNumberFromOneToThree();
|
||||||
|
};
|
||||||
|
|
||||||
// Grow/Flower
|
// Grow/Flower
|
||||||
if (pixel.age > 20 && pixel.temp < 100) {
|
if (pixel.age > 20 && pixel.temp < 100) {
|
||||||
var growthCoords = [pixel.x, pixel.y + 1];
|
var growthCoords = [pixel.x, pixel.y + 1];
|
||||||
if(isEmpty(...growthCoords)) {
|
if(isEmpty(...growthCoords)) {
|
||||||
if(Math.random() < 0.9) {
|
if(Math.random() < 0.9) {
|
||||||
createPixel(pixel.element,...growthCoords);
|
createPixel(pixel.element,...growthCoords);
|
||||||
|
pixelMap[growthCoords[0]][growthCoords[1]].bananaRange = pixel.bananaRange; //pass banana range down to next pixel of peduncle vertical
|
||||||
} else {
|
} else {
|
||||||
createPixel("petal",...growthCoords); //the sexual dimorphism of the banana plant has zonked me
|
createPixel("petal",...growthCoords); //the sexual dimorphism of the banana plant has zonked me
|
||||||
};
|
};
|
||||||
|
|
@ -233,28 +263,39 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
if (pixel.age > 40 && pixel.temp < 100) {
|
if (pixel.age > 40 && pixel.temp < 100) {
|
||||||
var bananaOffsets = [-1, 1]; //placed to the left, placed to the right
|
var bananaOffsets = [-1, 1]; //placed to the left, placed to the right
|
||||||
for(i = 0; i < bananaOffsets.length; i++) {
|
for(i = 0; i < bananaOffsets.length; i++) {
|
||||||
if (isEmpty(pixel.x+bananaOffsets[i],pixel.y,false)) {
|
//console.log(`Looping through left and right positions: ${bananaOffsets}`);
|
||||||
if (Math.random() < 0.005) {
|
for(j = 1; j < pixel.bananaRange + 1; j++) { //for max banana distance, using the banana range
|
||||||
createPixel("banana",pixel.x+bananaOffsets[i],pixel.y);
|
//console.log(`Looping through banana offset multipliers: ${j}`);
|
||||||
pixelMap[pixel.x+bananaOffsets[i]][pixel.y].attached = true;
|
if (isEmpty(pixel.x+(j * bananaOffsets[i]),pixel.y,false)) { //if there's an empty space
|
||||||
pixelMap[pixel.x+bananaOffsets[i]][pixel.y].attachDirection = -1 * Math.sign(bananaOffsets[i]); //attach dir is the opposite of placement dir so it attaches towards the stem
|
//console.log(`Banana position is empty: [${j * bananaOffsets[i]}, 0]\nTrying banana at (${pixel.x+(j * bananaOffsets[i])},${pixel.y})`);
|
||||||
};
|
if (Math.random() < (debugSpeedGrowth ? 0.05 : 0.005)) { //try to place the banana
|
||||||
} else {
|
//console.log(`Placing banana`);
|
||||||
if (isEmpty(pixel.x+(2 * bananaOffsets[i]),pixel.y,false)) {
|
createPixel("banana",pixel.x+(j * bananaOffsets[i]),pixel.y);
|
||||||
if (Math.random() < 0.005) {
|
pixelMap[pixel.x+(j * bananaOffsets[i])][pixel.y].attached = true;
|
||||||
createPixel("banana",pixel.x+(2 * bananaOffsets[i]),pixel.y);
|
pixelMap[pixel.x+(j * bananaOffsets[i])][pixel.y].attachDirection = -1 * Math.sign(bananaOffsets[i]); //attach dir is the opposite of placement dir so it attaches towards the stem
|
||||||
pixelMap[pixel.x+(2 * bananaOffsets[i])][pixel.y].attached = true;
|
} else {
|
||||||
pixelMap[pixel.x+(2 * bananaOffsets[i])][pixel.y].attachDirection = -1 * Math.sign((2 * bananaOffsets[i])); //attach dir is the opposite of placement dir so it attaches towards the stem
|
//console.log(`NOT placing banana`);
|
||||||
};
|
};
|
||||||
|
//console.log(`Banana tried, stopping iteration`);
|
||||||
|
break; //and then stop iteration
|
||||||
|
} else {
|
||||||
|
//console.log(`Banana position is NOT empty: [${j * bananaOffsets[i]}, 0]\nSkipping this offset`);
|
||||||
|
continue; //if not empty, skip that pixel and move on the next distance
|
||||||
};
|
};
|
||||||
|
//console.log(`====End of side try====`);
|
||||||
};
|
};
|
||||||
|
//console.log(`####End of side iterator####`);
|
||||||
};
|
};
|
||||||
|
//console.log(`>>>>End of banana iterator<<<<`);
|
||||||
};
|
};
|
||||||
pixel.age++;
|
pixel.age++;
|
||||||
doDefaults(pixel);
|
doDefaults(pixel);
|
||||||
|
//console.log(`\nEnd of peduncle tick\n`);
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
"age": 0,
|
"age": 0,
|
||||||
|
//"bananaRange": (1 + (Math.floor(Math.random() * 3))), //1-3
|
||||||
|
"bananaRange": null,
|
||||||
},
|
},
|
||||||
tempHigh: 100,
|
tempHigh: 100,
|
||||||
stateHigh: "dead_plant",
|
stateHigh: "dead_plant",
|
||||||
|
|
@ -290,6 +331,10 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
color: "#9df24e",
|
color: "#9df24e",
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
|
if(pixel.bananaRange === null) {
|
||||||
|
pixel.bananaRange = randomNumberFromOneToThree();
|
||||||
|
};
|
||||||
|
|
||||||
if(pixel.attached) {
|
if(pixel.attached) {
|
||||||
var attachCoords = [pixel.x + pixel.attachOffset[0], pixel.y + pixel.attachOffset[1]];
|
var attachCoords = [pixel.x + pixel.attachOffset[0], pixel.y + pixel.attachOffset[1]];
|
||||||
if(isEmpty(attachCoords[0],attachCoords[1],false)) { //consider OOB full
|
if(isEmpty(attachCoords[0],attachCoords[1],false)) { //consider OOB full
|
||||||
|
|
@ -317,6 +362,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
properties: {
|
properties: {
|
||||||
"attached": false,
|
"attached": false,
|
||||||
"attachOffset": [(!Math.floor(Math.random() * 2)) ? 1 : -1, 0],
|
"attachOffset": [(!Math.floor(Math.random() * 2)) ? 1 : -1, 0],
|
||||||
|
"bananaRange": null,
|
||||||
},
|
},
|
||||||
burn: 5,
|
burn: 5,
|
||||||
burnInto: ["steam", "ash"],
|
burnInto: ["steam", "ash"],
|
||||||
|
|
@ -395,6 +441,10 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
color: "#d5e39f",
|
color: "#d5e39f",
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
|
if(pixel.bananaRange === null) {
|
||||||
|
pixel.bananaRange = randomNumberFromOneToThree();
|
||||||
|
};
|
||||||
|
|
||||||
if (pixel.age > 30 && pixel.temp < 100) {
|
if (pixel.age > 30 && pixel.temp < 100) {
|
||||||
if(!pixel.grewLeftLeaves) {
|
if(!pixel.grewLeftLeaves) {
|
||||||
for(i = (0 - pixel.leafRange); i < 0; i++) { //left half
|
for(i = (0 - pixel.leafRange); i < 0; i++) { //left half
|
||||||
|
|
@ -419,6 +469,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
createPixel("banana_leaf",leafX,leafY);
|
createPixel("banana_leaf",leafX,leafY);
|
||||||
pixelMap[leafX][leafY].attached = true; //set leaf's attached to true
|
pixelMap[leafX][leafY].attached = true; //set leaf's attached to true
|
||||||
pixelMap[leafX][leafY].attachOffset = leafAttachOffset; //array of 2 numbers
|
pixelMap[leafX][leafY].attachOffset = leafAttachOffset; //array of 2 numbers
|
||||||
|
pixelMap[leafX][leafY].bananaRange = pixel.bananaRange;
|
||||||
pixel.grewLeftLeaves = true; //difference 2: separate flag for left side
|
pixel.grewLeftLeaves = true; //difference 2: separate flag for left side
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|
@ -449,6 +500,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
createPixel("banana_leaf",leafX,leafY);
|
createPixel("banana_leaf",leafX,leafY);
|
||||||
pixelMap[leafX][leafY].attached = true; //set leaf's attached to true
|
pixelMap[leafX][leafY].attached = true; //set leaf's attached to true
|
||||||
pixelMap[leafX][leafY].attachOffset = leafAttachOffset; //array of 2 numbers
|
pixelMap[leafX][leafY].attachOffset = leafAttachOffset; //array of 2 numbers
|
||||||
|
pixelMap[leafX][leafY].bananaRange = pixel.bananaRange;
|
||||||
pixel.grewRightLeaves = true; //difference 2: separate flag for right side
|
pixel.grewRightLeaves = true; //difference 2: separate flag for right side
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|
@ -464,6 +516,7 @@ if(enabledMods.includes(onTryMoveIntoMod)) {
|
||||||
"leafRange": 2 + (Math.floor(Math.random() * 3)), //2-4
|
"leafRange": 2 + (Math.floor(Math.random() * 3)), //2-4
|
||||||
"grewLeftLeaves": false,
|
"grewLeftLeaves": false,
|
||||||
"grewRightLeaves": false,
|
"grewRightLeaves": false,
|
||||||
|
"bananaRange": null,
|
||||||
},
|
},
|
||||||
tempHigh: 100,
|
tempHigh: 100,
|
||||||
stateHigh: "dead_plant",
|
stateHigh: "dead_plant",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue