0.0.1 • Published 11 years ago
world-tile v0.0.1
Tile
Simple module for creating Tiles with utility functions.
Example
var Tile = require('habitants-tile');
var person = {
name: 'eve',
id : 'akjldh',
items: []
};
var template = {
type: 'grass',
style: 'grass_faded',
visible: true,
blocking: false,
opacity: 0.01,
impedance: 0,
location: {x: 2, y: 2};
};
var tile = new Tile(template);
tile.addUnit(person);
tile.removeUnit(person);Methods
var Tile = require('habitants-tile');var tile = new Tile(opts)
Returns a new Tile object.
opts is an object to specify the tile's settings.
opts.locationrequired |objectwithxandycoordinate values.opts.typerequired |stringnon-visual tileType (e.g'grass')opts.visibleoptional |booleansets if the tile is visible.opts.stylerequired |stringused for choosing graphics (e.g'grass-top','grass-faded')opts.blockingoptional |booleansets if the tile is passable or notopts.impedanceoptional | (default: 0) |int (0 -> 1)sets how much the tile affects travel through it.opts.opacityoptional | (default: 0 ) |opacity (0 -> 1)sets how much the tile obscures vision.
tile.addUnit(unit)
Adds the unit.id to it's unit array.
tile.removeUnit(unit)
Removes the unit.id to it's unit array.
tile.copyWithUnits(visible)
visible optional | boolean (default: false)
Creates a copy of the Tile with unit array, and sets it's visiblility to visible argument.
tile.copyWithoutUnits()
visible optional | boolean (default: false)
Creates a copy of the Tile without unit array, and sets it's visiblility to visible argument.
tile.deepCopy()
Returns a complete deep copy of itself.
Installing
npm install habitants-tileTest
npm test0.0.1
11 years ago