diff options
| author | Code WvS <code-wvs@quantentunnel.de> | 2015-01-25 16:30:56 +0100 |
|---|---|---|
| committer | Code WvS <code-wvs@quantentunnel.de> | 2015-01-25 16:30:56 +0100 |
| commit | 5e25b1303319269ee44821d2a9592a441aa86cee (patch) | |
| tree | 4cac497aec68491f7b65e6cc92bfa2782fa6d519 | |
| parent | 2ca378c50bf67b6af5e16ba72af81f4f84db308c (diff) | |
| download | snap-byow-5e25b1303319269ee44821d2a9592a441aa86cee.tar.gz snap-byow-5e25b1303319269ee44821d2a9592a441aa86cee.zip | |
first working version, WIP
| -rw-r--r-- | byow.js | 71 | ||||
| -rw-r--r-- | gui.js | 17 | ||||
| -rw-r--r-- | lang-de.js | 26 | ||||
| -rw-r--r-- | objects.js | 150 | ||||
| -rw-r--r-- | package.json | 19 | ||||
| -rw-r--r-- | player.png | bin | 0 -> 3998 bytes | |||
| -rwxr-xr-x | snap.html | 36 | ||||
| -rw-r--r-- | test.js | 1 | ||||
| -rw-r--r-- | textures/bedrock.png | bin | 0 -> 3085 bytes | |||
| -rw-r--r-- | textures/bluewool.png | bin | 0 -> 3448 bytes | |||
| -rw-r--r-- | textures/bluewoolicon.png | bin | 0 -> 1738 bytes | |||
| -rw-r--r-- | textures/brick.png | bin | 0 -> 3531 bytes | |||
| -rw-r--r-- | textures/brickicon.png | bin | 0 -> 2036 bytes | |||
| -rw-r--r-- | textures/cobblestone.png | bin | 0 -> 3551 bytes | |||
| -rw-r--r-- | textures/cobblestoneicon.png | bin | 0 -> 2141 bytes | |||
| -rw-r--r-- | textures/crate.gif | bin | 0 -> 67585 bytes | |||
| -rw-r--r-- | textures/crate.png | bin | 0 -> 119696 bytes | |||
| -rw-r--r-- | textures/diamond.png | bin | 0 -> 3265 bytes | |||
| -rw-r--r-- | textures/diamondicon.png | bin | 0 -> 1683 bytes | |||
| -rw-r--r-- | textures/dirt.png | bin | 0 -> 3524 bytes | |||
| -rw-r--r-- | textures/glowstone.png | bin | 0 -> 3200 bytes | |||
| -rw-r--r-- | textures/glowstoneicon.png | bin | 0 -> 1988 bytes | |||
| -rw-r--r-- | textures/grass.png | bin | 0 -> 3364 bytes | |||
| -rw-r--r-- | textures/grass_dirt.png | bin | 0 -> 3526 bytes | |||
| -rw-r--r-- | textures/netherrack.png | bin | 0 -> 3827 bytes | |||
| -rw-r--r-- | textures/netherrackicon.png | bin | 0 -> 2537 bytes | |||
| -rw-r--r-- | textures/obsidian.png | bin | 0 -> 3489 bytes | |||
| -rw-r--r-- | textures/obsidianicon.png | bin | 0 -> 1744 bytes | |||
| -rw-r--r-- | textures/plank.png | bin | 0 -> 3134 bytes | |||
| -rw-r--r-- | textures/plankicon.png | bin | 0 -> 1511 bytes | |||
| -rw-r--r-- | textures/redwool.png | bin | 0 -> 3428 bytes | |||
| -rw-r--r-- | textures/redwoolicon.png | bin | 0 -> 1798 bytes | |||
| -rw-r--r-- | textures/whitewool.png | bin | 0 -> 3441 bytes | |||
| -rw-r--r-- | textures/whitewoolicon.png | bin | 0 -> 1989 bytes |
34 files changed, 304 insertions, 16 deletions
@@ -0,0 +1,71 @@ +var createGame = require('voxel-engine'); +var highlight = require('voxel-highlight'); +var player = require('voxel-player'); +var voxel = require('voxel'); +var fly = require('voxel-fly'); +var walk = require('voxel-walk'); + +function generator(x, y, z) { + return y === 1 ? 1 : 0; +} + +module.exports = function(setup) { + setup = setup || defaultSetup; + var options = { + generate: generator,//voxel.generator['Valley'], + chunkDistance: 2 + }; + // setup the game and add some trees + var game = createGame(options); + window.game = game; + gameWorld = document.createElement('div'); + game.appendTo(gameWorld); + window.gameWorld = gameWorld; + if (game.notCapable()) return game; + var createPlayer = player(game); + + var activeplayer = createPlayer('player.png'); + window.gamePlayer = activeplayer; + activeplayer.possess(); + activeplayer.yaw.position.set(2, 14, 4); + + setup(game, activeplayer); + + return game; +}; + +function defaultSetup(game, avatar) { + var makeFly = fly(game); + var target = game.controls.target(); + game.flyer = makeFly(target); + + // highlight blocks when you look at them, hold <Ctrl> for block placement + var blockPosPlace, blockPosErase; + var hl = game.highlighter = highlight(game, { color: 0xff0000 }); + hl.on('highlight', function (voxelPos) { blockPosErase = voxelPos; }); + hl.on('remove', function (voxelPos) { blockPosErase = null; }); + hl.on('highlight-adjacent', function (voxelPos) { blockPosPlace = voxelPos; }); + hl.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); + } + }); + + game.on('tick', function() { + walk.render(target.playerSkin); + var vx = Math.abs(target.velocity.x); + var vz = Math.abs(target.velocity.z); + if (vx > 0.001 || vz > 0.001) walk.stopWalking(); + else walk.startWalking(); + }); +} @@ -212,7 +212,7 @@ IDE_Morph.prototype.init = function (isAutoFill) { this.globalVariables = new VariableFrame(); this.currentSprite = new SpriteMorph(this.globalVariables); this.sprites = new List([this.currentSprite]); - this.currentCategory = 'motion'; + this.currentCategory = 'player'; this.currentTab = 'scripts'; this.projectName = ''; this.projectNotes = ''; @@ -3370,6 +3370,21 @@ IDE_Morph.prototype.toggleAppMode = function (appMode) { } } this.setExtent(this.world().extent()); // resume trackChanges + + /* BYOW changes */ + if (this.isAppMode) { + document.body.appendChild(window.gameWorld); + document.getElementById('world').style.display = 'none'; + } else { + for (j = 0; j < document.body.children.length; j++) { + // TODO refactor + if (document.body.children[j] == window.gameWorld) { + document.body.removeChild(window.gameWorld); + break; + } + } + document.getElementById('world').style.display = null; + } }; IDE_Morph.prototype.toggleStageSize = function (isSmall) { @@ -615,6 +615,32 @@ SnapTranslator.dict.de = { 'replace item %idx of %l with %s': 'ersetze Element %idx in %l durch %s', + // BYOW player + 'Player': + 'Spieler', + 'move x %n y %n z %n': + 'bewege um x %n y %n z %n', + 'move to x %n y %n z %n': + 'bewege zu x %n y %n z %n', + 'position': + 'Position', + 'set point of view to %s': + 'setze Ansicht auf %s', + 'toggle view': + 'schalte Ansicht um', + 'set rotation to x %n y %n z %n': + 'setze Drehung auf x %n y %n z %n', + 'get rotation': + 'Drehung', + + // BYOW world + 'World': + 'Welt', + 'set block at x %n y %n z %n material %n': + 'setze Block bei x %n y %n z %n Material %n', + 'get block at x %n y %n z %n': + 'Material des Blocks bei x %n y %n z %n', + // other 'Make a block': 'Neuer Block', @@ -155,21 +155,20 @@ SpriteMorph.uber = PenMorph.prototype; SpriteMorph.prototype.categories = [ - 'motion', + 'player', 'control', - 'looks', + 'world', 'sensing', 'sound', 'operators', - 'pen', 'variables', 'lists', 'other' ]; SpriteMorph.prototype.blockColor = { - motion : new Color(74, 108, 212), - looks : new Color(143, 86, 227), + player: new Color(74, 108, 212), + world: new Color(143, 86, 227), sound : new Color(207, 74, 217), pen : new Color(0, 161, 120), control : new Color(230, 168, 34), @@ -177,7 +176,7 @@ SpriteMorph.prototype.blockColor = { operators : new Color(98, 194, 19), variables : new Color(243, 118, 29), lists : new Color(217, 77, 17), - other: new Color(150, 150, 150) + other: new Color(150, 150, 150), }; SpriteMorph.prototype.paletteColor = new Color(55, 55, 55); @@ -203,7 +202,7 @@ SpriteMorph.prototype.initBlocks = function () { SpriteMorph.prototype.blocks = { // Motion - forward: { + /*forward: { only: SpriteMorph, type: 'command', category: 'motion', @@ -441,7 +440,7 @@ SpriteMorph.prototype.initBlocks = function () { type: 'command', category: 'looks', spec: 'console log %mult%s' - }, + }, */ // Sound playSound: { @@ -1186,6 +1185,60 @@ SpriteMorph.prototype.initBlocks = function () { type: 'reporter', category: 'other', spec: 'code of %cmdRing' + }, + + /* Snap! - Build Your Own World blocks */ + playerMove: { + only: SpriteMorph, + type: 'command', + category: 'player', + spec: 'move x %n y %n z %n' + }, + playerMoveTo: { + only: SpriteMorph, + type: 'command', + category: 'player', + spec: 'move to x %n y %n z %n' + }, + getPlayerPosition: { + only: SpriteMorph, + type: 'reporter', + category: 'player', + spec: 'position' + }, + playerPOV: { + only: SpriteMorph, + type: 'command', + category: 'player', + spec: 'set point of view to %s' // TODO + }, + playerTogglePOV: { + only: SpriteMorph, + type: 'command', + category: 'player', + spec: 'toggle view' + }, + setPlayerRotation: { + only: SpriteMorph, + type: 'command', + category: 'player', + spec: 'set rotation to x %n y %n z %n' + }, + getPlayerRotation: { + only: SpriteMorph, + type: 'command', + category: 'player', + spec: 'get rotation' + }, + worldSetBlock: { + type: 'command', + category: 'world', + spec: 'set block at x %n y %n z %n material %n' + }, + worldGetBlock: { + type: 'reporter', + category: 'world', + spec: 'get block at x %n y %n z %n' } }; }; @@ -1626,7 +1679,7 @@ SpriteMorph.prototype.variableBlock = function (varName) { SpriteMorph.prototype.blockTemplates = function (category) { var blocks = [], myself = this, varNames, button, - cat = category || 'motion', txt; + cat = category || 'player', txt; function block(selector) { if (StageMorph.prototype.hiddenPrimitives[selector]) { @@ -2128,6 +2181,23 @@ SpriteMorph.prototype.blockTemplates = function (category) { button.selector = 'addCustomBlock'; button.showHelp = BlockMorph.prototype.showHelp; blocks.push(button); + } else if (cat == 'player') { + + blocks.push(block('playerMove')); + blocks.push(block('playerMoveTo')); + blocks.push(block('getPlayerPosition')); + blocks.push('='); + blocks.push(block('playerPOV')); + blocks.push(block('playerTogglePOV')); + blocks.push('='); + blocks.push(block('setPlayerRotation')); + blocks.push(block('getPlayerRotation')); + + } else if (cat == 'world') { + + blocks.push(block('worldSetBlock')); + blocks.push(block('worldGetBlock')); + } return blocks; }; @@ -4865,11 +4935,64 @@ StageMorph.prototype.removeAllClones = function () { this.cloneCount = 0; }; +StageMorph.prototype.playerMove = function (deltaX, deltaY, deltaZ) { + var player = window.gamePlayer; + player.move(deltaX, deltaY, deltaZ); +}; + +StageMorph.prototype.playerMoveTo = function (posX, posY, posZ) { + var player = window.gamePlayer; + player.moveTo(posX, posY, posZ); +}; + +StageMorph.prototype.getPlayerPosition = function () { + var game = window.game; + var vecPos = game.controls.target().avatar.position; + return [vecPos.x, vecPos.y, vecPos.z]; +}; + +StageMorph.prototype.playerPOV = function (mode) { // TODO + var player = window.gamePlayer; + if (mode == 'first' || mode == 'third') { + player.pov(mode); + } else { + throw new Error('Must be either "first" or "third"!'); + } +}; + +StageMorph.prototype.playerTogglePOV = function () { + var player = window.gamePlayer; + player.toggle(); +}; + +StageMorph.prototype.setPlayerRotation = function (posX, posY, posZ) { + var world = window.game; + world.controls.target().avatar.rotation.set(posX, posY, posZ); +}; + +StageMorph.prototype.getPlayerRotation = function () { + var world = window.game; + var vecRotation = world.controls.target().avatar.rotation; + return [vecRotation.x, vecRotation.y, vecRotation.z]; +}; + +StageMorph.prototype.worldSetBlock = function (posX, posY, posZ, material) { + var world = window.game; + var pos = [posX, posY, posZ]; + world.setBlock(pos, material); +}; + +StageMorph.prototype.worldGetBlock = function (posX, posY, posZ) { + var world = window.game; + var pos = [posX, posY, posZ]; + world.getBlock(pos); +}; + // StageMorph block templates StageMorph.prototype.blockTemplates = function (category) { var blocks = [], myself = this, varNames, button, - cat = category || 'motion', txt; + cat = category || 'player', txt; function block(selector) { if (myself.hiddenPrimitives[selector]) { @@ -5303,6 +5426,13 @@ StageMorph.prototype.blockTemplates = function (category) { 'Make a block' ); blocks.push(button); + } else if (cat == 'player') { + + } else if (cat == 'world') { + + blocks.push(block('worldSetBlock')); + blocks.push(block('worldGetBlock')); + } return blocks; }; diff --git a/package.json b/package.json new file mode 100644 index 0000000..141629a --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "snap-byow", + "version": "0.1.0", + "dependencies": { + "voxel": "0.4.0", + "voxel-engine": "0.20.1", + "voxel-highlight": "0.0.10", + "voxel-player": "0.1.0", + "voxel-fly": "0.1.2", + "voxel-walk": "0.0.5" + }, + "devDependencies": { + "browserify": "8.1.1", + "beefy": "2.1.2" + }, + "scripts": { + "start": "beefy test.js:bundle.js 8000" + } +} diff --git a/player.png b/player.png Binary files differnew file mode 100644 index 0000000..9cdc96d --- /dev/null +++ b/player.png @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> - <title>Snap! Build Your Own Blocks. Beta</title> + <title>Snap! Build Your Own World. Alpha</title> <link rel="shortcut icon" href="favicon.ico"> <script type="text/javascript" src="morphic.js"></script> <script type="text/javascript" src="widgets.js"></script> @@ -17,21 +17,47 @@ <script type="text/javascript" src="store.js"></script> <script type="text/javascript" src="locale.js"></script> <script type="text/javascript" src="cloud.js"></script> - <script type="text/javascript" src="sha512.js"></script> + <script type="text/javascript" src="sha512.js"></script> + + <script type="text/javascript"> var world; window.onload = function () { world = new WorldMorph(document.getElementById('world')); - world.worldCanvas.focus(); - new IDE_Morph().openIn(world); - setInterval(loop, 1); + world.worldCanvas.focus(); + var ide = new IDE_Morph().openIn(world); + setInterval(loop, 10); + + document.onkeydown = function (e) { // exit appMode if the user exits the voxel window + e = e || window.event; + if (e.keyCode == 27) { + if (world.children[0].isAppMode) { + world.children[0].toggleAppMode() + } + } + } }; function loop() { world.doOneCycle(); + // copy the rendered frame to stage + var stage = world.children[0].stage; + var gameCanvas = window.gameWorld.children[0]; + var context = stage.trailsCanvas.getContext('2d'); + + // Force view to stage size TODO + if (stage.isAppMode == false) { + game.view.resizeWindow(stage.trailsCanvas.width, stage.trailsCanvas.height); + } + + context.drawImage(gameCanvas, 0, 0, stage.trailsCanvas.width, stage.trailsCanvas.height); + stage.changed(); } </script> </head> <body style="margin: 0;"> + <script type="text/javascript" src="bundle.js"></script> <canvas id="world" tabindex="1" style="position: absolute;" /> </body> + <body> + </body> </html> @@ -0,0 +1 @@ +require('./')() diff --git a/textures/bedrock.png b/textures/bedrock.png Binary files differnew file mode 100644 index 0000000..845f4c0 --- /dev/null +++ b/textures/bedrock.png diff --git a/textures/bluewool.png b/textures/bluewool.png Binary files differnew file mode 100644 index 0000000..e5e0cbe --- /dev/null +++ b/textures/bluewool.png diff --git a/textures/bluewoolicon.png b/textures/bluewoolicon.png Binary files differnew file mode 100644 index 0000000..e7ba41e --- /dev/null +++ b/textures/bluewoolicon.png diff --git a/textures/brick.png b/textures/brick.png Binary files differnew file mode 100644 index 0000000..d9ecc5d --- /dev/null +++ b/textures/brick.png diff --git a/textures/brickicon.png b/textures/brickicon.png Binary files differnew file mode 100644 index 0000000..841c3d4 --- /dev/null +++ b/textures/brickicon.png diff --git a/textures/cobblestone.png b/textures/cobblestone.png Binary files differnew file mode 100644 index 0000000..38a714d --- /dev/null +++ b/textures/cobblestone.png diff --git a/textures/cobblestoneicon.png b/textures/cobblestoneicon.png Binary files differnew file mode 100644 index 0000000..0312fcc --- /dev/null +++ b/textures/cobblestoneicon.png diff --git a/textures/crate.gif b/textures/crate.gif Binary files differnew file mode 100644 index 0000000..d9b475d --- /dev/null +++ b/textures/crate.gif diff --git a/textures/crate.png b/textures/crate.png Binary files differnew file mode 100644 index 0000000..90967a3 --- /dev/null +++ b/textures/crate.png diff --git a/textures/diamond.png b/textures/diamond.png Binary files differnew file mode 100644 index 0000000..fdb0fd7 --- /dev/null +++ b/textures/diamond.png diff --git a/textures/diamondicon.png b/textures/diamondicon.png Binary files differnew file mode 100644 index 0000000..6e037fb --- /dev/null +++ b/textures/diamondicon.png diff --git a/textures/dirt.png b/textures/dirt.png Binary files differnew file mode 100644 index 0000000..b2c4dbd --- /dev/null +++ b/textures/dirt.png diff --git a/textures/glowstone.png b/textures/glowstone.png Binary files differnew file mode 100644 index 0000000..aac9594 --- /dev/null +++ b/textures/glowstone.png diff --git a/textures/glowstoneicon.png b/textures/glowstoneicon.png Binary files differnew file mode 100644 index 0000000..1301e79 --- /dev/null +++ b/textures/glowstoneicon.png diff --git a/textures/grass.png b/textures/grass.png Binary files differnew file mode 100644 index 0000000..9da63fa --- /dev/null +++ b/textures/grass.png diff --git a/textures/grass_dirt.png b/textures/grass_dirt.png Binary files differnew file mode 100644 index 0000000..06f9259 --- /dev/null +++ b/textures/grass_dirt.png diff --git a/textures/netherrack.png b/textures/netherrack.png Binary files differnew file mode 100644 index 0000000..977798d --- /dev/null +++ b/textures/netherrack.png diff --git a/textures/netherrackicon.png b/textures/netherrackicon.png Binary files differnew file mode 100644 index 0000000..a4501dc --- /dev/null +++ b/textures/netherrackicon.png diff --git a/textures/obsidian.png b/textures/obsidian.png Binary files differnew file mode 100644 index 0000000..f4dc8fa --- /dev/null +++ b/textures/obsidian.png diff --git a/textures/obsidianicon.png b/textures/obsidianicon.png Binary files differnew file mode 100644 index 0000000..26a782f --- /dev/null +++ b/textures/obsidianicon.png diff --git a/textures/plank.png b/textures/plank.png Binary files differnew file mode 100644 index 0000000..f1a0490 --- /dev/null +++ b/textures/plank.png diff --git a/textures/plankicon.png b/textures/plankicon.png Binary files differnew file mode 100644 index 0000000..852b1c1 --- /dev/null +++ b/textures/plankicon.png diff --git a/textures/redwool.png b/textures/redwool.png Binary files differnew file mode 100644 index 0000000..caddd4f --- /dev/null +++ b/textures/redwool.png diff --git a/textures/redwoolicon.png b/textures/redwoolicon.png Binary files differnew file mode 100644 index 0000000..8caebf9 --- /dev/null +++ b/textures/redwoolicon.png diff --git a/textures/whitewool.png b/textures/whitewool.png Binary files differnew file mode 100644 index 0000000..3c68aec --- /dev/null +++ b/textures/whitewool.png diff --git a/textures/whitewoolicon.png b/textures/whitewoolicon.png Binary files differnew file mode 100644 index 0000000..0f187cf --- /dev/null +++ b/textures/whitewoolicon.png |
