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

beta.r3js.org
-=yb4f310 2018-02-18 12:07:12 +01:00
parent a8ab040488
commit 3058e99089
1 changed files with 175 additions and 1 deletions

View File

@ -1190,7 +1190,7 @@ GameLib.CustomCode.prototype.spawnBlock = function () {
mesh2.updateInstance('visible');
mesh3.visible = true;
mesh3.updateInstance('visible');
mesh0.setParentMesh(center);
mesh1.setParentMesh(center);
mesh2.setParentMesh(center);
@ -1345,8 +1345,43 @@ if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) {
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)
);
}
/**
* Set the game parameters
*/
@ -1362,6 +1397,8 @@ if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) {
this.ccTouchEnd.entityLoaded = this;
this.getNextBlock();
console.log('custom game start complete');
}.bind(this)
@ -1369,6 +1406,143 @@ if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) {
);
}
/**
* This code executes when the 'bottom' has been reached (the block is stopping)
*/
GameLib.CustomCode.prototype.bottomReached = function() {
var gridPositions = this.getBlockGridPositions(this.block);
gridPositions.map(
function (position) {
/**
* If there already is a mesh - remove it -
*/
if (this.grid[position.y][position.x].mesh) {
this.scene.removeObject(this.grid[position.y][position.x].mesh);
}
this.grid[position.y][position.x] = {
value: GameLib.CustomCode.TETRIS_GRID_TAKEN,
mesh: position.mesh
};
}.bind(this)
);
this.block.center.instance.position.x = this.block.center.position.x;
this.block.center.instance.position.y = this.block.center.position.y;
this.block.center.instance.position.z = this.block.center.position.z;
this.block.center.instance.rotation.x = this.block.center.rotation.x;
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();
this.block.meshes.map(
function (mesh) {
mesh.setParentMesh(null);
//mesh.position.z = 0.1;
mesh.updateInstancePosition();
}.bind(this)
);
this.animation.removeMesh(this.block.center);
GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT,
{
component: this.block.center
}
);
this.removeLines();
//this.visualizeGrid(0xff0000);
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
if (
this.grid[19][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN ||
this.grid[20][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN ||
this.grid[21][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN ||
this.grid[22][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN ||
this.grid[23][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN
) {
this.gameOver = true;
}
}
if (this.gameOver) {
this.block.meshes.map(
function (mesh) {
this.scene.removeObject(mesh);
}.bind(this)
);
delete this.block;
GameLib.Event.Emit(
GameLib.Event.GAME_OVER,
{
score: this.entityLoaded.score,
level: this.entityLoaded.level,
rows: this.entityLoaded.rows
}
);
//this.visualizeGrid(0xff0000);
} else {
this.getNextBlock();
}
}.bind(this);
/**
* Clears the grid
*/
GameLib.CustomCode.prototype.clearGrid = function() {
/**
* Remove all stale components (if any)
*/
if (this.grid instanceof Array) {
this.grid.map(
function(y) {
if (this.grid[y] instanceof Array) {
this.grid[y].map(
function(x){
if (this.grid[y][x].mesh) {
this.scene.removeObject(this.grid[y][x].mesh);
}
if (this.grid[y][x].baconDisappearing) {
this.scene.removeObject(this.grid[y][x].baconDisappearing);
}
}.bind(this)
)
}
}.bind(this)
)
}
/**
* Initialize the grid
*/
this.grid = [];
for (var y = 0; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT; y++) {
this.grid[y] = [];
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
this.grid[y][x] = {
value: GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN,
mesh: null
};
}
}
}.bind(this)
GameLib.CustomCode.prototype.createTile = function(tileName, imageName) {
var apiMaterial;