Permalink
Browse files

pasting and editing life patterns now working

  • Loading branch information...
1 parent c927880 commit 5d94f63ce4eca95cc1ec0b105d378510be64b586 @theoxylo committed Mar 30, 2013
Showing with 36 additions and 18 deletions.
  1. +20 −1 README.md
  2. +1 −0 fixPerms.sh
  3. +6 −9 index.js
  4. +9 −8 life-engine.js
View
21 README.md 100644 → 100755
@@ -9,6 +9,25 @@ The latest stable version of the game is available online:
http://theoxylo.github.com/voxel-life
+## how to play
+Game play is still very rough and evolving quickly, but here are some things to try.
+
+#### Shapes you create in the ground with obsidian will become active life patterns:
+1. pause the life simulation: press the P key
+2. remove some grass cubes: look at the cube and left-click
+3. add obsidian cubes: press H to toggle build mode, then left-click
+4. unpause the simulation and your new creation will come to life
+
+#### You can copy interesting formations and paste them again:
+1. pause the life simulation: press the P key
+2. change to select mode: press the I key
+3. move and look around until you get the desired selection (press H to select empty cubes)
+4. copy the selection into memory: press the X key
+5. cancel select mode: press the I key again
+5. you can rotate the selection before pasting: press the T key
+6. paste the selection: press the E key
+7. unpause the simulation and your new creations will come to life
+
## controls
These are not yet configurable via the UI (coming soon)
```
@@ -22,10 +41,10 @@ keybindings: {
, 'I': 'select' // toggle multi-voxel selection box
, 'X': 'select_copy' // copy current multi-voxel selection
, 'E': 'select_paste' // paste current multi-voxel selection
+ , 'T': 'select_rotate' // rotates currently copied selection (in memory)
, 'Y': 'select_export' // export selection copy in [voxel interchange format](https://github.com/maxogden/voxel-engine#voxel-interchange-format)
, 'O': 'randomize' // reset GoL state
, 'P': 'pause' // pause GoL updates
- , 'U': 'life_update' // apply voxel edits back to life engine
, '<mouse 1>': 'fire' // left mouse click, remove or place block
, '<mouse 2>': 'firealt'
, '<space>' : 'jump'
View
1 fixPerms.sh 100644 → 100755
@@ -4,4 +4,5 @@ chown -R toneill *
chgrp -R root *
find . -type f | sed /\ /d | xargs chmod 644
+find . -type f -name "*.sh" | sed /\ /d | xargs chmod 755
find . -type d | sed /\ /d | xargs chmod 755
View
15 index.js 100644 → 100755
@@ -50,8 +50,8 @@ var game = createGame( {
, 'X': 'select_copy'
, 'E': 'select_paste'
, 'Y': 'select_export'
+ , 'T': 'select_rotate'
, 'O': 'life_randomize'
- , 'U': 'life_update'
, 'P': 'life_pause'
, '<mouse 1>': 'fire'
, '<mouse 2>': 'firealt'
@@ -115,6 +115,7 @@ var selection
var triggerCopy = createNonRepeater('select_copy')
var triggerPaste = createNonRepeater('select_paste')
var triggerExport = createNonRepeater('select_export')
+var triggerRotate = createNonRepeater('select_rotate')
// GoL support, life engine wrapper
var life = require('./life-engine')(game, { tickTime: 300 } )
@@ -123,7 +124,6 @@ life.resume()
var triggerLifeRandomize = createNonRepeater('life_randomize', life.randomize)
var triggerLifePause = createNonRepeater('life_pause', life.togglePause)
-var triggerLifeUpdate = createNonRepeater('life_update', life.readVoxels)
// main update function, called at about 60 hz
game.on('tick', function onUpdate(dt) {
@@ -134,7 +134,9 @@ game.on('tick', function onUpdate(dt) {
clipboard.paste(highlighter.currVoxelAdj || highlighter.currVoxelPos, selection);
}
- if (triggerExport()) {
+ if (triggerRotate()) clipboard.rotateAboutY()
+
+ if (triggerExport() && selection) {
var exportedData = JSON.stringify(clipboard.exportData())
console.log(exportedData)
alert("Selection data: " + exportedData)
@@ -145,19 +147,14 @@ game.on('tick', function onUpdate(dt) {
// game of life triggers
triggerLifeRandomize()
triggerLifePause()
- triggerLifeUpdate()
life.tick(dt) // iterate life engine
})
-game.on('updateLife', function () {
- console.log("Applying voxel state to life engine")
- life.readVoxels()
-})
-
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")
View
17 life-engine.js 100644 → 100755
@@ -10,14 +10,17 @@ module.exports = function createInstance(game, opts) {
var instance = new Life(boardSize)
function pause() {
+ if (paused) return
paused = true
}
function togglePause() {
- paused = !paused
+ paused ? resume() : pause()
}
function resume() {
+ if (!paused) return
+ readVoxels()
paused = false
}
@@ -33,11 +36,11 @@ module.exports = function createInstance(game, opts) {
}
function readVoxels() {
- pause()
for (var i = 0; i < boardSize; i++) {
for (var j = 0; j < boardSize; j++) {
- pos = [boardPos[0] + i, boardPos[1], boardPos[2] + j]
- instance.setCell(i, j, game.getBlock(pos))
+ var pos = [boardPos[0] + i, boardPos[1], boardPos[2] + j]
+ // voxel material 2 (obsidian) is active life cell
+ instance.setCell(i, j, game.getBlock(pos) === 2 ? 1 : 0)
}
}
paint()
@@ -54,11 +57,10 @@ module.exports = function createInstance(game, opts) {
}
function paint() {
- var pos
for (var i = 0; i < boardSize; i++) {
for (var j = 0; j < boardSize; j++) {
- pos = [boardPos[0] + i, boardPos[1], boardPos[2] + j]
- game.setBlock(pos, instance.getCell(i, j) ? 2 : 1)
+ var pos = [boardPos[0] + i, boardPos[1], boardPos[2] + j]
+ game.setBlock(pos, instance.getCell(i, j) ? 2 : 1)
}
}
}
@@ -69,7 +71,6 @@ module.exports = function createInstance(game, opts) {
togglePause: togglePause,
resume: resume,
randomize: randomize,
- readVoxels: readVoxels,
tick: tick,
paint: paint
}

0 comments on commit 5d94f63

Please sign in to comment.