Update betaworldgen.js
This commit is contained in:
parent
1d1886558a
commit
f6c254252c
|
|
@ -1,128 +1,187 @@
|
||||||
//This mod was made by Alex the transfem, https://discord.com/users/778753696804765696 on discord and https://www.tiktok.com/@alextheagenenby?_t=8hoCVI3NRhu&_r=1 on tiktok.
|
//This mod was made by Alex the transfem, https://discord.com/users/778753696804765696 on discord and https://www.tiktok.com/@alextheagenenby?_t=8hoCVI3NRhu&_r=1 on tiktok.
|
||||||
function randomAlter(num, list){
|
let code = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 11, l: 12, m: 13, n: 14, o: 15, p: 16, q: 17, r: 18, s: 19, t: 20, u: 21, v: 22, w: 23, x: 24, y: 25, z: 26, A: 27, B: 28, C: 29, D: 30, E: 31, F: 32, G: 33, H: 34, I: 35, J: 36, K: 37, L: 38, M: 39, N: 40, O: 41, P: 42, Q: 43, R: 44, S: 45, T: 46, U: 47, V: 48, W: 49, X: 50, Y: 51, Z: 52 }
|
||||||
let r = Math.floor(Math.random() * list.length);
|
let invertedCode = {}
|
||||||
return (num + list[r]);
|
let flat = function(){
|
||||||
|
let str = "";
|
||||||
|
for(var i = 0; i < width; i++){
|
||||||
|
str += "a";
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
let biomes = {
|
||||||
|
plains: {
|
||||||
|
layers: 2,
|
||||||
|
thicknesses: [15, 10],
|
||||||
|
specificSeeds: "flat",
|
||||||
|
heights: [1, 21],
|
||||||
|
layersObj: {
|
||||||
|
1: ["rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","iron","iron","iron","aluminum","aluminum","aluminum","aluminum","uranium","diamond","copper","copper","copper","copper","sodium","sodium","potassium","potassium","charcoal","charcoal","charcoal","charcoal","charcoal", "calcium"],
|
||||||
|
2: ["dirt", "dirt", "dirt", "dirt", "dirt", "dirt", "dirt", "dirt", "dirt","dirt", "dirt", "dirt","dirt", "dirt", "gravel", "gravel"]
|
||||||
|
},
|
||||||
|
ssHeight: 39,
|
||||||
|
ssElems: ["grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","sapling","pinecone","seeds","seeds"]
|
||||||
|
},
|
||||||
|
desert: {
|
||||||
|
layers: 1,
|
||||||
|
thicknesses: [20],
|
||||||
|
specificSeeds: "flat",
|
||||||
|
heights: [1],
|
||||||
|
layersObj: {
|
||||||
|
1: ["sand"]
|
||||||
|
},
|
||||||
|
ssHeight: 40,
|
||||||
|
ssElems: [undefined,undefined,undefined,undefined,undefined,undefined,"cactus"]
|
||||||
|
},
|
||||||
|
forest: {
|
||||||
|
layers: 2,
|
||||||
|
specificSeeds: "flat",
|
||||||
|
heights: [1, 16],
|
||||||
|
thicknesses: [15, 10],
|
||||||
|
ssHeight: 29,
|
||||||
|
layersObj: {
|
||||||
|
1: ["rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","charcoal","charcoal","charcoal","charcoal","charcoal","iron","iron","iron","aluminum","aluminum","aluminum","calcium","calcium","sodium","potassium","diamond"],
|
||||||
|
2: ["dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","dirt","gravel"]
|
||||||
|
},
|
||||||
|
ssElems: ["grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","grass_seed","sapling", "pinecone"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var item in code){
|
||||||
|
invertedCode[code[item]] = item;
|
||||||
|
}
|
||||||
|
let ranNum = function(max, last) {
|
||||||
|
// Calculate a bias factor
|
||||||
|
let bias = Math.random() * 0.07 + 0.5; // Adjust this range to control the bias strength
|
||||||
|
|
||||||
|
// Generate a biased random number towards the 'last' value
|
||||||
|
let num = Math.round(bias * last + (1 - bias) * Math.random() * max) + 1;
|
||||||
|
|
||||||
|
// Randomly assign a negative or positive sign
|
||||||
|
return (Math.random() > 0.5) ? num : -num;
|
||||||
|
}
|
||||||
|
function decode(str){
|
||||||
|
let result = [];
|
||||||
|
str.split("");
|
||||||
|
for(var i = 0; i < str.length; i++){
|
||||||
|
if(code[str[i]]){
|
||||||
|
if(str[i - 1] == "*"){
|
||||||
|
result[i] = code[str[i]] * 2;
|
||||||
|
} else {
|
||||||
|
result[i] = code[str[i]];
|
||||||
|
}
|
||||||
|
} else if(str[i] == ":"){
|
||||||
|
result[i] = ":";
|
||||||
|
} else {continue;}
|
||||||
|
}
|
||||||
|
return result.filter(element => element !== undefined);
|
||||||
|
}
|
||||||
|
function makeSeed(layers, thickness){
|
||||||
|
let result = "";
|
||||||
|
for(var i = 0; i < layers; i++){
|
||||||
|
let avgThickness = thickness[i];
|
||||||
|
let str = "";
|
||||||
|
let lastNum = 0;
|
||||||
|
for(var ii = 1; ii <= width-1; ii++){
|
||||||
|
let num = ranNum(4, lastNum);
|
||||||
|
let cThickness = avgThickness + num;
|
||||||
|
lastNum = num;
|
||||||
|
if(invertedCode[cThickness] != undefined){
|
||||||
|
str += invertedCode[cThickness];
|
||||||
|
} else {
|
||||||
|
let num = Math.round(cThickness / 2);
|
||||||
|
str += `*${invertedCode[num]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result += (i == (layers - 1)) ? str : `${str}:`;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function splitArrayByCharacter(arr, char) {
|
||||||
|
let result = [];
|
||||||
|
let subArray = [];
|
||||||
|
|
||||||
|
arr.forEach(element => {
|
||||||
|
if (element === char) {
|
||||||
|
result.push(subArray);
|
||||||
|
subArray = [];
|
||||||
|
} else {
|
||||||
|
subArray.push(element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Push the last subarray if it's not empty
|
||||||
|
if (subArray.length > 0) {
|
||||||
|
result.push(subArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
let avgheight = 0;
|
|
||||||
let seed = "";
|
let seed = "";
|
||||||
function getSeed(type = "plains", thickness = 15){
|
function generate(type, seed1 = undefined){
|
||||||
seed = "";
|
if(seed1){
|
||||||
console.log(thickness)
|
seed = seed1;
|
||||||
if(thickness == 15){
|
|
||||||
avgheight = Math.floor(Math.random() * (18 - 12 + 1)) + 12;
|
|
||||||
} else{
|
} else{
|
||||||
avgheight = thickness;
|
seed = makeSeed(biomes[type].layers, biomes[type].thicknesses);
|
||||||
}
|
}
|
||||||
console.log(avgheight)
|
let semifinalArr = decode(seed);
|
||||||
|
let finalArr = splitArrayByCharacter(semifinalArr, ":");
|
||||||
if(type == "plains"){
|
for(var i = 0; i < finalArr.length; i++){
|
||||||
let location = Math.floor(Math.random(0, pixelMap.length) * 100);
|
let lHeight = biomes[type].heights[i];
|
||||||
let i = 0;
|
for(var ii = 1; ii < width-1; ii++){
|
||||||
while (i < pixelMap.length){
|
for(var iii = (height - 1) - lHeight; iii > height - lHeight - finalArr[i][ii]; iii--){
|
||||||
if (i !== location){
|
let x = ii;
|
||||||
seed += `${randomAlter(avgheight, [0, 1, 1, 2, 0, 0])}|`;
|
let y = iii;
|
||||||
i += 1;
|
let Num = Math.round(Math.random() * biomes[type].layersObj[i+1].length);
|
||||||
} else if (i == location){
|
if(Num == biomes[type].layersObj[i+1].length){Num-=1;}
|
||||||
let height = `${Math.floor(Math.random(40, pixelMap[i].length) * 10)}`;
|
let element = biomes[type].layersObj[i+1][Num];
|
||||||
let prevH = randomAlter(avgheight, [1, 1, 1, 2, 0, 0]);
|
if(isEmpty(x, y) && !outOfBounds(x, y)){
|
||||||
while (height > prevH){
|
createPixel(element, x, y);
|
||||||
prevH = randomAlter(prevH, [0, 1, 1, 2, 0, 0, 0, 1]);
|
} else {console.log("could not place. " + x + ", " + y); continue;}
|
||||||
seed += `${prevH}|`;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
i += 1;
|
if(biomes[type].specificSeeds){
|
||||||
|
if(biomes[type].specificSeeds == "flat"){
|
||||||
|
for(var i = 1; i < width-1; i++){
|
||||||
|
let y = height - biomes[type].ssHeight;
|
||||||
|
let Num = Math.round(Math.random() * biomes[type].ssElems.length);
|
||||||
|
if(Num == biomes[type].ssElems.length){Num-=1;}
|
||||||
|
let element = biomes[type].ssElems[Num];
|
||||||
|
if(element == undefined){continue;}
|
||||||
|
if(isEmpty(i, y) && !outOfBounds(i, y)){
|
||||||
|
createPixel(element, i, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return seed;
|
|
||||||
}
|
}
|
||||||
if(type == "desert"){
|
}
|
||||||
let i = 0;
|
}
|
||||||
while (i < pixelMap.length){
|
elements.copy_seed = {
|
||||||
seed += `${randomAlter(avgheight, [0, 1, 1, 2, 0, 0])}|`;
|
category: "tools",
|
||||||
i += 1;
|
onSelect: function(pixel){
|
||||||
|
navigator.clipboard.writeText(seed).then(function() {
|
||||||
|
alert(`Seed succesfully copied to clipboard!`);
|
||||||
|
}).catch(function(error) {
|
||||||
|
alert("Unable to copy text.")
|
||||||
|
});
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
function spawnElements(seed, list, height2 = 1, condition = [1, 1, 0]){
|
|
||||||
console.log(list);
|
|
||||||
let width = pixelMap.length - 1;
|
|
||||||
let element;
|
|
||||||
let height = pixelMap[1].length - 1;
|
|
||||||
console.log(seed);
|
|
||||||
let seedArray = seed.split("|");
|
|
||||||
console.log(seedArray);
|
|
||||||
seedArray.splice(seedArray.indexOf(""), 1);
|
|
||||||
seedArray.splice(pixelMap.length);
|
|
||||||
console.log(seedArray);
|
|
||||||
let i = 0;
|
|
||||||
while (i < seedArray.length - 1){
|
|
||||||
|
|
||||||
let ii = 0;
|
|
||||||
while (ii < seedArray[i]){
|
|
||||||
if((Math.floor(Math.random() * (condition[0] - condition[1] + 1))) == condition[2]){
|
|
||||||
if (height2 != 1){
|
|
||||||
element = list[Math.floor(Math.random() * list.length)];
|
|
||||||
createPixel(element, (width - 1) - i, (height - (height2 + 1)) - ii);
|
|
||||||
} else{
|
|
||||||
element = list[Math.floor(Math.random() * list.length)];
|
|
||||||
createPixel(element, (width - 1) - i, (height - 1) - ii);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ii += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elements.random_generation = {
|
||||||
function flat(){
|
category: "tools",
|
||||||
let iii = 0;
|
onSelect: function(pixel){
|
||||||
let flat = "";
|
autoResizeCanvas();
|
||||||
while (iii < pixelMap.length){
|
focusGame();
|
||||||
flat += "1|";
|
let type = prompt("Enter the biome you want to generate: \nOptions: plains, desert, forest");
|
||||||
iii += 1;
|
if(!biomes[type]) {type = "plains";}
|
||||||
}
|
generate(type);
|
||||||
return flat;
|
|
||||||
}
|
|
||||||
function processSeed(seed, type = "plains"){
|
|
||||||
|
|
||||||
console.log(flat());
|
|
||||||
let seedsArray = seed.split(":");
|
|
||||||
console.log(seedsArray);
|
|
||||||
if(type == "plains"){
|
|
||||||
spawnElements(seedsArray[0],["rock","rock","rock","rock","rock","rock","metal_scrap","metal_scrap","metal_scrap","gold_coin","uranium","uranium","diamond","rock","iron","iron","iron","aluminum","aluminum","aluminum","aluminum","copper","copper","copper","zinc","zinc","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock"].sort(() => Math.random() - 0.5));
|
|
||||||
setTimeout(function(){ spawnElements(seedsArray[1], ["dirt"], 24); }, 200);
|
|
||||||
setTimeout(function(){ spawnElements(flat(),["grass","grass","grass","sapling","flower_seed","grass","grass","pinecone","grass","grass","grass","grass","grass","grass","grass","grass","grass","grass"], 40); }, 300);
|
|
||||||
} else if(type == "desert"){
|
|
||||||
spawnElements(seed, ["sand"]);
|
|
||||||
setTimeout(function(){ spawnElements(flat(), ["cactus"], 40, [6, 0, 3]); }, 100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elements.worldGen = {
|
elements.seed_generation = {
|
||||||
color: "#FFFFFF",
|
category: "tools",
|
||||||
behavior: elements.erase.behavior,
|
onSelect: function(pixel){
|
||||||
temp: 2,
|
autoResizeCanvas();
|
||||||
category: "tools",
|
focusGame();
|
||||||
insulate:true,
|
let type = prompt("Enter the biome you want to generate: \nOptions: plains, desert, forest");
|
||||||
canPlace: false,
|
let seed1 = prompt("Enter the seed: ");
|
||||||
desc: "Generate worlds with random seeds or your own seeds.",
|
generate(type, seed1);
|
||||||
onSelect: function() {
|
|
||||||
let Seed = prompt("Enter desert or plains random generation! automatically set to plains.");
|
|
||||||
let regex = /[a-z]/;
|
|
||||||
if (regex.test(Seed)){
|
|
||||||
if(Seed.toLowerCase() == "desert"){
|
|
||||||
processSeed(getSeed("desert", 30), "desert");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Seed == ""){
|
|
||||||
seed = `${getSeed("plains", 20)}:${getSeed("plains", 8)}`
|
|
||||||
processSeed(seed);
|
|
||||||
} else{
|
|
||||||
processSeed(Seed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue