Skip to content

Instantly share code, notes, and snippets.

@techwraith
Created February 8, 2013 02:55
Show Gist options
  • Save techwraith/4736260 to your computer and use it in GitHub Desktop.
Save techwraith/4736260 to your computer and use it in GitHub Desktop.
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y,z ) {
// return the number of the material you want to show up
// at the current x, y, z position.
// the numbers refer to the games materials array.
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
// 3 is dirt
return 3
}
var game = createGame({
// use the sphereWorld function to make the worlds voxels
generate: sphereWorld,
// make the player start y (up) position 1000
startingPosition: [0, 1000, 0],
materials: [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt', 'obsidian', 'bedrock']
})
// rotate camera to look straight down
game.controls.pitchObject.rotation.x = -1.5
// add the game to the page and make it playable
var container = document.body
game.appendTo(container)
game.setupPointerLock(container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment