Update: CC - Bacon - Entity Loaded (2xswm1bwq8.js) 147 bytes modified
parent
3058e99089
commit
794c2a678b
|
@ -59,6 +59,10 @@ this.level = 1;
|
||||||
this.rows = 0;
|
this.rows = 0;
|
||||||
this.speed = 1;
|
this.speed = 1;
|
||||||
|
|
||||||
|
this.grid = [];
|
||||||
|
|
||||||
|
this.gameOver = false;
|
||||||
|
|
||||||
GameLib.CustomCode.TETRIS_BLOCK_I = 0;
|
GameLib.CustomCode.TETRIS_BLOCK_I = 0;
|
||||||
GameLib.CustomCode.TETRIS_BLOCK_L = 1;
|
GameLib.CustomCode.TETRIS_BLOCK_L = 1;
|
||||||
GameLib.CustomCode.TETRIS_BLOCK_L2 = 2;
|
GameLib.CustomCode.TETRIS_BLOCK_L2 = 2;
|
||||||
|
@ -84,9 +88,9 @@ GameLib.CustomCode.prototype.visualizeGrid = function (color) {
|
||||||
|
|
||||||
this.starsGeometry = new THREE.Geometry();
|
this.starsGeometry = new THREE.Geometry();
|
||||||
|
|
||||||
for (var y = 0; y < this.ccBeforeRender.grid.length; y++) {
|
for (var y = 0; y < this.grid.length; y++) {
|
||||||
for (var x = 0; x < this.ccBeforeRender.grid[y].length; x++) {
|
for (var x = 0; x < this.grid[y].length; x++) {
|
||||||
if (this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
if (this.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
||||||
this.starsGeometry.vertices.push(
|
this.starsGeometry.vertices.push(
|
||||||
new THREE.Vector3(
|
new THREE.Vector3(
|
||||||
x,
|
x,
|
||||||
|
@ -120,10 +124,10 @@ GameLib.CustomCode.prototype.startAnimation = function (index) {
|
||||||
bacon.position.z = 3;
|
bacon.position.z = 3;
|
||||||
bacon.updateInstance('position');
|
bacon.updateInstance('position');
|
||||||
|
|
||||||
this.ccBeforeRender.grid[index][x].baconDisappearing = bacon;
|
this.grid[index][x].baconDisappearing = bacon;
|
||||||
|
|
||||||
this.baconMaterials.push(
|
this.baconMaterials.push(
|
||||||
this.ccBeforeRender.grid[index][x].mesh.materials[0]
|
this.grid[index][x].mesh.materials[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,21 +225,21 @@ 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++) {
|
||||||
|
|
||||||
if (!this.ccBeforeRender.grid[__animationObject.rowNumber][x].mesh) {
|
if (!this.grid[__animationObject.rowNumber][x].mesh) {
|
||||||
throw new Error('mesh should exist but does not');
|
throw new Error('mesh should exist but does not');
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.REMOVE_COMPONENT,
|
GameLib.Event.REMOVE_COMPONENT,
|
||||||
{
|
{
|
||||||
component: this.ccBeforeRender.grid[__animationObject.rowNumber][x].mesh
|
component: this.grid[__animationObject.rowNumber][x].mesh
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.REMOVE_COMPONENT,
|
GameLib.Event.REMOVE_COMPONENT,
|
||||||
{
|
{
|
||||||
component: this.ccBeforeRender.grid[__animationObject.rowNumber][x].baconDisappearing
|
component: this.grid[__animationObject.rowNumber][x].baconDisappearing
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -244,7 +248,7 @@ GameLib.CustomCode.prototype.startAnimation = function (index) {
|
||||||
/**
|
/**
|
||||||
* Add a new row to the top of the grid
|
* Add a new row to the top of the grid
|
||||||
*/
|
*/
|
||||||
this.ccBeforeRender.grid.splice(__animationObject.rowNumber, 1);
|
this.grid.splice(__animationObject.rowNumber, 1);
|
||||||
|
|
||||||
var row = [];
|
var row = [];
|
||||||
|
|
||||||
|
@ -257,7 +261,7 @@ GameLib.CustomCode.prototype.startAnimation = function (index) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ccBeforeRender.grid.push(row);
|
this.grid.push(row);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now - drop all blocks above the current index down one row
|
* Now - drop all blocks above the current index down one row
|
||||||
|
@ -265,14 +269,14 @@ GameLib.CustomCode.prototype.startAnimation = function (index) {
|
||||||
for (var y = __animationObject.rowNumber; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT - 1; y++) {
|
for (var y = __animationObject.rowNumber; y < GameLib.CustomCode.TETRIS_GRID_HEIGHT - 1; y++) {
|
||||||
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
|
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
|
||||||
|
|
||||||
if (this.ccBeforeRender.grid[y][x].mesh) {
|
if (this.grid[y][x].mesh) {
|
||||||
this.ccBeforeRender.grid[y][x].mesh.position.y = y;
|
this.grid[y][x].mesh.position.y = y;
|
||||||
this.ccBeforeRender.grid[y][x].mesh.updateInstance('position');
|
this.grid[y][x].mesh.updateInstance('position');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.ccBeforeRender.grid[y][x].baconDisappearing) {
|
if (this.grid[y][x].baconDisappearing) {
|
||||||
this.ccBeforeRender.grid[y][x].baconDisappearing.position.y = y;
|
this.grid[y][x].baconDisappearing.position.y = y;
|
||||||
this.ccBeforeRender.grid[y][x].baconDisappearing.updateInstance('position');
|
this.grid[y][x].baconDisappearing.updateInstance('position');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,8 +333,8 @@ GameLib.CustomCode.prototype.removeLines = function () {
|
||||||
|
|
||||||
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.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN ||
|
this.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN ||
|
||||||
this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING
|
this.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING
|
||||||
) {
|
) {
|
||||||
line = false;
|
line = false;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +444,7 @@ GameLib.CustomCode.prototype.removeLines = function () {
|
||||||
indices.map(
|
indices.map(
|
||||||
function (index) {
|
function (index) {
|
||||||
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
|
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
|
||||||
this.ccBeforeRender.grid[index][x].value = GameLib.CustomCode.TETRIS_GRID_DISAPPEARING;
|
this.grid[index][x].value = GameLib.CustomCode.TETRIS_GRID_DISAPPEARING;
|
||||||
}
|
}
|
||||||
this.startAnimation(index);
|
this.startAnimation(index);
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
@ -717,7 +721,7 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
|
||||||
* But we cannot be sure y is inside bounds
|
* But we cannot be sure y is inside bounds
|
||||||
*/
|
*/
|
||||||
if (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) {
|
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) {
|
if (this.grid[position.y][position.x + 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
||||||
/**
|
/**
|
||||||
* Ok - we found a block to the right - its over
|
* Ok - we found a block to the right - its over
|
||||||
*/
|
*/
|
||||||
|
@ -740,7 +744,7 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
|
||||||
* But we cannot be sure y is inside bounds
|
* But we cannot be sure y is inside bounds
|
||||||
*/
|
*/
|
||||||
if (position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 0) {
|
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) {
|
if (this.grid[position.y][position.x - 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
||||||
/**
|
/**
|
||||||
* We found a block to the left - its over also
|
* We found a block to the left - its over also
|
||||||
*/
|
*/
|
||||||
|
@ -761,7 +765,7 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
|
||||||
*/
|
*/
|
||||||
if (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) {
|
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) {
|
if (this.grid[position.y + 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
||||||
/**
|
/**
|
||||||
* Ok - this block is at the top
|
* Ok - this block is at the top
|
||||||
*/
|
*/
|
||||||
|
@ -782,14 +786,14 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
|
||||||
* We cannot be sure, position.x is inside bounds
|
* We cannot be sure, position.x is inside bounds
|
||||||
*/
|
*/
|
||||||
if (position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) {
|
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) {
|
if (this.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
||||||
/**
|
/**
|
||||||
* Ok - this block hit bottom
|
* Ok - this block hit bottom
|
||||||
*/
|
*/
|
||||||
bottomHit = true;
|
bottomHit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.ccBeforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING) {
|
if (this.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING) {
|
||||||
bottomDisappearing = true;
|
bottomDisappearing = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -803,7 +807,7 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
|
||||||
(position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) &&
|
(position.x < GameLib.CustomCode.TETRIS_GRID_WIDTH && position.x >= 0) &&
|
||||||
(position.y < GameLib.CustomCode.TETRIS_GRID_HEIGHT && position.y >= 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) {
|
if (this.grid[position.y][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
|
||||||
collision = true;
|
collision = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -823,7 +827,7 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.rotateBlock = function (clockwise) {
|
GameLib.CustomCode.prototype.rotateBlock = function (clockwise) {
|
||||||
|
|
||||||
if (this.ccBeforeRender.gameOver) {
|
if (this.gameOver) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,6 +868,10 @@ GameLib.CustomCode.prototype.rotateBlock = function (clockwise) {
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.moveBlock = function (block, direction, units, collisionCheck) {
|
GameLib.CustomCode.prototype.moveBlock = function (block, direction, units, collisionCheck) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(block)) {
|
||||||
|
block = this.block;
|
||||||
|
}
|
||||||
|
|
||||||
if (!units) {
|
if (!units) {
|
||||||
units = 1;
|
units = 1;
|
||||||
}
|
}
|
||||||
|
@ -1309,9 +1317,9 @@ GameLib.CustomCode.prototype.getNextBlock = function () {
|
||||||
|
|
||||||
this.stopAnimations();
|
this.stopAnimations();
|
||||||
|
|
||||||
this.ccBeforeRender.block = this.spawnBigBlock();
|
this.block = this.spawnBigBlock();
|
||||||
|
|
||||||
this.block = this.ccBeforeRender.block;
|
this.block = this.block;
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.COMPONENT_REGISTER,
|
GameLib.Event.COMPONENT_REGISTER,
|
||||||
|
@ -1382,6 +1390,8 @@ if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.getNextBlock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the game parameters
|
* Set the game parameters
|
||||||
*/
|
*/
|
||||||
|
@ -1396,10 +1406,13 @@ if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) {
|
||||||
this.ccTouchStart.entityLoaded = this;
|
this.ccTouchStart.entityLoaded = this;
|
||||||
this.ccTouchEnd.entityLoaded = this;
|
this.ccTouchEnd.entityLoaded = this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow the game to proceed
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.gameOver = false;
|
||||||
|
|
||||||
this.getNextBlock();
|
console.log('game start complete');
|
||||||
|
|
||||||
console.log('custom game start complete');
|
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
|
@ -1414,6 +1427,7 @@ GameLib.CustomCode.prototype.bottomReached = function() {
|
||||||
var gridPositions = this.getBlockGridPositions(this.block);
|
var gridPositions = this.getBlockGridPositions(this.block);
|
||||||
|
|
||||||
gridPositions.map(
|
gridPositions.map(
|
||||||
|
|
||||||
function (position) {
|
function (position) {
|
||||||
/**
|
/**
|
||||||
* If there already is a mesh - remove it -
|
* If there already is a mesh - remove it -
|
||||||
|
@ -1427,6 +1441,7 @@ GameLib.CustomCode.prototype.bottomReached = function() {
|
||||||
mesh: position.mesh
|
mesh: position.mesh
|
||||||
};
|
};
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.block.center.instance.position.x = this.block.center.position.x;
|
this.block.center.instance.position.x = this.block.center.position.x;
|
||||||
|
@ -1460,7 +1475,7 @@ GameLib.CustomCode.prototype.bottomReached = function() {
|
||||||
|
|
||||||
this.removeLines();
|
this.removeLines();
|
||||||
|
|
||||||
//this.visualizeGrid(0xff0000);
|
this.visualizeGrid(0xff0000);
|
||||||
|
|
||||||
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
|
for (var x = 0; x < GameLib.CustomCode.TETRIS_GRID_WIDTH; x++) {
|
||||||
if (
|
if (
|
||||||
|
@ -1475,6 +1490,14 @@ GameLib.CustomCode.prototype.bottomReached = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.gameOver) {
|
if (this.gameOver) {
|
||||||
|
this.endGame();
|
||||||
|
} else {
|
||||||
|
this.getNextBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
GameLib.CustomCode.prototype.endGame = function() {
|
||||||
|
|
||||||
this.block.meshes.map(
|
this.block.meshes.map(
|
||||||
function (mesh) {
|
function (mesh) {
|
||||||
|
@ -1493,12 +1516,8 @@ GameLib.CustomCode.prototype.bottomReached = function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//this.visualizeGrid(0xff0000);
|
}.bind(this)
|
||||||
|
|
||||||
} else {
|
|
||||||
this.getNextBlock();
|
|
||||||
}
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the grid
|
* Clears the grid
|
||||||
|
|
Loading…
Reference in New Issue