Created
February 8, 2013 22:32
-
-
Save snagy/4742488 to your computer and use it in GitHub Desktop.
voxel.js game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Voxel Tetris by @tatarize | |
// Click the board side to make the piece go that way. | |
// Click something on the board (eg, the falling piece) to make it turn. | |
// Turns are currently logged counter clockwise/counter-clockwise depending on the height you clicked at. | |
var createGame = require('voxel-engine') | |
var chunkSize = 32 | |
var chunkDistance = 3 | |
var game = createGame({ | |
texturePath: '/textures/', | |
materials: [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt', 'obsidian', 'whitewool', 'cobblestone'], | |
generate: function(x,y,z) { | |
return (y < -2 && Math.abs(x) < 100 && Math.abs(z) < 100) ? 1 : 0 | |
}, | |
controlOptions: { | |
jump: 0, | |
move: 0, | |
fall: 0 | |
}, | |
startingPosition:[125,250,400] | |
}) | |
var container = document.body | |
game.appendTo(container); | |
window.game = game; | |
var tetris = require('voxel-tetris')(game); | |
game.on('mousedown', function (pos) { | |
tetris.touch(pos); | |
}); | |
game.controls.on('command', function(cmd) { | |
switch(cmd) { | |
case 'moveForward': | |
tetris.command(0); | |
break; | |
case 'moveLeft': | |
tetris.command(3); | |
break; | |
case 'moveRight': | |
tetris.command(2); | |
break; | |
} | |
}); | |
game.on('tick', function() { | |
tetris.tick(); | |
}); | |
// obtain pointer lock | |
game.setupPointerLock(container) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment