UNPKG

behavior

Version:

Class for modeling turn-based game behaviors

55 lines (45 loc) 1.09 kB
"use strict"; /* * Behavior.js: defines how objects act on their turn * * mit license * copyright (c) 2014 michael keating * */ var Options = require('options') , events = require('events') , util = require('util') /* global behavior constructor * hurr */ module.exports = function Behavior (instance, opts) { util.inherits(this, events.EventEmitter) this.instance = instance opts = new Options({ maxHP: 0 , initHP: 0 , isSolid: false , action: function () {} , active: function () {} }).merge(opts) console.log(opts) for (var option in opts) this[option] = opts[option] /* if (opts.action instanceof Array) for (var action in opts.action) this.on('action', opts.action[action] */ this.action = opts.action | function (instance) { return {x: instance.x, y: instance.y } } return this } /* basically a wall */ module.exports.fixed = function FixedBehavior (instance, opts) { opts = new Options({ isSolid: true , foo: false }).merge(opts) util.inherits(this, module.exports(instance, opts)) }