From 97386ee4fdda708b719282ec558244d2e84de61d Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Tue, 13 Feb 2018 10:35:25 +0100 Subject: [PATCH] Update: CC - Bacon - Entity Loaded (2xswm1bwq8.js) 7303 bytes modified --- 2xswm1bwq8.js | 2051 +++++++++++++++++++++++++------------------------ 1 file changed, 1027 insertions(+), 1024 deletions(-) diff --git a/2xswm1bwq8.js b/2xswm1bwq8.js index d64d59e..591b616 100644 --- a/2xswm1bwq8.js +++ b/2xswm1bwq8.js @@ -1,13 +1,18 @@ if (data.entity === this.parentEntity) { - console.log('my entity loaded'); + console.log('my entity loaded'); } -this.beforeRender = GameLib.EntityManager.Instance.findComponentById('o4c478xpx3'); -this.renderer = GameLib.EntityManager.Instance.findComponentById('nofv0eath8'); -this.keyDown = GameLib.EntityManager.Instance.findComponentById('dgscoensvf'); -this.touchStart = GameLib.EntityManager.Instance.findComponentById('xjaoh824ff'); -this.touchEnd = GameLib.EntityManager.Instance.findComponentById('ohqwmnjfgf'); +/** + * Custom Code Components + */ +this.ccBeforeRender = GameLib.EntityManager.Instance.findComponentById('o4c478xpx3'); +this.ccKeyDown = GameLib.EntityManager.Instance.findComponentById('dgscoensvf'); +this.ccTouchStart = GameLib.EntityManager.Instance.findComponentById('xjaoh824ff'); +this.ccTouchEnd = GameLib.EntityManager.Instance.findComponentById('ohqwmnjfgf'); +/** + * Images + */ this.image_0 = GameLib.EntityManager.Instance.findComponentById('gvrik6h4yd'); this.image_1 = GameLib.EntityManager.Instance.findComponentById('ssdlmrpv9j'); this.image_2 = GameLib.EntityManager.Instance.findComponentById('zdg2qpu35c'); @@ -50,1356 +55,1354 @@ GameLib.CustomCode.TETRIS_GRID_DISAPPEARING = 2; GameLib.CustomCode.prototype.visualizeGrid = function (color) { - if (this.starsMesh) { - this.scene.instance.remove(this.starsMesh); - } + if (this.starsMesh) { + this.scene.instance.remove(this.starsMesh); + } - this.starsGeometry = new THREE.Geometry(); + this.starsGeometry = new THREE.Geometry(); - for (var y = 0; y < this.beforeRender.grid.length; y++) { - for (var x = 0; x < this.beforeRender.grid[y].length; x++) { - if (this.beforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { - this.starsGeometry.vertices.push( - new THREE.Vector3( - x, - y, - 5 - ) - ); - } - } - } + for (var y = 0; y < this.ccBeforeRender.grid.length; y++) { + for (var x = 0; x < this.ccBeforeRender.grid[y].length; x++) { + if (this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { + this.starsGeometry.vertices.push( + new THREE.Vector3( + x, + y, + 5 + ) + ); + } + } + } - var starsMaterial = new THREE.PointsMaterial({color: color, size: 0.1}); + var starsMaterial = new THREE.PointsMaterial({color: color, size: 0.1}); - this.starsMesh = new THREE.Points(this.starsGeometry, starsMaterial); + this.starsMesh = new THREE.Points(this.starsGeometry, starsMaterial); - this.scene.instance.add(this.starsMesh); + this.scene.instance.add(this.starsMesh); }.bind(this) GameLib.CustomCode.prototype.startAnimation = function (index) { - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - var bacon = this.meshBaconDisappearing.clone(); - bacon.position.x = x; - bacon.position.y = index; - bacon.position.z = 0.2; - bacon.updateInstance('position'); + var bacon = this.meshBaconDisappearing.clone(); + bacon.position.x = x; + bacon.position.y = index; + bacon.position.z = 0.2; + bacon.updateInstance('position'); - this.beforeRender.grid[index][x].baconDisappearing = bacon; + this.ccBeforeRender.grid[index][x].baconDisappearing = bacon; - this.baconMaterials.push( - this.beforeRender.grid[index][x].mesh.materials[0] - ); - } + this.baconMaterials.push( + this.ccBeforeRender.grid[index][x].mesh.materials[0] + ); + } - var glow = this.glow.clone(); + var glow = this.glow.clone(); - glow.position.y = index; - glow.position.x = (GameLib.CustomCode.TETRIS_GRID_WIDTH / 2) - 0.5; - glow.position.z = 2; - glow.updateInstance('position'); + glow.position.y = index; + glow.position.x = (GameLib.CustomCode.TETRIS_GRID_WIDTH / 2) - 0.5; + glow.position.z = 2; + glow.updateInstance('position'); - var flames = this.flamesSmall.clone(); + var flames = this.flamesSmall.clone(); - flames.position.y = index + 0.5; - flames.position.x = (GameLib.CustomCode.TETRIS_GRID_WIDTH / 2) - 0.5; - flames.position.z = 2; - flames.updateInstance('position'); + flames.position.y = index + 0.5; + flames.position.x = (GameLib.CustomCode.TETRIS_GRID_WIDTH / 2) - 0.5; + flames.position.z = 2; + flames.updateInstance('position'); - var animationObject = { - rowNumber: index, - glow: glow, - flames: flames, - flamesArray: [], - time: 0 - } + var animationObject = { + rowNumber: index, + glow: glow, + flames: flames, + flamesArray: [], + time: 0 + } - animationObject.subscription = GameLib.Event.Subscribe( - GameLib.Event.BEFORE_RENDER, - function (__animationObject) { - return function (data) { - __animationObject.time += data.delta * 4; + animationObject.subscription = GameLib.Event.Subscribe( + GameLib.Event.BEFORE_RENDER, + function (__animationObject) { + return function (data) { + __animationObject.time += data.delta * 4; - this.burnLight.intensity = Math.sin(__animationObject.time); - this.burnLight.updateInstance('intensity'); + this.burnLight.intensity = Math.sin(__animationObject.time); + this.burnLight.updateInstance('intensity'); - this.glowMaterial.opacity = Math.sin(__animationObject.time); - this.glowMaterial.updateInstance('opacity'); + this.glowMaterial.opacity = Math.sin(__animationObject.time); + this.glowMaterial.updateInstance('opacity'); - if (__animationObject.time < (Math.PI / 2)) { + if (__animationObject.time < (Math.PI / 2)) { - this.baconMaterials.map( - function (material) { - material.displacementScale = -1 * Math.sin(__animationObject.time); - material.updateInstance('displacementScale'); - } - ); + this.baconMaterials.map( + function (material) { + material.displacementScale = -1 * Math.sin(__animationObject.time); + material.updateInstance('displacementScale'); + } + ); - } + } - if (__animationObject.time > Math.PI) { + if (__animationObject.time > Math.PI) { - __animationObject.subscription.remove(); + __animationObject.subscription.remove(); - /** - * Done with animation - */ - this.burnLight.intensity = 0; - this.burnLight.updateInstance('intensity'); + /** + * Done with animation + */ + this.burnLight.intensity = 0; + this.burnLight.updateInstance('intensity'); - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: __animationObject.glow - } - ); + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: __animationObject.glow + } + ); - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: __animationObject.flames - } - ); + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: __animationObject.flames + } + ); - /** - * Remove any additional flames - */ - __animationObject.flamesArray.map( - function (flame) { - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: flame - } - ); - } - ); + /** + * Remove any additional flames + */ + __animationObject.flamesArray.map( + function (flame) { + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: flame + } + ); + } + ); - /** - * Remove the meshes and the baconDisappearing objects - */ - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + /** + * Remove the meshes and the baconDisappearing objects + */ + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - if (!this.beforeRender.grid[__animationObject.rowNumber][x].mesh) { - throw new Error('mesh should exist but does not'); - } + if (!this.ccBeforeRender.grid[__animationObject.rowNumber][x].mesh) { + throw new Error('mesh should exist but does not'); + } - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: this.beforeRender.grid[__animationObject.rowNumber][x].mesh - } - ); + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: this.ccBeforeRender.grid[__animationObject.rowNumber][x].mesh + } + ); - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: this.beforeRender.grid[__animationObject.rowNumber][x].baconDisappearing - } - ); + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: this.ccBeforeRender.grid[__animationObject.rowNumber][x].baconDisappearing + } + ); - } + } - /** - * Add a new row to the top of the grid - */ - this.beforeRender.grid.splice(__animationObject.rowNumber, 1); + /** + * Add a new row to the top of the grid + */ + this.ccBeforeRender.grid.splice(__animationObject.rowNumber, 1); - var row = []; + var row = []; - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - row.push( - { - value: GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN, - mesh: null - } - ) - } + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + row.push( + { + value: GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN, + mesh: null + } + ) + } - this.beforeRender.grid.push(row); + this.ccBeforeRender.grid.push(row); - /** - * Now - drop all blocks above the current index down one row - */ - for (var y = __animationObject.rowNumber; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT - 1; y++) { - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + /** + * Now - drop all blocks above the current index down one row + */ + for (var y = __animationObject.rowNumber; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT - 1; y++) { + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - if (this.beforeRender.grid[y][x].mesh) { - this.beforeRender.grid[y][x].mesh.position.y = y; - this.beforeRender.grid[y][x].mesh.updateInstance('position'); - } + if (this.ccBeforeRender.grid[y][x].mesh) { + this.ccBeforeRender.grid[y][x].mesh.position.y = y; + this.ccBeforeRender.grid[y][x].mesh.updateInstance('position'); + } - if (this.beforeRender.grid[y][x].baconDisappearing) { - this.beforeRender.grid[y][x].baconDisappearing.position.y = y; - this.beforeRender.grid[y][x].baconDisappearing.updateInstance('position'); - } - } - } + if (this.ccBeforeRender.grid[y][x].baconDisappearing) { + this.ccBeforeRender.grid[y][x].baconDisappearing.position.y = y; + this.ccBeforeRender.grid[y][x].baconDisappearing.updateInstance('position'); + } + } + } - /** - * Find any animation objects with a line number greater than our current line number, decrease it - */ - this.animationObjects.map( - function (animationObject) { - if (animationObject.rowNumber > __animationObject.rowNumber) { - animationObject.rowNumber -= 1; - } - } - ) + /** + * Find any animation objects with a line number greater than our current line number, decrease it + */ + this.animationObjects.map( + function (animationObject) { + if (animationObject.rowNumber > __animationObject.rowNumber) { + animationObject.rowNumber -= 1; + } + } + ) - var objectIndex = this.animationObjects.indexOf(__animationObject); + var objectIndex = this.animationObjects.indexOf(__animationObject); - /** - * Remove ourselves from the animation objects - */ - this.animationObjects.splice(objectIndex, 1); + /** + * Remove ourselves from the animation objects + */ + this.animationObjects.splice(objectIndex, 1); - /** - * Restore our bacon materials if we have no more animation objects - */ - if (this.animationObjects.length === 0) { + /** + * Restore our bacon materials if we have no more animation objects + */ + if (this.animationObjects.length === 0) { - this.baconMaterials.map( - function (material) { - material.displacementScale = 0; - material.updateInstance('displacementScale'); - } - ); + this.baconMaterials.map( + function (material) { + material.displacementScale = 0; + material.updateInstance('displacementScale'); + } + ); - this.baconMaterials = []; - } + this.baconMaterials = []; + } - } + } - }.bind(this) - }.bind(this)(animationObject) - ); + }.bind(this) + }.bind(this)(animationObject) + ); - this.animationObjects.push(animationObject); + this.animationObjects.push(animationObject); }.bind(this) GameLib.CustomCode.prototype.removeLines = function () { - var indices = []; + var indices = []; - for (var y = 0; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT; y++) { + for (var y = 0; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT; y++) { - var line = true; + var line = true; - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - if ( - this.beforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN || - this.beforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING - ) { - line = false; - } - } + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + if ( + this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN || + this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING + ) { + line = false; + } + } - if (line) { - indices.push(y); - } - } + if (line) { + indices.push(y); + } + } - var multiplier = 1; + var multiplier = 1; - if (indices.length === 4) { - multiplier = 10000; - } + if (indices.length === 4) { + multiplier = 10000; + } - if (indices.length === 3) { - multiplier = 1000; - } + if (indices.length === 3) { + multiplier = 1000; + } - if (indices.length === 2) { - multiplier = 100; - } + if (indices.length === 2) { + multiplier = 100; + } - if (indices.length === 1) { - multiplier = 10; - } + if (indices.length === 1) { + multiplier = 10; + } - this.score += (multiplier * this.level); + this.score += (multiplier * this.level); - this.rows += indices.length; + this.rows += indices.length; - this.level = Math.floor(this.rows / 5) + 1; + this.level = Math.floor(this.rows / 5) + 1; - if (this.level === 1) { - this.speed = 1; - } + if (this.level === 1) { + this.speed = 1; + } - if (this.level === 2) { - this.speed = 0.9; - } + if (this.level === 2) { + this.speed = 0.9; + } - if (this.level === 3) { - this.speed = 0.85; - } + if (this.level === 3) { + this.speed = 0.85; + } - if (this.level === 4) { - this.speed = 0.8; - } + if (this.level === 4) { + this.speed = 0.8; + } - if (this.level === 5) { - this.speed = 0.75; - } + if (this.level === 5) { + this.speed = 0.75; + } - if (this.level === 6) { - this.speed = 0.7; - } + if (this.level === 6) { + this.speed = 0.7; + } - if (this.level === 7) { - this.speed = 0.65; - } + if (this.level === 7) { + this.speed = 0.65; + } - if (this.level === 8) { - this.speed = 0.6; - } + if (this.level === 8) { + this.speed = 0.6; + } - if (this.level === 9) { - this.speed = 0.55; - } + if (this.level === 9) { + this.speed = 0.55; + } - if (this.level === 10) { - this.speed = 0.5; - } + if (this.level === 10) { + this.speed = 0.5; + } - if (this.level === 11) { - this.speed = 0.45; - } + if (this.level === 11) { + this.speed = 0.45; + } - if (this.level === 12) { - this.speed = 0.4; - } + if (this.level === 12) { + this.speed = 0.4; + } - if (this.level === 13) { - this.speed = 0.35; - } + if (this.level === 13) { + this.speed = 0.35; + } - if (this.level === 14) { - this.speed = 0.3; - } + if (this.level === 14) { + this.speed = 0.3; + } - if (this.level === 15) { - this.speed = 0.25; - } + if (this.level === 15) { + this.speed = 0.25; + } - if (this.level === 16) { - this.speed = 0.2; - } + if (this.level === 16) { + this.speed = 0.2; + } - if (this.level >= 17) { - this.speed = 0.18; - } + if (this.level >= 17) { + this.speed = 0.18; + } - this.drawStatus(); + this.drawStatus(); - this.animationsDone = []; + this.animationsDone = []; - indices.map( - function (index) { - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - this.beforeRender.grid[index][x].value = GameLib.CustomCode.TETRIS_GRID_DISAPPEARING; - } - this.startAnimation(index); - }.bind(this) - ); + indices.map( + function (index) { + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + this.ccBeforeRender.grid[index][x].value = GameLib.CustomCode.TETRIS_GRID_DISAPPEARING; + } + this.startAnimation(index); + }.bind(this) + ); }.bind(this); GameLib.CustomCode.prototype.drawStatus = function () { - var context = this.canvas.instance.getContext('2d'); + var context = this.canvas.instance.getContext('2d'); - context.textBaseline = "middle"; + context.textBaseline = "middle"; - context.clearRect(0, 0, this.canvas.width, this.canvas.height); + context.clearRect(0, 0, this.canvas.width, this.canvas.height); - context.fillStyle = "rgba(58, 36, 25, 0.7)"; - context.fillRect(12, 30, 485, 178); + context.fillStyle = "rgba(58, 36, 25, 0.7)"; + context.fillRect(12, 30, 485, 178); - context.lineWidth = 8; + context.lineWidth = 8; - context.strokeStyle = '#612d1a'; - context.strokeRect(12, 30, 485, 178); + context.strokeStyle = '#612d1a'; + context.strokeRect(12, 30, 485, 178); - context.beginPath(); - context.moveTo(11, 68); - context.lineTo(498, 68); - context.stroke(); + context.beginPath(); + context.moveTo(11, 68); + context.lineTo(498, 68); + context.stroke(); - context.beginPath(); - context.moveTo(172, 30); - context.lineTo(172, 208); - context.stroke(); + context.beginPath(); + context.moveTo(172, 30); + context.lineTo(172, 208); + context.stroke(); - context.beginPath(); - context.moveTo(172, 135); - context.lineTo(498, 135); - context.stroke(); + context.beginPath(); + context.moveTo(172, 135); + context.lineTo(498, 135); + context.stroke(); - context.beginPath(); - context.moveTo(172, 172); - context.lineTo(498, 172); - context.stroke(); + context.beginPath(); + context.moveTo(172, 172); + context.lineTo(498, 172); + context.stroke(); - /** - * Write text - */ - context.fillStyle = '#7e3b26'; - context.font = '20pt BkBold'; - context.fillText('NEXT TILES', 23, 52); + /** + * Write text + */ + context.fillStyle = '#7e3b26'; + context.font = '20pt BkBold'; + context.fillText('NEXT TILES', 23, 52); - context.fillText('SCORE', 182, 52); + context.fillText('SCORE', 182, 52); - context.fillText('LEVEL', 182, 156); + context.fillText('LEVEL', 182, 156); - context.fillText('ROWS', 182, 193); + context.fillText('ROWS', 182, 193); - context.fillStyle = '#e0b899'; + context.fillStyle = '#e0b899'; - context.font = '50pt BkBold'; + context.font = '50pt BkBold'; - var str = this.score.toString(); - var pad = "0000000"; - var ans = pad.substring(0, pad.length - str.length) + str; + var str = this.score.toString(); + var pad = "0000000"; + var ans = pad.substring(0, pad.length - str.length) + str; - context.fillText(ans, 225, 110); + context.fillText(ans, 225, 110); - str = this.level.toString(); - pad = "000"; - ans = pad.substring(0, pad.length - str.length) + str; + str = this.level.toString(); + pad = "000"; + ans = pad.substring(0, pad.length - str.length) + str; - context.font = '20pt BkBold'; - context.fillText(ans, 435, 156); + context.font = '20pt BkBold'; + context.fillText(ans, 435, 156); - str = this.rows.toString(); - pad = "000"; - ans = pad.substring(0, pad.length - str.length) + str; + str = this.rows.toString(); + pad = "000"; + ans = pad.substring(0, pad.length - str.length) + str; - context.font = '20pt BkBold'; - context.fillText(ans, 435, 193); + context.font = '20pt BkBold'; + context.fillText(ans, 435, 193); - this.scoreTexture.instance.needsUpdate = true; + this.scoreTexture.instance.needsUpdate = true; }.bind(this) GameLib.CustomCode.prototype.getBlockGridPositions = function (block) { - var object = new THREE.Mesh(); + var object = new THREE.Mesh(); - object.position.x = block.center.position.x; - object.position.y = block.center.position.y; - object.position.z = block.center.position.z; - object.rotation.x = block.center.rotation.x; - object.rotation.y = block.center.rotation.y; - object.rotation.z = block.center.rotation.z; + object.position.x = block.center.position.x; + object.position.y = block.center.position.y; + object.position.z = block.center.position.z; + object.rotation.x = block.center.rotation.x; + object.rotation.y = block.center.rotation.y; + object.rotation.z = block.center.rotation.z; - var children = block.meshes.map( - function (mesh) { - var child = new THREE.Mesh(); - child.position.x = mesh.position.x; - child.position.y = mesh.position.y; - child.position.z = mesh.position.z; - object.add(child); - child.mesh = mesh; - return child; - } - ); + var children = block.meshes.map( + function (mesh) { + var child = new THREE.Mesh(); + child.position.x = mesh.position.x; + child.position.y = mesh.position.y; + child.position.z = mesh.position.z; + object.add(child); + child.mesh = mesh; + return child; + } + ); - object.updateMatrixWorld(); + object.updateMatrixWorld(); - var positions = children.map( - function (child) { + var positions = children.map( + function (child) { - var vector = new THREE.Vector3(); + var vector = new THREE.Vector3(); - vector.setFromMatrixPosition(child.matrixWorld); + vector.setFromMatrixPosition(child.matrixWorld); - var x = vector.x; - var y = vector.y; + var x = vector.x; + var y = vector.y; - x = Math.round(x); - y = Math.round(y); + x = Math.round(x); + y = Math.round(y); - return { - x: x, - y: y, - mesh: child.mesh - } - } - ); + return { + x: x, + y: y, + mesh: child.mesh + } + } + ); - return positions; + return positions; }.bind(this); GameLib.CustomCode.prototype.stopAnimations = function () { - this.animationSystems.map( - function (system) { - if (system.started) { - system.stop(); - } - } - ); + this.animationSystems.map( + function (system) { + if (system.started) { + system.stop(); + } + } + ); }.bind(this) GameLib.CustomCode.prototype.startAnimations = function () { - this.animationSystems.map( - function (system) { - if (!system.started) { - system.start(); - } - } - ); + this.animationSystems.map( + function (system) { + if (!system.started) { + system.start(); + } + } + ); }.bind(this) GameLib.CustomCode.prototype.drawGrid = function () { - this.gridMaterial.color.fromHex('#a79f99'); - this.gridMaterial.color.updateInstance('color'); + this.gridMaterial.color.fromHex('#a79f99'); + this.gridMaterial.color.updateInstance('color'); - var geometry = new THREE.Geometry(); + var geometry = new THREE.Geometry(); - for (var y = 0; y < (GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE); y++) { - for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { - geometry.vertices.push( - new THREE.Vector3( - x, - y, - 0.17 - ) - ) - } - } + for (var y = 0; y < (GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE); y++) { + for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { + geometry.vertices.push( + new THREE.Vector3( + x, + y, + 0.17 + ) + ) + } + } - this.scene.instance.add(new THREE.Points(geometry, this.gridMaterial.instance)); + this.scene.instance.add(new THREE.Points(geometry, this.gridMaterial.instance)); - geometry = new THREE.Geometry(); + geometry = new THREE.Geometry(); - geometry.vertices.push( - new THREE.Vector3( - -0.5, - GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE - 0.5, - 5 - ), - new THREE.Vector3( - -0.5, - -0.5, - 5 - ), - new THREE.Vector3( - GameLib.CustomCode.TETRIS_GRID_WIDTH - 0.5, - -0.5, - 5 - ), - new THREE.Vector3( - GameLib.CustomCode.TETRIS_GRID_WIDTH - 0.5, - GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE - 0.5, - 5 - ) - ); + geometry.vertices.push( + new THREE.Vector3( + -0.5, + GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE - 0.5, + 5 + ), + new THREE.Vector3( + -0.5, + -0.5, + 5 + ), + new THREE.Vector3( + GameLib.CustomCode.TETRIS_GRID_WIDTH - 0.5, + -0.5, + 5 + ), + new THREE.Vector3( + GameLib.CustomCode.TETRIS_GRID_WIDTH - 0.5, + GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE - 0.5, + 5 + ) + ); - this.scene.instance.add( - new THREE.Line( - geometry, - new THREE.LineBasicMaterial( - { - linewidth: 3, - color: 0x612d1a - } - ) - ) - ); + this.scene.instance.add( + new THREE.Line( + geometry, + new THREE.LineBasicMaterial( + { + linewidth: 3, + color: 0x612d1a + } + ) + ) + ); }.bind(this) GameLib.CustomCode.prototype.checkBoundaries = function (block) { - /** - * collisions are true only for out of bounds indexes, and if the current block is taken - */ - var gridPositions = this.getBlockGridPositions(block); + /** + * collisions are true only for out of bounds indexes, and if the current block is taken + */ + var gridPositions = this.getBlockGridPositions(block); - var leftHit = false; - var rightHit = false; - var bottomHit = false; - var topHit = false; - var collision = false; - var bottomDisappearing = false; + var leftHit = false; + var rightHit = false; + var bottomHit = false; + var topHit = false; + var collision = false; + var bottomDisappearing = false; - gridPositions.map( - function (position) { + gridPositions.map( + function (position) { - /** - * Check grid boundaries + /** + * Check grid boundaries + */ + if (position.x === 0) { + leftHit = true; + } + + if (position.x === (GameLib.CustomCode.TETRIS_GRID_WIDTH - 1)) { + rightHit = true; + } + + if (position.y === 0) { + bottomHit = true; + } + + if (position.y === (GameLib.CustomCode.TETRIS_GRID_HEIGHT - 1)) { + topHit = true; + } + + /** + * Check outside of bounds + */ + if (position.x < 0) { + collision = true; + } + + if (position.x >= GameLib.CustomCode.TETRIS_GRID_WIDTH) { + collision = true; + } + + if (position.y < 0) { + collision = true; + } + + if (position.y >= GameLib.CustomCode.TETRIS_GRID_HEIGHT) { + collision = true; + } + + /** + * We want to see if the block to the right is taken, but we cannot + * be sure x+1 is inside bounds + */ + if ( + ((position.x + 1) < GameLib.CustomCode.TETRIS_GRID_WIDTH) && + ((position.x + 1) >= 0) + ) { + /** + * But we cannot be sure y is inside bounds */ - if (position.x === 0) { - leftHit = true; - } + if (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) { + if (this.ccBeforeRender.grid[position.y][position.x + 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { + /** + * Ok - we found a block to the right - its over + */ + rightHit = true; + } + } + } - if (position.x === (GameLib.CustomCode.TETRIS_GRID_WIDTH - 1)) { - rightHit = true; - } - if (position.y === 0) { - bottomHit = true; - } + /** + * We want to see if the block to the left is taken, but we cannot be sure x - 1 is inside bounds + */ + if ( + ((position.x) > 0) && + ((position.x - 1) >= 0) && + ((position.x - 1) < GameLib.CustomCode.TETRIS_GRID_WIDTH) + ) { - if (position.y === (GameLib.CustomCode.TETRIS_GRID_HEIGHT - 1)) { - topHit = true; - } - - /** - * Check outside of bounds + /** + * But we cannot be sure y is inside bounds */ - if (position.x < 0) { - collision = true; - } + if (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) { + if (this.ccBeforeRender.grid[position.y][position.x - 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { + /** + * We found a block to the left - its over also + */ + leftHit = true; + } + } + } - if (position.x >= GameLib.CustomCode.TETRIS_GRID_WIDTH) { - collision = true; - } - - if (position.y < 0) { - collision = true; - } - - if (position.y >= GameLib.CustomCode.TETRIS_GRID_HEIGHT) { - collision = true; - } - - /** - * We want to see if the block to the right is taken, but we cannot - * be sure x+1 is inside bounds + /** + * Now we want to see if the block above is taken, we cannot be sure y+1 is inside bounds + */ + if ( + ((position.y + 1) < GameLib.CustomCode.TETRIS_GRID_HEIGHT) && + ((position.y + 1) >= 0) + ) { + /** + * We cannot be sure, position.x is inside bounds */ - if ( - ((position.x + 1) < GameLib.CustomCode.TETRIS_GRID_WIDTH) && - ((position.x + 1) >= 0) - ) { - /** - * But we cannot be sure y is inside bounds - */ - if (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) { - if (this.beforeRender.grid[position.y][position.x + 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { - /** - * Ok - we found a block to the right - its over - */ - rightHit = true; - } - } - } + if (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) { + if (this.ccBeforeRender.grid[position.y + 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { + /** + * Ok - this block is at the top + */ + topHit = true; + } + } + } - /** - * We want to see if the block to the left is taken, but we cannot be sure x - 1 is inside bounds + /** + * Now we want to see if the block below is taken, we cannot be sure y-1 is inside bounds + */ + if ( + ((position.y) > 0) && + ((position.y - 1) >= 0) && + ((position.y - 1) < GameLib.CustomCode.TETRIS_GRID_HEIGHT) + ) { + /** + * We cannot be sure, position.x is inside bounds */ - if ( - ((position.x) > 0) && - ((position.x - 1) >= 0) && - ((position.x - 1) < GameLib.CustomCode.TETRIS_GRID_WIDTH) - ) { + if (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) { + if (this.ccBeforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { + /** + * Ok - this block hit bottom + */ + bottomHit = true; + } - /** - * But we cannot be sure y is inside bounds - */ - if (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) { - if (this.beforeRender.grid[position.y][position.x - 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { - /** - * We found a block to the left - its over also - */ - leftHit = true; - } - } - } + if (this.ccBeforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING) { + bottomDisappearing = true; + } + } + } - /** - * Now we want to see if the block above is taken, we cannot be sure y+1 is inside bounds - */ - if ( - ((position.y + 1) < GameLib.CustomCode.TETRIS_GRID_HEIGHT) && - ((position.y + 1) >= 0) - ) { - /** - * We cannot be sure, position.x is inside bounds - */ - if (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) { + /** + * Now we want to see if the block is inside another block, + * we cannot be sure, x and y is inside bounds + */ + if ( + (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) && + (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) + ) { + if (this.ccBeforeRender.grid[position.y][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { + collision = true; + } + } + }.bind(this) + ); - if (this.beforeRender.grid[position.y + 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { - /** - * Ok - this block is at the top - */ - topHit = true; - } - } - } - - /** - * Now we want to see if the block below is taken, we cannot be sure y-1 is inside bounds - */ - if ( - ((position.y) > 0) && - ((position.y - 1) >= 0) && - ((position.y - 1) < GameLib.CustomCode.TETRIS_GRID_HEIGHT) - ) { - /** - * We cannot be sure, position.x is inside bounds - */ - if (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) { - if (this.beforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { - /** - * Ok - this block hit bottom - */ - bottomHit = true; - } - - if (this.beforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING) { - bottomDisappearing = true; - } - } - } - - /** - * Now we want to see if the block is inside another block, - * we cannot be sure, x and y is inside bounds - */ - if ( - (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) && - (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) - ) { - if (this.beforeRender.grid[position.y][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { - collision = true; - } - } - }.bind(this) - ); - - return { - left: leftHit, - top: topHit, - right: rightHit, - bottom: bottomHit, - bottomDisappearing: bottomDisappearing, - collision: collision - } + return { + left: leftHit, + top: topHit, + right: rightHit, + bottom: bottomHit, + bottomDisappearing: bottomDisappearing, + collision: collision + } }.bind(this) GameLib.CustomCode.prototype.rotateBlock = function (clockwise) { - if (this.beforeRender.gameOver) { - return; - } + if (this.ccBeforeRender.gameOver) { + return; + } - if (clockwise) { - var targetRotation = this.block.center.rotation.z - Math.PI / 2; - } else { - var targetRotation = this.block.center.rotation.z + Math.PI / 2; - } + if (clockwise) { + var targetRotation = this.block.center.rotation.z - Math.PI / 2; + } else { + var targetRotation = this.block.center.rotation.z + Math.PI / 2; + } - this.stopAnimations(); + this.stopAnimations(); - var originalRotation = this.block.center.rotation.z; + var originalRotation = this.block.center.rotation.z; - this.block.center.rotation.z = targetRotation; - this.block.center.updateInstance('rotation'); + this.block.center.rotation.z = targetRotation; + this.block.center.updateInstance('rotation'); - var boundaries = this.checkBoundaries(this.block); + var boundaries = this.checkBoundaries(this.block); - if (boundaries.collision) { + if (boundaries.collision) { - this.block.center.rotation.z = originalRotation; - this.block.center.updateInstance('rotation'); + this.block.center.rotation.z = originalRotation; + this.block.center.updateInstance('rotation'); - this.startAnimations(); + this.startAnimations(); - } else { + } else { - this.block.center.rotation.z = originalRotation; + this.block.center.rotation.z = originalRotation; - this.startAnimations(); + this.startAnimations(); - this.block.center.rotation.z = targetRotation; - this.block.center.updateInstance('rotation'); + this.block.center.rotation.z = targetRotation; + this.block.center.updateInstance('rotation'); - } + } }.bind(this); GameLib.CustomCode.prototype.moveBlock = function (block, direction, units, collisionCheck) { - if (!units) { - units = 1; - } + if (!units) { + units = 1; + } - var boundaries = null; - var moved = false; + var boundaries = null; + var moved = false; - if (collisionCheck) { - boundaries = this.checkBoundaries(block); - } + if (collisionCheck) { + boundaries = this.checkBoundaries(block); + } - if (boundaries && boundaries.collision) { - return moved; - } + if (boundaries && boundaries.collision) { + return moved; + } - if (direction.left) { + if (direction.left) { - if (boundaries && boundaries.left) { - //Do nothing - } else { - block.center.position.x -= units; - moved = true; - } - } + if (boundaries && boundaries.left) { + //Do nothing + } else { + block.center.position.x -= units; + moved = true; + } + } - if (direction.right) { + if (direction.right) { - if (boundaries && boundaries.right) { - //Do nothing - } else { - block.center.position.x += units; - moved = true; - } - } + if (boundaries && boundaries.right) { + //Do nothing + } else { + block.center.position.x += units; + moved = true; + } + } - if (direction.down) { + if (direction.down) { - if (boundaries && boundaries.bottom) { - //Do nothing - } else if (boundaries && boundaries.bottomDisappearing) { - /** - * Set moved to 'null' instead of 'false' - null indicates to called we should wait - while still being 'false' - */ - moved = null; - } else { - block.center.position.y -= units; - moved = true; - } - } + if (boundaries && boundaries.bottom) { + //Do nothing + } else if (boundaries && boundaries.bottomDisappearing) { + /** + * Set moved to 'null' instead of 'false' - null indicates to called we should wait - while still being 'false' + */ + moved = null; + } else { + block.center.position.y -= units; + moved = true; + } + } - if (direction.up) { + if (direction.up) { - if (boundaries && boundaries.top) { - //Do nothing - } else { - block.center.position.y += units; - moved = true; - } - } + if (boundaries && boundaries.top) { + //Do nothing + } else { + block.center.position.y += units; + moved = true; + } + } - if (moved) { - block.center.updateInstance('position'); - } + if (moved) { + block.center.updateInstance('position'); + } - return moved; + return moved; }.bind(this); GameLib.CustomCode.prototype.spawnBlock = function () { - var blockType = Math.floor(Math.random() * 7); + var blockType = Math.floor(Math.random() * 7); - var mesh0 = null; - var mesh1 = null; - var mesh2 = null; - var mesh3 = null; + var mesh0 = null; + var mesh1 = null; + var mesh2 = null; + var mesh3 = null; - var offsetX = 0; - var offsetY = 0; + var offsetX = 0; + var offsetY = 0; - var tinyPositionX = 0; - var tinyPositionY = 0; + var tinyPositionX = 0; + var tinyPositionY = 0; - var nextPositionX = 0; - var nextPositionY = 0; + var nextPositionX = 0; + var nextPositionY = 0; - var center = this.boxCenter.clone(); + var center = this.boxCenter.clone(); - center.position.y = 0; - center.position.x = 0; - center.position.z = 0.4; + center.position.y = 0; + center.position.x = 0; + center.position.z = 0.4; - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_I) { + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_I) { - mesh0 = this.tile_4.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.x -= 1; + mesh0 = this.tile_4.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.x -= 1; - mesh1 = this.tile_5.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; - mesh1.position.x -= 2; + mesh1 = this.tile_5.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; + mesh1.position.x -= 2; - mesh2 = this.tile_6.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; - mesh2.position.x += 0; + mesh2 = this.tile_6.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; + mesh2.position.x += 0; - mesh3 = this.tile_2.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.x += 1; + mesh3 = this.tile_2.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.x += 1; - offsetX = 0.5; - offsetY = 1; + offsetX = 0.5; + offsetY = 1; - tinyPositionX = 1.32; - tinyPositionY = 16.7; + tinyPositionX = 1.32; + tinyPositionY = 16.7; - nextPositionX = 2.12; - nextPositionY = 15.5; - } + nextPositionX = 2.12; + nextPositionY = 15.5; + } - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_L) { - mesh0 = this.tile_6.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.x += 1; - mesh0.position.y += 1; + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_L) { + mesh0 = this.tile_6.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.x += 1; + mesh0.position.y += 1; - mesh1 = this.tile_4.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; - mesh1.position.x += 1; + mesh1 = this.tile_4.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; + mesh1.position.x += 1; - mesh2 = this.tile_6.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; - mesh2.position.x += 0; + mesh2 = this.tile_6.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; + mesh2.position.x += 0; - mesh3 = this.tile_2.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.x -= 1; + mesh3 = this.tile_2.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.x -= 1; - offsetX = 0.5; - offsetY = 2; + offsetX = 0.5; + offsetY = 2; - tinyPositionX = 1.00; - tinyPositionY = 16.65; + tinyPositionX = 1.00; + tinyPositionY = 16.65; - nextPositionX = 1.78; - nextPositionY = 15.3; - } + nextPositionX = 1.78; + nextPositionY = 15.3; + } - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_L2) { - mesh0 = this.tile_6.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.x -= 1; - mesh0.position.y += 1; + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_L2) { + mesh0 = this.tile_6.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.x -= 1; + mesh0.position.y += 1; - mesh1 = this.tile_4.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; - mesh1.position.x += 1; + mesh1 = this.tile_4.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; + mesh1.position.x += 1; - mesh2 = this.tile_6.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; - mesh2.position.x += 0; + mesh2 = this.tile_6.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; + mesh2.position.x += 0; - mesh3 = this.tile_2.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.x -= 1; + mesh3 = this.tile_2.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.x -= 1; - offsetX = 0.5; - offsetY = 2; + offsetX = 0.5; + offsetY = 2; - tinyPositionX = 1.00; - tinyPositionY = 16.65; + tinyPositionX = 1.00; + tinyPositionY = 16.65; - nextPositionX = 1.78; - nextPositionY = 15.3; - } + nextPositionX = 1.78; + nextPositionY = 15.3; + } - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_Z) { - mesh0 = this.tile_3.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.y += 1; + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_Z) { + mesh0 = this.tile_3.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.y += 1; - mesh1 = this.tile_4.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; - mesh1.position.x -= 1; - mesh1.position.y += 1; + mesh1 = this.tile_4.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; + mesh1.position.x -= 1; + mesh1.position.y += 1; - mesh2 = this.tile_2.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; + mesh2 = this.tile_2.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; - mesh3 = this.tile_1.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.x += 1; + mesh3 = this.tile_1.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.x += 1; - offsetX = 0.5; - offsetY = 2; + offsetX = 0.5; + offsetY = 2; - tinyPositionX = 1.00; - tinyPositionY = 16.65; + tinyPositionX = 1.00; + tinyPositionY = 16.65; - nextPositionX = 1.78; - nextPositionY = 15.3; - } + nextPositionX = 1.78; + nextPositionY = 15.3; + } - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_Z2) { + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_Z2) { - mesh0 = this.tile_3.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.y += 1; + mesh0 = this.tile_3.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.y += 1; - mesh1 = this.tile_4.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; - mesh1.position.x += 1; - mesh1.position.y += 1; + mesh1 = this.tile_4.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; + mesh1.position.x += 1; + mesh1.position.y += 1; - mesh2 = this.tile_2.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; + mesh2 = this.tile_2.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; - mesh3 = this.tile_1.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.x -= 1; + mesh3 = this.tile_1.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.x -= 1; - offsetX = 0.5; - offsetY = 2; + offsetX = 0.5; + offsetY = 2; - tinyPositionX = 1.00; - tinyPositionY = 16.65; + tinyPositionX = 1.00; + tinyPositionY = 16.65; - nextPositionX = 1.78; - nextPositionY = 15.3; - } + nextPositionX = 1.78; + nextPositionY = 15.3; + } - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_T) { - mesh0 = this.tile_6.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.y -= 1; + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_T) { + mesh0 = this.tile_6.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.y -= 1; - mesh1 = this.tile_5.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; + mesh1 = this.tile_5.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; - mesh2 = this.tile_4.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; - mesh2.position.x -= 1; + mesh2 = this.tile_4.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; + mesh2.position.x -= 1; - mesh3 = this.tile_2.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.x += 1; + mesh3 = this.tile_2.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.x += 1; - offsetX = 0.5; - offsetY = 1; + offsetX = 0.5; + offsetY = 1; - tinyPositionX = 1.00; - tinyPositionY = 17; + tinyPositionX = 1.00; + tinyPositionY = 17; - nextPositionX = 1.78; - nextPositionY = 16; - } + nextPositionX = 1.78; + nextPositionY = 16; + } - if (blockType === GameLib.CustomCode.TETRIS_BLOCK_O) { - mesh0 = this.tile_3.clone(); - mesh0.position.setFrom(center.position); - mesh0.position.z = -0.1; - mesh0.position.y += 0.5; - mesh0.position.x += 0.5; + if (blockType === GameLib.CustomCode.TETRIS_BLOCK_O) { + mesh0 = this.tile_3.clone(); + mesh0.position.setFrom(center.position); + mesh0.position.z = -0.1; + mesh0.position.y += 0.5; + mesh0.position.x += 0.5; - mesh1 = this.tile_0.clone(); - mesh1.position.setFrom(center.position); - mesh1.position.z = -0.1; - mesh1.position.y += 0.5; - mesh1.position.x -= 0.5; + mesh1 = this.tile_0.clone(); + mesh1.position.setFrom(center.position); + mesh1.position.z = -0.1; + mesh1.position.y += 0.5; + mesh1.position.x -= 0.5; - mesh2 = this.tile_5.clone(); - mesh2.position.setFrom(center.position); - mesh2.position.z = -0.1; - mesh2.position.y -= 0.5; - mesh2.position.x -= 0.5; + mesh2 = this.tile_5.clone(); + mesh2.position.setFrom(center.position); + mesh2.position.z = -0.1; + mesh2.position.y -= 0.5; + mesh2.position.x -= 0.5; - mesh3 = this.tile_2.clone(); - mesh3.position.setFrom(center.position); - mesh3.position.z = -0.1; - mesh3.position.y -= 0.5; - mesh3.position.x += 0.5; + mesh3 = this.tile_2.clone(); + mesh3.position.setFrom(center.position); + mesh3.position.z = -0.1; + mesh3.position.y -= 0.5; + mesh3.position.x += 0.5; - offsetX = 0; - offsetY = 1.5; + offsetX = 0; + offsetY = 1.5; - tinyPositionX = 1.00; - tinyPositionY = 16.85; + tinyPositionX = 1.00; + tinyPositionY = 16.85; - nextPositionX = 1.78; - nextPositionY = 15.65; - } + nextPositionX = 1.78; + nextPositionY = 15.65; + } - mesh0.setParentMesh(center); - mesh1.setParentMesh(center); - mesh2.setParentMesh(center); - mesh3.setParentMesh(center); + mesh0.setParentMesh(center); + mesh1.setParentMesh(center); + mesh2.setParentMesh(center); + mesh3.setParentMesh(center); - center.updateInstance('position'); + center.updateInstance('position'); - mesh0.updateInstance('position'); - mesh1.updateInstance('position'); - mesh2.updateInstance('position'); - mesh3.updateInstance('position'); + mesh0.updateInstance('position'); + mesh1.updateInstance('position'); + mesh2.updateInstance('position'); + mesh3.updateInstance('position'); - var block = { - type: blockType, - offset: { - x: offsetX, - y: offsetY - }, - tinyPosition: { - x: tinyPositionX, - y: tinyPositionY - }, - nextPosition: { - x: nextPositionX, - y: nextPositionY - }, - meshes: [ - mesh0, - mesh1, - mesh2, - mesh3 - ], - angle: center.rotation.z, - center: center - }; + var block = { + type: blockType, + offset: { + x: offsetX, + y: offsetY + }, + tinyPosition: { + x: tinyPositionX, + y: tinyPositionY + }, + nextPosition: { + x: nextPositionX, + y: nextPositionY + }, + meshes: [ + mesh0, + mesh1, + mesh2, + mesh3 + ], + angle: center.rotation.z, + center: center + }; - return block; + return block; }.bind(this) GameLib.CustomCode.prototype.spawnTinyBlock = function () { - var block = this.spawnBlock(); + var block = this.spawnBlock(); - /** - * Set the scale for the blocks - */ - block.center.scale.x = 0.333; - block.center.scale.y = 0.333; - block.center.scale.z = 0.333; - block.center.updateInstance('scale'); + /** + * Set the scale for the blocks + */ + block.center.scale.x = 0.333; + block.center.scale.y = 0.333; + block.center.scale.z = 0.333; + block.center.updateInstance('scale'); - /** - * move tiny block a bit up - then a bit right - */ - block.center.position.x = block.tinyPosition.x; - block.center.position.y = block.tinyPosition.y; - block.center.position.z = 0.4; - block.center.updateInstance('position'); + /** + * move tiny block a bit up - then a bit right + */ + block.center.position.x = block.tinyPosition.x; + block.center.position.y = block.tinyPosition.y; + block.center.position.z = 0.4; + block.center.updateInstance('position'); - return block; + return block; }.bind(this) GameLib.CustomCode.prototype.spawnNextBlock = function () { - if (!this.tinyBlock) { - this.tinyBlock = this.spawnTinyBlock(); - } + if (!this.tinyBlock) { + this.tinyBlock = this.spawnTinyBlock(); + } - var block = this.tinyBlock; + var block = this.tinyBlock; - block.center.scale.x = 0.666; - block.center.scale.y = 0.666; - block.center.scale.z = 0.666; - block.center.updateInstance('scale'); + block.center.scale.x = 0.666; + block.center.scale.y = 0.666; + block.center.scale.z = 0.666; + block.center.updateInstance('scale'); - block.center.position.x = block.nextPosition.x; - block.center.position.y = block.nextPosition.y; - block.center.position.z = 0.4; - block.center.updateInstance('position'); + block.center.position.x = block.nextPosition.x; + block.center.position.y = block.nextPosition.y; + block.center.position.z = 0.4; + block.center.updateInstance('position'); - this.tinyBlock = this.spawnTinyBlock(); + this.tinyBlock = this.spawnTinyBlock(); - return block; + return block; }.bind(this) GameLib.CustomCode.prototype.spawnBigBlock = function () { - if (!this.nextBlock) { - this.nextBlock = this.spawnNextBlock(); - } + if (!this.nextBlock) { + this.nextBlock = this.spawnNextBlock(); + } - var block = this.nextBlock; + var block = this.nextBlock; - block.center.scale.x = 1; - block.center.scale.y = 1; - block.center.scale.z = 1; - block.center.updateInstance('scale'); + block.center.scale.x = 1; + block.center.scale.y = 1; + block.center.scale.z = 1; + block.center.updateInstance('scale'); - block.center.position.x = 0; - block.center.position.y = 0; - block.center.position.z = 0.4; - block.center.updateInstance('position'); + block.center.position.x = 0; + block.center.position.y = 0; + block.center.position.z = 0.4; + block.center.updateInstance('position'); - this.moveBlock(block, {up: true}, (GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE), false); - this.moveBlock(block, {right: true}, GameLib.CustomCode.TETRIS_GRID_WIDTH / 2, false); - this.moveBlock(block, {left: true}, block.offset.x, false); - this.moveBlock(block, {down: true}, block.offset.y, false); + this.moveBlock(block, {up: true}, (GameLib.CustomCode.TETRIS_GRID_HEIGHT - GameLib.CustomCode.TETRIS_GRID_HEADSPACE), false); + this.moveBlock(block, {right: true}, GameLib.CustomCode.TETRIS_GRID_WIDTH / 2, false); + this.moveBlock(block, {left: true}, block.offset.x, false); + this.moveBlock(block, {down: true}, block.offset.y, false); - this.nextBlock = this.spawnNextBlock(); + this.nextBlock = this.spawnNextBlock(); - return block; + return block; }.bind(this) GameLib.CustomCode.prototype.getNextBlock = function () { - this.stopAnimations(); + this.stopAnimations(); - this.beforeRender.block = this.spawnBigBlock(); + this.ccBeforeRender.block = this.spawnBigBlock(); - this.block = this.beforeRender.block; + this.block = this.ccBeforeRender.block; - GameLib.Event.Emit( - GameLib.Event.COMPONENT_REGISTER, - { - component: this.block.center - } - ); + GameLib.Event.Emit( + GameLib.Event.COMPONENT_REGISTER, + { + component: this.block.center + } + ); - this.startAnimations(); + this.startAnimations(); - this.animation.addMesh(this.block.center); + this.animation.addMesh(this.block.center); }.bind(this); if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) { - this.subscriptions = []; + this.subscriptions = []; - this.subscriptions.push( - new GameLib.Event.Subscribe( - GameLib.Event.CUSTOM_GAME_START, + this.subscriptions.push( + new GameLib.Event.Subscribe( + GameLib.Event.CUSTOM_GAME_START, - function () { + function () { - this.animationObjects = []; + this.animationObjects = []; - this.baconMaterials = []; + this.baconMaterials = []; - GameLib.Event.Subscribe( - GameLib.Event.WINDOW_RESIZE, - function (data) { - var aspect = data.width / data.height; - this.camera.offsetX = -((this.camera.maxX - this.camera.minX) / 2) + (GameLib.CustomCode.TETRIS_GRID_WIDTH / 2) - 0.5 - (0.5 * aspect); - this.camera.updateInstance('offsetX'); - }.bind(this) - ) + GameLib.Event.Subscribe( + GameLib.Event.WINDOW_RESIZE, + function (data) { + var aspect = data.width / data.height; + this.camera.offsetX = -((this.camera.maxX - this.camera.minX) / 2) + (GameLib.CustomCode.TETRIS_GRID_WIDTH / 2) - 0.5 - (0.5 * aspect); + this.camera.updateInstance('offsetX'); + }.bind(this) + ) - GameLib.Event.Emit( - GameLib.Event.WINDOW_RESIZE, - { - width: window.innerWidth, - height: window.innerHeight - } - ); + GameLib.Event.Emit( + GameLib.Event.WINDOW_RESIZE, + { + width: window.innerWidth, + height: window.innerHeight + } + ); - this.score = 0; - this.level = 1; - this.rows = 0; - this.speed = 1; + this.score = 0; + this.level = 1; + this.rows = 0; + this.speed = 1; - this.drawGrid(); + this.drawGrid(); - this.drawStatus(); + this.drawStatus(); - /** - * Set the game parameters - */ - this.beforeRender.entityLoaded = null; - this.beforeRender.initialized = false; + /** + * Set the game parameters + */ + this.ccBeforeRender.entityLoaded = null; + this.ccBeforeRender.initialized = false; - /** - * Link the classes - */ - this.beforeRender.entityLoaded = this; - this.keyDown.entityLoaded = this; - this.touchEnd.entityLoaded = this; - this.touchStart.entityLoaded = this; + /** + * Link the classes + */ + this.ccBeforeRender.entityLoaded = this; + this.ccKeyDown.entityLoaded = this; + this.ccTouchStart.entityLoaded = this; + this.ccTouchEnd.entityLoaded = this; - console.log('custom game start complete'); - }.bind(this) - ) - ); + console.log('custom game start complete'); + + }.bind(this) + ) + ); } GameLib.CustomCode.prototype.createTile = function(tileName, imageName) { - this[tileName] = new GameLib.D3.Mesh( - this.graphics, - new GameLib.D3.API.Mesh( - null, - null, - null, - this.parentEntity, - new GameLib.D3.API.Geometry.Buffer.Plane(), - [ - new GameLib.D3.API.Material.Phong( - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - new GameLib.D3.API.Texture.Image( - null, - this[imageName] - ) - ) - ] - ) - ) + this[tileName] = new GameLib.D3.Mesh( + this.graphics, + new GameLib.D3.API.Mesh( + null, + null, + null, + this.parentEntity, + new GameLib.D3.API.Geometry.Buffer.Plane(), + [ + new GameLib.D3.API.Material.Phong( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + new GameLib.D3.API.Texture.Image( + null, + this[imageName] + ) + ) + ] + ) + ) }.bind(this); GameLib.Event.Emit( - GameLib.Event.GET_RUNTIME, - {}, - function(runtime) { + GameLib.Event.GET_RUNTIME, + {}, + function(runtime) { - this.graphics = runtime.graphics; + this.graphics = runtime.graphics; - this.createTile('tile_0', 'image_0'); - this.createTile('tile_1', 'image_1'); - this.createTile('tile_2', 'image_2'); - this.createTile('tile_3', 'image_3'); - this.createTile('tile_4', 'image_4'); - this.createTile('tile_5', 'image_5'); - this.createTile('tile_6', 'image_6'); + this.createTile('tile_0', 'image_0'); + this.createTile('tile_1', 'image_1'); + this.createTile('tile_2', 'image_2'); + this.createTile('tile_3', 'image_3'); + this.createTile('tile_4', 'image_4'); + this.createTile('tile_5', 'image_5'); + this.createTile('tile_6', 'image_6'); - GameLib.Event.Emit(GameLib.Event.GAME_LOADED); + GameLib.Event.Emit(GameLib.Event.GAME_LOADED); - }.bind(this) + }.bind(this) ) - - - //@ sourceURL=entityLoaded.js \ No newline at end of file