@nichathan-gaming/map-generator
Version:
Creates and generates a 2 dimensional array with various path generation functions.
40 lines (30 loc) • 1.91 kB
JavaScript
import mapGenerator from "./mapGenerator/mapGenerator.js";
import random from "./mapGenerator/helpers/random.js";
export default mapGenerator;
export {random};
//EXAMPLE
// //define base values
// const equalityFunction = (a, b)=>a===b;
// const startingIndex = [0, 0];
// //randomly places unwalkable paths around the map
// new mapGenerator(10, 10, 0, 1, equalityFunction).generateRandomly(0.75).logMap();
// new mapGenerator(10, 10, 0, 1, equalityFunction).generateRandomly(0.5).logMap();
// new mapGenerator(10, 10, 0, 1, equalityFunction).generateRandomly(0.25).logMap();
// //randomly crawls across the map horizontally and vertically
// new mapGenerator(10, 10, 0, 1, equalityFunction).generateCrawler(5, 3).logMap();
// //recursively traverses the map creating a path
// new mapGenerator(10, 10, 0, 1, equalityFunction).generateRecursively(startingIndex, 1, true).logMap();
// //traverses the map by creating new paths until they connect to the main path or are impossible to connect following Wilson's algorithm
// new mapGenerator(10, 10, 0, 1, equalityFunction).generateWilsons(startingIndex, 1, 2, true).logMap();
//traverses the map by creating a minimum spanning tree following Prim's algorithm
// const primsMap = new mapGenerator(10, 10, 0, 1, equalityFunction).generatePrims(startingIndex, 1, true).logMap();
// primsMap.multiplyMap(2).logMap()
// primsMap.addBorder(1, 1).logMap()
// primsMap.findDisplayIndex([0, 2], 0, false)
// primsMap.changeGeneratedType(generatedTypes.crawl).logMap();
// //get and shuffle the walkable indexes
// const walkablePath = mapGenerator.shuffleArray(map.getWalkableIndexes());
// //test the pathfinding
// console.log(`starting index for path: [${walkablePath[0]}], ending index for path: [${walkablePath[1]}]`);
// const foundPath = map.getPath(walkablePath[0], walkablePath[1]);
// console.log(foundPath);