habitants-map-generator
v0.0.1
Published
creates simple 2d array with tiletypes
Downloads
3
Readme
Example
var Tile = require('habitants-tile');
var tiles = {};
// These are your own creations
var mapTemplate = require('./mapdata/map.json');
var tileTemplates = require('./mapdata/tiletypes.json');
// Just loop over the 2D array and create tiles with locations, referenced by geokey! i.e '4:8', '32:89'
mapTemplate.forEach(function (row, yi) {
row.forEach(function (tileType, xi) {
var tileTemplate = tileTemplates[tileType];
tileTemplate.location = {
x: xi,
y: yi
};
var tile = new Tile(tileTemplate);
tiles[tile.toString()] = tile;
});
});
// Check some out!
console.log(tiles['1:1'], tiles['2:4'], tiles['5:7']);
{ blocking: false,
blocked: false,
type: 'grassland',
style: 'grass',
impedance: 1,
opacity: 0.02,
location: { x: 1, y: 1 },
units: [] }
{ blocking: false,
blocked: false,
type: 'grassland',
style: 'grass',
impedance: 1,
opacity: 0.02,
location: { x: 2, y: 4 },
units: [] }
{ blocking: false,
blocked: false,
type: 'grassland',
style: 'grass',
impedance: 1,
opacity: 0.02,
location: { x: 5, y: 7 },
units: [] }