@nichathan-gaming/map-generator
Version:
Creates and generates a 2 dimensional array with various path generation functions.
24 lines (21 loc) • 827 B
JavaScript
import patternMap from "./patternMap.js";
/**
* Receives the 8 neighbors around a cell to determine the index of the sprite to display for Nichathan Gaming's mapRenderer.
*
* Neighbors are tracked by their value:
* 1 2 3
* 4 * 5
* 6 7 8
*
* count cardinal directions first then diagonals if they are not next to an unpathed value.
* @param {number[]} mismatchedNeighbors
* @param {number[]} matchingNeighbors
* @returns {[number, number]} The index of the sprite to display.
*/
const tileSelector = (mismatchedNeighbors, matchingNeighbors) => {
//get the key for the pattern
const patternKey = `${mismatchedNeighbors.sort().join('')},${matchingNeighbors.sort().join('')}`;
//return the value of the key
return patternMap[patternKey];
};
export default tileSelector;