Update: CC - Bacon - Entity Loaded (2xswm1bwq8.js) 194 bytes modified

beta.r3js.org
-=yb4f310 2018-02-18 16:39:23 +01:00
parent e49a84b478
commit 3bce4a9146
1 changed files with 50 additions and 34 deletions

View File

@ -1436,41 +1436,49 @@ GameLib.CustomCode.prototype.stopBlock = function() {
/** /**
* If there already is a mesh - remove it - * If there already is a mesh - remove it -
*/ */
if (this.grid[position.y][position.x].mesh) { var block = this.grid[position.y][position.x];
this.scene.removeObject(this.grid[position.y][position.x].mesh);
if (block.mesh) {
this.scene.removeObject(block.mesh);
}
if (block.baconDisappearing) {
this.scene.removeObject(block.baconDisappearing);
} }
this.grid[position.y][position.x] = { block = {
value: GameLib.CustomCode.TETRIS_GRID_TAKEN, value : GameLib.CustomCode.TETRIS_GRID_TAKEN,
mesh: position.mesh mesh : position.mesh,
}; baconDisappearing : null
}
this.grid[position.y][position.x] = block;
}.bind(this) }.bind(this)
); );
this.block.center.instance.position.x = this.block.center.position.x; /**
this.block.center.instance.position.y = this.block.center.position.y; * We apply our current rotation and position to the instance
this.block.center.instance.position.z = this.block.center.position.z; */
this.block.center.updateInstance('position');
this.block.center.instance.rotation.x = this.block.center.rotation.x; this.block.center.updateInstance('rotation');
this.block.center.instance.rotation.y = this.block.center.rotation.y;
this.block.center.instance.rotation.z = this.block.center.rotation.z;
this.block.center.instance.updateMatrixWorld();
/**
* Now we unlink the meshes from the controlling center block
*/
this.block.meshes.map( this.block.meshes.map(
function (mesh) { function (mesh) {
mesh.setParentMesh(null); mesh.setParentMesh(null);
mesh.position.z = 2.5; mesh.position.z = 2.5;
mesh.updateInstancePosition(); mesh.updateInstance('position');
}.bind(this) }.bind(this)
); );
this.animation.removeMesh(this.block.center); /**
* We remove the controlling block
*/
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT, GameLib.Event.REMOVE_COMPONENT,
{ {
@ -1478,10 +1486,16 @@ GameLib.CustomCode.prototype.stopBlock = function() {
} }
); );
/**
* We remove any lines
*/
this.removeLines(); this.removeLines();
this.visualizeGrid(0xff0000); this.visualizeGrid(0xff0000);
/**
* Check if the game is over
*/
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) { for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
if ( if (
this.grid[19][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN || this.grid[19][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN ||
@ -1495,15 +1509,10 @@ GameLib.CustomCode.prototype.stopBlock = function() {
} }
if (this.gameOver) { if (this.gameOver) {
this.endGame();
} else {
this.getNextBlock();
}
}.bind(this);
GameLib.CustomCode.prototype.endGame = function() {
/**
* End the game if game over
*/
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.GAME_OVER, GameLib.Event.GAME_OVER,
{ {
@ -1513,8 +1522,15 @@ GameLib.CustomCode.prototype.endGame = function() {
} }
); );
}.bind(this) } else {
/**
* Otherwise continue
*/
this.getNextBlock();
}
}.bind(this);
/** /**
* Clears the grid * Clears the grid