Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
bundle.js |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//Settings | ||
var.TurnSpeed = 28 //Sensitivity used for right joystick | ||
var.InvSpeed = 36 //Sensitivity used for POVHat - supposed to make it move one square | ||
|
||
// default minecraft control mapping from Options menu | ||
// Left Stick | ||
Key.A = EnsureMapRange(Joystick1.x, 0,-1, 0,1) // left stick, left | ||
Key.D = EnsureMapRange(Joystick1.x, 0, 1, 0,1) // left stick, right | ||
Key.W = EnsureMapRange(Joystick1.y, 0,-1, 0,1) // left stick, up | ||
Key.S = EnsureMapRange(Joystick1.y, 0, 1, 0,1) // left stick, down | ||
//Key.W = EnsureMapRange(Joystick1.yaw, 0,-1, 0,1) // right stick, up | ||
//Key.S = EnsureMapRange(Joystick1.yaw, 0, 1, 0,1) // right stick, down | ||
|
||
Mouse.DirectInputY = Mouse.DirectInputY + var.TurnSpeed*deadzone(-Joystick1.yaw) // right stick, y | ||
//Mouse.DirectInputY = Mouse.DirectInputY + var.TurnSpeed*deadzone(Joystick1.y) // left stick, y | ||
|
||
Mouse.DirectInputX = Mouse.DirectInputX + var.TurnSpeed*deadzone(Joystick1.pitch) // right stick, x | ||
|
||
Key.H = Joystick1.Button5 // LB -- toggle adjacent voxel highlight | ||
Key.E = Joystick1.Button4 // Btn Y -- inventory | ||
//Key.Y = Joystick1.Button5 // LB -- exit | ||
Key.L = Joystick1.Button6 // RB -- look pitch | ||
|
||
Key.Escape = Joystick1.Button8 // Start button - pause | ||
Key.U = Joystick1.Button7 // Back button - look behind | ||
Key.K = Joystick1.Button9 // LS Click - auto level | ||
Key.F5 = Joystick1.Button10 // RS Click - 1st/3rd person view | ||
|
||
Key.Space = Joystick1.Button1 // Btn A to jump, ascend | ||
Key.I = Joystick1.Button3 // Btn X for reload | ||
|
||
// Custom mappings for new keys | ||
Key.X = Joystick1.Button2 // Btn B button, descend | ||
Key.LShift = Joystick1.Button2 // Btn B button, crouch | ||
|
||
// use right stick ('.yaw' for Y, '.pitch' for X!) for yaw and throttle | ||
//Key.G = EnsureMapRange(Joystick1.pitch, 0,-1, 0,1) // RS, L | ||
//Key.H = EnsureMapRange(Joystick1.pitch, 0, 1, 0,1) // RS, R | ||
//Key.Z = EnsureMapRange(Joystick1.yaw, 0,-1, 0,1) // RS, Up | ||
//Key.X = EnsureMapRange(Joystick1.yaw, 0, 1, 0,1) // RS, Down | ||
|
||
//Key.Y = Joystick1.Button4 // Btn Y -- exit | ||
//Key.U = Joystick1.Button4 // Btn Y -- look back | ||
//Key.G = Joystick1.Button5 // RB, rotate left | ||
//Key.H = Joystick1.Button6 // RB, rotate right | ||
|
||
//Mouse.WheelUp = Joystick1.Button9 // LS Click | ||
//Mouse.WheelDown = Joystick1.Button10 // RS Click | ||
//Mouse.WheelUp = Joystick1.Button5 // LB | ||
//Mouse.WheelDown = Joystick1.Button6 // RB | ||
|
||
|
||
// double map stick clicks for drone mode where you need buttons to rotate | ||
Key.G = Joystick1.Button9 // LS Click | ||
Key.H = Joystick1.Button10 // RS Click | ||
//Key.Y = Joystick1.Button7 // Back button - exit, needed for drone mode | ||
|
||
|
||
//Key.FakeLeftShift = Joystick1.Button2 //B to sneak, but doesn't work yet | ||
|
||
|
||
// to swap throttle and pitch sticks | ||
//Mouse.DirectInputY = Mouse.DirectInputY + var.TurnSpeed*deadzone(Joystick1.y) // right stick, y | ||
//Key.W = EnsureMapRange(Joystick1.yaw, 0,-1, 0,1) // left stick, up | ||
//Key.S = EnsureMapRange(Joystick1.yaw, 0, 1, 0,1) // left stick, down | ||
|
||
// for right stick rotate yaw in drone mode | ||
//Key.G = EnsureMapRange(Joystick1.pitch, 0,-1, 0,1) // left stick, left | ||
//Key.H = EnsureMapRange(Joystick1.pitch, 0, 1, 0,1) // left stick, right | ||
|
||
// left stick analog | ||
//Mouse.DirectInputX = Mouse.DirectInputX + var.TurnSpeed*deadzone(Joystick1.x) // left stick, x | ||
//Mouse.DirectInputY = Mouse.DirectInputY + var.TurnSpeed*deadzone(Joystick1.y) // left stick, y | ||
|
||
//Clicking | ||
Mouse.LeftButton = EnsureMapRange(Joystick1.z, 0,-1, 0,1) //RT | ||
Mouse.RightButton = EnsureMapRange(Joystick1.z, 0,1, 0,1) //LT | ||
|
||
//Inventory Navigation (POV Hat) | ||
//Mouse.DirectInputX = Mouse.DirectInputX + var.InvSpeed*Pressed(Joystick1.Pov1x)*Joystick1.Pov1x | ||
//Mouse.DirectInputY = Mouse.DirectInputY + var.InvSpeed*Pressed(Joystick1.Pov1y)*Joystick1.Pov1y | ||
|
||
// D-pad | ||
//Key.F11 = EnsureMapRange(Joystick1.Pov1y, 0,-1, 0,1) // D-pad, up | ||
//Key.Y = EnsureMapRange(Joystick1.Pov1y, 0,-1, 0,1) // D-pad, up | ||
Key.P = EnsureMapRange(Joystick1.Pov1y, 0,-1, 0,1) // D-pad, up | ||
//Key.F12 = EnsureMapRange(Joystick1.Pov1y, 0, 1, 0,1) // D-pad, down | ||
Key.C = EnsureMapRange(Joystick1.Pov1y, 0, 1, 0,1) // D-pad, down | ||
Mouse.WheelUp = EnsureMapRange(Joystick1.Pov1x, 0,-1, 0,1) // D-pad, left | ||
Mouse.WheelDown = EnsureMapRange(Joystick1.Pov1x, 0, 1, 0,1) // D-pad, right | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE HTML> | ||
<html lang="en"> | ||
<head> | ||
<title>Voxel Life</title> | ||
<meta charset="utf-8"> | ||
<style type="text/css"> | ||
body { | ||
font-family: Monospace; | ||
font-size: 12px; | ||
background-color: #f0f0f0; | ||
margin: 0px; | ||
overflow: hidden; | ||
} | ||
#container { | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
user-select: none; | ||
} | ||
#crosshair { | ||
position: fixed; | ||
top: 50%; | ||
left: 50%; | ||
margin: -16px 0 0 -16px; | ||
width: 32px; | ||
height: 32px; | ||
} | ||
|
||
#stats { bottom: 0px; right: 0px; } | ||
.bar-tab { right: 33% !important; left: 33% !important; } | ||
.logo {position: absolute; top: 5px; left: 5px; } | ||
.errorMessage { text-align: center; width: 200px; margin: 20px auto; } | ||
</style> | ||
</head> | ||
<body> | ||
<img class="logo" src="logo-white.png"> | ||
<div id="container"></div> | ||
<div id="crosshair"><img src="crosshair.png"/></div> | ||
<script type="text/javascript" src="bundle.js"></script> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
var voxel = require('voxel') | ||
var createGame = require('voxel-engine') | ||
var highlight = require('voxel-highlight') | ||
var createPlayer = require('voxel-player') | ||
var texturePath = require('painterly-textures')(__dirname) | ||
var Clipboard = require('./voxel-clipboard') | ||
|
||
function createToggler(keyControl) { | ||
var active, canToggle | ||
return function () { | ||
if (!game.controls.state[keyControl]) { | ||
canToggle = true // key released, reset | ||
} else if (canToggle) { | ||
canToggle = false | ||
active = !active | ||
} | ||
return active | ||
} | ||
} | ||
|
||
function createNonRepeater(keyControl) { | ||
var canActivate | ||
return function () { // will only return true once per long keypress | ||
if (!game.controls.state[keyControl]) { | ||
canActivate = true // key released, reset | ||
} else if (canActivate) { | ||
canActivate = false | ||
return true | ||
} | ||
return false | ||
} | ||
} | ||
|
||
console.log("creating game..."); | ||
var game = createGame( { | ||
generate: function (x, y, z) { | ||
return y % 16 ? 0 : Math.ceil(Math.random() * 2) | ||
}, | ||
keybindings: { | ||
'W': 'forward' | ||
, 'A': 'left' | ||
, 'S': 'backward' | ||
, 'D': 'right' | ||
, '<mouse 1>': 'fire' | ||
, '<mouse 2>': 'firealt' | ||
, '<space>': 'jump' | ||
, '<shift>': 'crouch' | ||
, '<control>': 'alt' | ||
, 'R': 'view' | ||
, 'H': 'adjacent' | ||
, 'I': 'select' | ||
, 'X': 'copy' | ||
, 'E': 'paste' | ||
}, | ||
chunkDistance: 2, | ||
materials: [ | ||
['grass', 'dirt', 'grass_dirt'], | ||
'obsidian', | ||
'brick', | ||
'grass', | ||
'plank' | ||
], | ||
texturePath: texturePath, | ||
worldOrigin: [0, 0, 0], | ||
controls: { discreteFire: true } | ||
}); | ||
|
||
window.game = game // for debugging | ||
game.appendTo(document.body) | ||
|
||
console.log("creating player...") | ||
// add the player | ||
var playerFn = createPlayer(game) | ||
var player = playerFn('player.png') | ||
player.possess() | ||
player.yaw.position.set(2, 14, 4) | ||
console.log("player created: " + player); | ||
|
||
// highlight blocks when you look at them, hold <Ctrl> for block placement | ||
var blockPosPlace, blockPosErase | ||
var highlighter = highlight(game, { | ||
color: 0xffff00 | ||
, distance: 100 | ||
, adjacentActive: createToggler('adjacent') | ||
, selectActive: createToggler('select') | ||
, animate: false | ||
}); | ||
highlighter.on('highlight', function (voxelPos) { blockPosErase = voxelPos }) | ||
highlighter.on('remove', function (voxelPos) { blockPosErase = null }) | ||
highlighter.on('highlight-adjacent', function (voxelPos) { blockPosPlace = voxelPos }) | ||
highlighter.on('remove-adjacent', function (voxelPos) { blockPosPlace = null }) | ||
|
||
// block interaction stuff, uses highlight data | ||
var currentMaterial = 1 | ||
|
||
game.on('fire', function (target, state) { | ||
var position = blockPosPlace | ||
if (position) { | ||
game.createBlock(position, currentMaterial) | ||
} | ||
else { | ||
position = blockPosErase | ||
if (position) game.setBlock(position, 0) | ||
} | ||
}) | ||
|
||
var selection | ||
|
||
var triggerCopy = createNonRepeater('copy') | ||
var triggerPaste = createNonRepeater('paste') | ||
var triggerView = createNonRepeater('view') | ||
|
||
var clipboard = new Clipboard(game) | ||
|
||
setTimeout(function onUpdate() { | ||
if (triggerCopy() && selection) { | ||
clipboard.copy(selection.start, selection.end); | ||
} | ||
else if (triggerPaste()) { | ||
clipboard.paste(highlighter.currVoxelAdj || highlighter.currVoxelPos, selection); | ||
} | ||
if (triggerView()) { | ||
player.toggle() // 1st vs 3rd person view | ||
} | ||
setTimeout(onUpdate, 100) // repeat | ||
}, 100) | ||
|
||
highlighter.on('highlight-select', function (s) { | ||
selection = s | ||
console.log(">>> [" + s.start + "][" + s.end + "] highlighted selection") | ||
}) | ||
highlighter.on('highlight-deselect', function (s) { | ||
selection = null | ||
console.log("<<< [" + s.start + "][" + s.end + "] selection un-highlighted") | ||
}) | ||
|
||
//highlighter.on('highlight', function (voxelPos) { | ||
// console.log("> [" + voxelPos + "] highlighted voxel") | ||
//}) | ||
//highlighter.on('remove', function (voxelPos) { | ||
// console.log("< [" + voxelPos + "] removed voxel highlight") | ||
//}) | ||
//highlighter.on('highlight-adjacent', function (voxelPos) { | ||
// console.log(">> [" + voxelPos + "] highlighted adjacent") | ||
//}) | ||
//highlighter.on('remove-adjacent', function (voxelPos) { | ||
// console.log("<< [" + voxelPos + "] removed adjacent highlight") | ||
//}) | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "voxel-life", | ||
"version": "0.0.1", | ||
"repository": { | ||
"type":"git", | ||
"url": "git@github.com:theoxylo/voxel-life.git" | ||
}, | ||
"dependencies": { | ||
"voxel": "0.3.1", | ||
"voxel-engine": "0.14.4", | ||
"voxel-highlight": "0.0.9", | ||
"voxel-player": "0.1.0", | ||
"painterly-textures": "0.0.3", | ||
"extend": "1.1.3" | ||
}, | ||
"devDependencies": { | ||
"browserify": "2.7.3", | ||
"browservefy": "0.0.10" | ||
}, | ||
"scripts": { | ||
"start": "browservefy index.js:bundle.js 8080 -- -d -v" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module.exports = Clipboard | ||
|
||
function Clipboard(game, opts) { | ||
if (!(this instanceof Clipboard)) return new Clipboard(game, opts); | ||
this.game = game || {} | ||
this.opts = opts || {} | ||
this.dims = [] | ||
this.data = [] | ||
} | ||
|
||
Clipboard.prototype.copy = function (start, end) { | ||
if (!start || !end) { | ||
console.log("copy failed: missing data") | ||
return; | ||
} | ||
console.log("Copying selection from " + start + " to " + end) | ||
|
||
var x_min = Math.min(start[0], end[0]) | ||
var y_min = Math.min(start[1], end[1]) | ||
var z_min = Math.min(start[2], end[2]) | ||
|
||
// dimensions | ||
this.dims[0] = Math.abs(start[0] - end[0]) + 1 | ||
this.dims[1] = Math.abs(start[1] - end[1]) + 1 | ||
this.dims[2] = Math.abs(start[2] - end[2]) + 1 | ||
|
||
var newSelectionData = [] | ||
var index = 0 | ||
|
||
for (var i = 0; i < this.dims[0]; i++) { | ||
for (var j = 0; j < this.dims[1]; j++) { | ||
for (var k = 0; k < this.dims[2]; k++) { | ||
// store voxel block material index, 0 for none | ||
newSelectionData[index++] = this.game.getBlock([x_min + i, y_min + j, z_min + k]) | ||
} | ||
} | ||
} | ||
this.data = newSelectionData | ||
} | ||
|
||
Clipboard.prototype.paste = function (pos, selection) { | ||
if (!this.data || (!pos && !selection)) { | ||
console.log("paste failed: missing required data") | ||
return; | ||
} | ||
if (!pos) { // derive placement position from selection volume | ||
var x_min = Math.min(selection.start[0], selection.end[0]) | ||
var y_min = Math.min(selection.start[1], selection.end[1]) | ||
var z_min = Math.min(selection.start[2], selection.end[2]) | ||
pos = [x_min, y_min, z_min] | ||
} | ||
console.log("Pasting copied selection at position " + pos + ", data: " + this.data) | ||
|
||
var index = 0 | ||
|
||
for (var i = 0; i < this.dims[0]; i++) { | ||
for (var j = 0; j < this.dims[1]; j++) { | ||
for (var k = 0; k < this.dims[2]; k++) { | ||
this.game.setBlock([pos[0]+ i, pos[1] + j, pos[2] + k], this.data[index++]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
Clipboard.prototype.rotateAboutY = function () { | ||
if (!this.data) return; | ||
|
||
console.log("rotateAboutY start data: " + this.data); | ||
|
||
var newSelectionData = [] | ||
var index = 0 | ||
|
||
for (var i = 0; i < this.dims[0]; i++) { | ||
for (var j = 0; j < this.dims[1]; j++) { | ||
for (var k = 0; k < this.dims[2]; k++) { | ||
newSelectionData = this.data[index++] // rearrange data somehow... | ||
} | ||
} | ||
} | ||
this.data = newSelectionData | ||
console.log("rotateAboutY ended data: " + this.data) | ||
} |