Permalink
Browse files

number version of opts.yield

  • Loading branch information...
substack committed Jan 11, 2013
1 parent 2ba1f37 commit 1874fe013430876a0b2132e84bfb8639254a67cc
Showing with 11 additions and 2 deletions.
  1. +1 −0 example/gather.js
  2. +1 −0 example/simple.js
  3. +7 −1 index.js
  4. +2 −1 readme.markdown
View
@@ -11,6 +11,7 @@ var game = createEngine({
materials: [ 'dirt', 'grass', 'crate', 'brick' ]
});
game.appendTo('#container');
+game.controls.pitchObject.rotation.x = -1.5;
var explode = require('../')(game, {
yield: function (value) {
View
@@ -8,6 +8,7 @@ var game = createEngine({
materials: [ 'dirt', 'grass', 'crate', 'brick' ]
});
game.appendTo('#container');
+game.controls.pitchObject.rotation.x = -1.5;
var explode = require('../')(game, { power : 1.5 });
View
@@ -4,7 +4,13 @@ var EventEmitter = require('events').EventEmitter;
module.exports = function (game, opts) {
if (!opts) opts = {};
if (!opts.limit) opts.limit = function () { return false };
- if (!opts.yield) opts.yield = function () { return 4 };
+ if (opts.yield === undefined) opts.yield = 4;
+ if (typeof opts.yield !== 'function') {
+ opts.yield = (function (y) {
+ return function () { return y };
+ })(opts.yield);
+ }
+
if (!opts.expire) opts.expire = {};
if (typeof opts.expire === 'number') {
opts.expire = { start : opts.expire, end : opts.expire };
View
@@ -53,7 +53,8 @@ If `opts.limit(item)` is specified, when it returns true, `item` will not be
collected by the player when they pass within the collision radius.
If `opts.yield(value)` is specified, its return value will be how many debris
-items are created for the voxel data `value`.
+items are created for the voxel data `value`. `opts.yield` can be a function or
+just a number.
`opts.expire.start` and `opts.expire.end` control how long debris should persist
in the game world in milliseconds. A timeout will be chosen uniformly randomly

0 comments on commit 1874fe0

Please sign in to comment.