Git Product home page Git Product logo

voxel-debris's Introduction

voxel-debris

create and collect voxel debris from exploded voxels

example

View this example..

var createEngine = require('voxel-engine')
var game = createEngine({
    generate: function(x, y, z) {
        if (x*x + y*y + z*z > 20*20) return 0;
        return Math.floor(Math.random() * 4) + 1;
    },
    texturePath: './',
    materials: [ 'dirt', 'grass', 'crate', 'brick' ]
});
game.appendTo('#container');

var explode = require('voxel-debris')(game, { power : 1.5 });

explode.on('collect', function (item) {
    console.log(game.materials[item.value - 1]);
});

game.on('mousedown', function (pos) {
    if (erase) explode(pos)
    else game.createBlock(pos, 1)
});

window.addEventListener('keydown', ctrlToggle);
window.addEventListener('keyup', ctrlToggle);

var erase = true
function ctrlToggle (ev) { erase = !ev.ctrlKey }
game.requestPointerLock('canvas');

methods

var voxelDebris = require('voxel-debris')

var explode = voxelDebris(game, opts)

Create an explosion function from a voxel-engine instance and some options.

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. 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 between start and end. When opts.expire is a number, its value will be used for both start and end.

opts.power influcences the velocity of the debris. Default value: 1.

explode(pos)

Explode the block at the THREE.Vector3 position pos if the data at pos is non-zero.

events

explode.on('collect', function (item) {})

When a debris item passes within the collision radius, the 'collect' event fires with the item object before being removed from the scene.

install

With npm do:

npm install voxel-debris

Then use browserify to require('voxel-debris').

license

MIT

voxel-debris's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.