summaryrefslogtreecommitdiff
path: root/gui.js
diff options
context:
space:
mode:
authorCode WvS <code-wvs@quantentunnel.de>2015-01-25 18:43:48 +0100
committerCode WvS <code-wvs@quantentunnel.de>2015-01-25 18:43:48 +0100
commit7c567632f21d37509b656cf820ffbbc08e3d98f2 (patch)
tree5e75eb9b5bfd7a71a022b34c59f7ac8881da060d /gui.js
parent60002bda7ca804808dcfae82bc46847068a2f917 (diff)
downloadsnap-byow-7c567632f21d37509b656cf820ffbbc08e3d98f2.tar.gz
snap-byow-7c567632f21d37509b656cf820ffbbc08e3d98f2.zip
make every sprite represent a player; stage gets the cam
Diffstat (limited to 'gui.js')
-rw-r--r--gui.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/gui.js b/gui.js
index ee5cd60..569e580 100644
--- a/gui.js
+++ b/gui.js
@@ -2953,6 +2953,62 @@ IDE_Morph.prototype.openProjectString = function (str) {
};
IDE_Morph.prototype.rawOpenProjectString = function (str) {
+ // BYOW changes
+ // TODO too messy, split things up function
+ function generator(x, y, z) {
+ return y === 1 ? 1 : 0;
+ }
+ 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();
+ });
+ }
+
+ window.game = window.gameWorld = undefined;
+
+ var options = {
+ generate: generator,
+ chunkDistance: 2
+ };
+ window.game = createGame(options);
+ window.gameWorld = document.createElement('div');
+ window.game.appendTo(window.gameWorld);
+ window.createPlayer = window.player(window.game);
+ window.gamePlayer = createPlayer('greg.png');
+ window.gamePlayer.possess();
+ window.gamePlayer.yaw.position.set(2, 14, 4);
+ defaultSetup(window.game, window.gamePlayer);
+
this.toggleAppMode(false);
this.spriteBar.tabBar.tabTo('scripts');
StageMorph.prototype.hiddenPrimitives = {};