0.0.1 • Published 9 years ago

world-tile v0.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
9 years ago

Tile

Build Status

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.location required | object with x and y coordinate values.
  • opts.type required | string non-visual tileType (e.g 'grass')
  • opts.visible optional | boolean sets if the tile is visible.
  • opts.style required | string used for choosing graphics (e.g 'grass-top', 'grass-faded')
  • opts.blocking optional | boolean sets if the tile is passable or not
  • opts.impedance optional | (default: 0) | int (0 -> 1) sets how much the tile affects travel through it.
  • opts.opacity optional | (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-tile

Test

npm test
0.0.1

9 years ago