Skip to content

Commit

Permalink
change API - now you require()
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Mar 6, 2013
1 parent dbf74e4 commit 6eec566
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 49 deletions.
102 changes: 55 additions & 47 deletions index.js
Expand Up @@ -7,60 +7,68 @@ var texturePath = require('painterly-textures')(__dirname)
var toolbar = require('toolbar')
var blockSelector = toolbar({el: '#tools'})
var voxel = require('voxel')
var extend = require('extend')

// setup the game and add some trees
var game = createGame({
generate: voxel.generator['Valley'],
chunkDistance: 2,
materials: [
['grass', 'dirt', 'grass_dirt'],
'obsidian',
'brick',
'grass',
'plank'
],
texturePath: texturePath,
worldOrigin: [0, 0, 0],
controls: { discreteFire: true }
})
module.exports = function(opts) {
var defaults = {
generate: voxel.generator['Valley'],
chunkDistance: 2,
materials: [
['grass', 'dirt', 'grass_dirt'],
'obsidian',
'brick',
'grass',
'plank'
],
texturePath: texturePath,
worldOrigin: [0, 0, 0],
controls: { discreteFire: true }
}
opts = extend({}, defaults, opts || {})

// setup the game and add some trees
var game = createGame(opts)

window.game = game // for debugging
window.game = game // for debugging

var container = document.querySelector('#container')
var container = document.querySelector('#container')

game.appendTo(container)
game.appendTo(container)

// create the player from a minecraft skin file and tell the
// game to use it as the main player
var createPlayer = player(game)
var substack = createPlayer('substack.png')
substack.possess()
substack.yaw.position.set(2, 14, 4)
// create the player from a minecraft skin file and tell the
// game to use it as the main player
var createPlayer = player(game)
var substack = createPlayer('substack.png')
substack.possess()
substack.yaw.position.set(2, 14, 4)

// highlight blocks when you look at them
var highlighter = highlight(game)
// highlight blocks when you look at them
var highlighter = highlight(game)

// toggle between first and third person modes
window.addEventListener('keydown', function (ev) {
if (ev.keyCode === 'R'.charCodeAt(0)) substack.toggle()
})
// toggle between first and third person modes
window.addEventListener('keydown', function (ev) {
if (ev.keyCode === 'R'.charCodeAt(0)) substack.toggle()
})

// block interaction stuff
var currentMaterial = 1
// block interaction stuff
var currentMaterial = 1

blockSelector.on('select', function(material) {
material = +material // cast to int
if (material > -1) currentMaterial = material
else currentMaterial = 1
})
blockSelector.on('select', function(material) {
material = +material // cast to int
if (material > -1) currentMaterial = material
else currentMaterial = 1
})

game.on('fire', function(target, state) {
var point = game.raycast()
if (!point) return
var erase = !state.firealt && !state.alt
if (erase) {
game.setBlock(point.position, 0)
} else {
game.createBlock(point.adjacent, currentMaterial)
}
})
game.on('fire', function(target, state) {
var point = game.raycast()
if (!point) return
var erase = !state.firealt && !state.alt
if (erase) {
game.setBlock(point.position, 0)
} else {
game.createBlock(point.adjacent, currentMaterial)
}
})

return game
}
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -10,13 +10,14 @@
"voxel-highlight": "0.0.5",
"voxel-player": "0.1.0",
"painterly-textures": "0.0.3",
"toolbar": "0.0.5"
"toolbar": "0.0.5",
"extend": "1.1.3"
},
"devDependencies": {
"browserify": "1.17.3",
"browservefy": "0.0.8"
},
"scripts": {
"start": "echo \"open localhost:8080/\" && ./node_modules/browservefy/bin/browservefy index.js:bundle.js 8080 --browserify=./node_modules/browserify/bin/cmd.js -- -d"
"start": "echo \"open localhost:8080/\" && ./node_modules/browservefy/bin/browservefy test.js:bundle.js 8080 --browserify=./node_modules/browserify/bin/cmd.js -- -d"
}
}
1 change: 1 addition & 0 deletions test.js
@@ -0,0 +1 @@
require('./')()

0 comments on commit 6eec566

Please sign in to comment.