From b4585163dbb0c7c5d39fc7f2df207580cbee7974 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 12 Nov 2014 14:14:37 -0800 Subject: [PATCH] Global board position / piece boundaries --- examples/entityScripts/chessPiece.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/entityScripts/chessPiece.js b/examples/entityScripts/chessPiece.js index 5342e9cd4f..fe68e2a13b 100644 --- a/examples/entityScripts/chessPiece.js +++ b/examples/entityScripts/chessPiece.js @@ -1,4 +1,6 @@ (function(){ + this.GRID_POSITION = { x: 1, y: 1, z: 1 }; + this.GRID_SIZE = 1.0; this.sound = null; this.entityID = null; this.properties = null; @@ -24,15 +26,16 @@ Entities.editEntity(this.entityID, { position: intersection }); } this.snapToGrid = function() { - var position = { x: 1, y: 1, z: 1 }; - var size = 1.0; + var position = this.GRID_POSITION; + var size = this.GRID_SIZE; var tileSize = size / 8.0; var height = tileSize * 0.2; - var relative = Vec3.subtract(this.properties.position, position); var i = Math.floor(relative.x / tileSize); var j = Math.floor(relative.z / tileSize); + i = Math.min(Math.max(0, i), 7); + j = Math.min(Math.max(-1, j), 8); relative.x = (i + 0.5) * tileSize; relative.z = (j + 0.5) * tileSize; @@ -58,7 +61,6 @@ Audio.playSound(this.sound, options); } - this.clickDownOnEntity = function(entityID, mouseEvent){ this.maybeDownloadSound(); this.updateProperties(entityID);