diff --git a/2xswm1bwq8.js b/2xswm1bwq8.js index 4395c66..d55ca9e 100644 --- a/2xswm1bwq8.js +++ b/2xswm1bwq8.js @@ -43,7 +43,6 @@ this.scoreTexture = GameLib.EntityManager.Instance.findComponentById('kva68t4dm8 * Animations */ this.animation = GameLib.EntityManager.Instance.findComponentById('tnlwgvf12x'); -//this.animationSystem = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SYSTEM_ANIMATION)[0]; /** * Lights @@ -126,11 +125,11 @@ GameLib.CustomCode.prototype.startAnimation = function (index) { bacon.position.x = x; bacon.position.y = index; - bacon.position.z = 3; + bacon.position.z = 2; bacon.updateInstance('position'); this.grid[index][x].baconDisappearing = bacon; - + this.baconMaterials.push( this.grid[index][x].mesh.materials[0] ); @@ -1310,8 +1309,6 @@ GameLib.CustomCode.prototype.spawnBigBlock = function () { GameLib.CustomCode.prototype.getNextBlock = function () { -// this.animationSystem.stop(); - this.block = this.spawnBigBlock(); GameLib.Event.Emit( @@ -1321,97 +1318,10 @@ GameLib.CustomCode.prototype.getNextBlock = function () { } ); -// this.animationSystem.start(); - this.animation.meshes.push(this.block.center); }.bind(this); - -if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) { - - this.subscriptions = []; - - this.subscriptions.push( - new GameLib.Event.Subscribe( - GameLib.Event.CUSTOM_GAME_START, - - function () { - - this.animationObjects = []; - - this.baconMaterials = []; - - this.score = 0; - this.level = 1; - this.rows = 0; - this.speed = 1; - - /** - * Draw our new status - */ - this.drawStatus(); - - /** - * Ensure the grid is cleared - */ - this.clearGrid(); - - - if (this.block && this.block.center) { - - //this.animation.removeMesh(this.block.center); - - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: this.block.center - } - ); - } - - if (this.block && this.block.meshes) { - this.block.meshes.map( - function (mesh) { - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component: mesh - } - ); - }.bind(this) - ); - } - - - this.getNextBlock(); - - /** - * Set the game parameters - */ - this.ccBeforeRender.entityLoaded = null; - this.ccBeforeRender.initialized = false; - - /** - * Link the classes - */ - this.ccBeforeRender.entityLoaded = this; - this.ccKeyDown.entityLoaded = this; - this.ccTouchStart.entityLoaded = this; - this.ccTouchEnd.entityLoaded = this; - - /** - * Allow the game to proceed - * @type {boolean} - */ - this.gameOver = false; - - console.log('game start complete'); - - }.bind(this) - ) - ); -} - + /** * This code executes when the 'bottom' has been reached (the block is stopping) */ @@ -1452,7 +1362,7 @@ GameLib.CustomCode.prototype.stopBlock = function() { */ this.block.center.updateInstance('position'); this.block.center.updateInstance('rotation'); - + /** * Now we unlink the meshes from the controlling center block */ @@ -1483,7 +1393,7 @@ GameLib.CustomCode.prototype.stopBlock = function() { */ this.removeLines(); - this.visualizeGrid(0xff0000); + //this.visualizeGrid(0xff0000); /** * Check if the game is over @@ -1566,34 +1476,60 @@ GameLib.CustomCode.prototype.clearGrid = function() { }.bind(this) -GameLib.CustomCode.prototype.createTile = function(tileName, imageName) { +GameLib.CustomCode.prototype.createTile = function(tileName, imageName, displace) { var apiMaterial; if (imageName) { - apiMaterial = 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( + if (displace) { + apiMaterial = new GameLib.D3.API.Material.Phong( null, - this[imageName] + null, + null, + null, + null, + null, + null, + null, + this.textureDisplacement, + null, + null, + null, + null, + null, + null, + null, + null, + new GameLib.D3.API.Texture.Image( + null, + this[imageName] + ) ) - ) + } else { + apiMaterial = 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] + ) + ) + } } else { apiMaterial = new GameLib.D3.API.Material.Phong(); } @@ -1624,6 +1560,82 @@ GameLib.CustomCode.prototype.createTile = function(tileName, imageName) { }.bind(this); +GameLib.Event.Subscribe( + GameLib.Event.CUSTOM_GAME_START, + + function () { + + this.animationObjects = []; + + this.baconMaterials = []; + + this.score = 0; + this.level = 1; + this.rows = 0; + this.speed = 1; + + /** + * Draw our new status + */ + this.drawStatus(); + + /** + * Ensure the grid is cleared + */ + this.clearGrid(); + + + if (this.block && this.block.center) { + + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: this.block.center + } + ); + } + + if (this.block && this.block.meshes) { + this.block.meshes.map( + function (mesh) { + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component: mesh + } + ); + }.bind(this) + ); + } + + + this.getNextBlock(); + + /** + * Set the game parameters + */ + this.ccBeforeRender.entityLoaded = null; + this.ccBeforeRender.initialized = false; + + /** + * Link the classes + */ + this.ccBeforeRender.entityLoaded = this; + this.ccKeyDown.entityLoaded = this; + this.ccTouchStart.entityLoaded = this; + this.ccTouchEnd.entityLoaded = this; + + /** + * Allow the game to proceed + * @type {boolean} + */ + this.gameOver = false; + + console.log('game start complete'); + + }.bind(this) +); + GameLib.Event.Emit( GameLib.Event.GET_RUNTIME, {}, @@ -1631,13 +1643,13 @@ GameLib.Event.Emit( 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', true); + this.createTile('tile_1', 'image_1', true); + this.createTile('tile_2', 'image_2', true); + this.createTile('tile_3', 'image_3', true); + this.createTile('tile_4', 'image_4', true); + this.createTile('tile_5', 'image_5', true); + this.createTile('tile_6', 'image_6', true); this.createTile('tile_flames_small', 'image_flames_small');