npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

voxel-creature

v0.1.0

Published

create creatures for voxel.js

Downloads

2

Readme

voxel-creature

create creatures for voxel.js

example

var createGame = require('voxel-engine');
var voxel = require('voxel');
var game = createGame({
    generate: voxel.generator['Valley'],
    texturePath: '/textures/'
});
game.appendTo('#container');

var createPlayer = require('voxel-player')(game);
var substack = createPlayer('substack.png');
substack.possess();
window.substack = substack;

window.addEventListener('keydown', function (ev) {
    if (ev.keyCode === 'R'.charCodeAt(0)) {
        substack.toggle();
    }
});

var createCreature = require('../')(game);
var creature = createCreature((function () {
    var T = game.THREE;
    var body = new T.Object3D;
    
    var head = new T.Mesh(
        new T.CubeGeometry(10, 10, 10),
        new T.MeshLambertMaterial({
            color: 0x800830,
            ambient: 0x800830
        })
    );
    head.position.set(0, 5, 0);
    body.add(head);
    
    var eyes = [0,1].map(function () {
        var eye = new T.Mesh(
            new T.CubeGeometry(1, 1, 1),
            new T.MeshLambertMaterial({
                color: 0xffffff,
                ambient: 0xffffff
            })
        );
        body.add(eye);
        return eye;
    });
    eyes[0].position.set(2, 8, 5);
    eyes[1].position.set(-2, 8, 5);
    
    return body;
})());
window.creature = creature;
 
creature.position.y = 200;
creature.position.x = Math.random() * 300 - 150;
creature.position.z = Math.random() * 300 - 150;

creature.on('block', function () { creature.jump() });
creature.notice(substack, { radius: 500 });

creature.on('notice', function (player) {
    creature.lookAt(player);
    creature.move(0, 0, 0.5);
});

setInterval(function () {
    if (creature.noticed) return;
    creature.rotation.y += Math.random() * Math.PI / 2 - Math.PI / 4;
    creature.move(0, 0, 0.5 * Math.random());
}, 1000);

methods

var voxelCreature = require('voxel-creature')

var createCreature = voxelCreature(game)

Return a function createCreature for making creatures given a voxel-engine game instance.

var creature = createCreature(obj, opts={})

Create a creature with the three.js 3d object (use game.THREE) obj.

Control the bounding box size with a vector3 opts.dims and the force (like gravity) for the object to be subject to with opts.force.

The default opts.dims is [10,10,10]. The default opts.force is [0,-0.00009,0].

creature.jump(power=1)

Jump upward.

creature.move(x, y, z)

Move the creature [x,y,z] smoothly by altering its velocity.

creature.lookAt(target)

Turn toward the 3d object target. target should be a 3d vector itself or it should have a target.position.

creature.notice(target, opts)

Return an interval for detecting the presence of target. target should be a 3d vector itself or it should have a target.position.

The opts.radius controls how nearby target needs to be to trigger a 'notice' event. The default opts.radius is 500.

The opts.interval controls how often to check the distance to target. The default opts.interval is 1000.

events

creature.on('notice', function (target) {})

When target is within the radius configured by creature.notice(), the 'notice' event fires.

creature.on('block', function () {})

When a creature is constrained by a block in front of it, the 'block' event fires. A good thing to try when a creature is blocked is to jump.

attributes

creature.position

control the creature item position

creature.rotation

control the creature item rotation

install

With npm do:

npm install voxel-creature

license

MIT