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

beta.r3js.org
-=yb4f310 2018-02-13 10:35:25 +01:00
parent b8ac1df997
commit 97386ee4fd
1 changed files with 1027 additions and 1024 deletions

View File

@ -2,12 +2,17 @@ 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'); * Custom Code Components
this.keyDown = GameLib.EntityManager.Instance.findComponentById('dgscoensvf'); */
this.touchStart = GameLib.EntityManager.Instance.findComponentById('xjaoh824ff'); this.ccBeforeRender = GameLib.EntityManager.Instance.findComponentById('o4c478xpx3');
this.touchEnd = GameLib.EntityManager.Instance.findComponentById('ohqwmnjfgf'); 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_0 = GameLib.EntityManager.Instance.findComponentById('gvrik6h4yd');
this.image_1 = GameLib.EntityManager.Instance.findComponentById('ssdlmrpv9j'); this.image_1 = GameLib.EntityManager.Instance.findComponentById('ssdlmrpv9j');
this.image_2 = GameLib.EntityManager.Instance.findComponentById('zdg2qpu35c'); this.image_2 = GameLib.EntityManager.Instance.findComponentById('zdg2qpu35c');
@ -56,9 +61,9 @@ GameLib.CustomCode.prototype.visualizeGrid = function (color) {
this.starsGeometry = new THREE.Geometry(); this.starsGeometry = new THREE.Geometry();
for (var y = 0; y < this.beforeRender.grid.length; y++) { for (var y = 0; y < this.ccBeforeRender.grid.length; y++) {
for (var x = 0; x < this.beforeRender.grid[y].length; x++) { for (var x = 0; x < this.ccBeforeRender.grid[y].length; x++) {
if (this.beforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { if (this.ccBeforeRender.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,
@ -88,10 +93,10 @@ GameLib.CustomCode.prototype.startAnimation = function (index) {
bacon.position.z = 0.2; bacon.position.z = 0.2;
bacon.updateInstance('position'); bacon.updateInstance('position');
this.beforeRender.grid[index][x].baconDisappearing = bacon; this.ccBeforeRender.grid[index][x].baconDisappearing = bacon;
this.baconMaterials.push( this.baconMaterials.push(
this.beforeRender.grid[index][x].mesh.materials[0] this.ccBeforeRender.grid[index][x].mesh.materials[0]
); );
} }
@ -183,21 +188,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.beforeRender.grid[__animationObject.rowNumber][x].mesh) { if (!this.ccBeforeRender.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.beforeRender.grid[__animationObject.rowNumber][x].mesh component: this.ccBeforeRender.grid[__animationObject.rowNumber][x].mesh
} }
); );
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT, GameLib.Event.REMOVE_COMPONENT,
{ {
component: this.beforeRender.grid[__animationObject.rowNumber][x].baconDisappearing component: this.ccBeforeRender.grid[__animationObject.rowNumber][x].baconDisappearing
} }
); );
@ -206,7 +211,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.beforeRender.grid.splice(__animationObject.rowNumber, 1); this.ccBeforeRender.grid.splice(__animationObject.rowNumber, 1);
var row = []; var row = [];
@ -219,7 +224,7 @@ GameLib.CustomCode.prototype.startAnimation = function (index) {
) )
} }
this.beforeRender.grid.push(row); this.ccBeforeRender.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
@ -227,14 +232,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.beforeRender.grid[y][x].mesh) { if (this.ccBeforeRender.grid[y][x].mesh) {
this.beforeRender.grid[y][x].mesh.position.y = y; this.ccBeforeRender.grid[y][x].mesh.position.y = y;
this.beforeRender.grid[y][x].mesh.updateInstance('position'); this.ccBeforeRender.grid[y][x].mesh.updateInstance('position');
} }
if (this.beforeRender.grid[y][x].baconDisappearing) { if (this.ccBeforeRender.grid[y][x].baconDisappearing) {
this.beforeRender.grid[y][x].baconDisappearing.position.y = y; this.ccBeforeRender.grid[y][x].baconDisappearing.position.y = y;
this.beforeRender.grid[y][x].baconDisappearing.updateInstance('position'); this.ccBeforeRender.grid[y][x].baconDisappearing.updateInstance('position');
} }
} }
} }
@ -291,8 +296,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.beforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN || this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_NOT_TAKEN ||
this.beforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING this.ccBeforeRender.grid[y][x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING
) { ) {
line = false; line = false;
} }
@ -402,7 +407,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.beforeRender.grid[index][x].value = GameLib.CustomCode.TETRIS_GRID_DISAPPEARING; this.ccBeforeRender.grid[index][x].value = GameLib.CustomCode.TETRIS_GRID_DISAPPEARING;
} }
this.startAnimation(index); this.startAnimation(index);
}.bind(this) }.bind(this)
@ -684,7 +689,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.beforeRender.grid[position.y][position.x + 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { 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 * Ok - we found a block to the right - its over
*/ */
@ -707,7 +712,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.beforeRender.grid[position.y][position.x - 1].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { 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 * We found a block to the left - its over also
*/ */
@ -728,7 +733,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.beforeRender.grid[position.y + 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { if (this.ccBeforeRender.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
*/ */
@ -749,14 +754,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.beforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { if (this.ccBeforeRender.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.beforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING) { if (this.ccBeforeRender.grid[position.y - 1][position.x].value === GameLib.CustomCode.TETRIS_GRID_DISAPPEARING) {
bottomDisappearing = true; bottomDisappearing = true;
} }
} }
@ -770,7 +775,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.beforeRender.grid[position.y][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) { if (this.ccBeforeRender.grid[position.y][position.x].value === GameLib.CustomCode.TETRIS_GRID_TAKEN) {
collision = true; collision = true;
} }
} }
@ -790,7 +795,7 @@ GameLib.CustomCode.prototype.checkBoundaries = function (block) {
GameLib.CustomCode.prototype.rotateBlock = function (clockwise) { GameLib.CustomCode.prototype.rotateBlock = function (clockwise) {
if (this.beforeRender.gameOver) { if (this.ccBeforeRender.gameOver) {
return; return;
} }
@ -1264,9 +1269,9 @@ 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.Emit(
GameLib.Event.COMPONENT_REGISTER, GameLib.Event.COMPONENT_REGISTER,
@ -1324,16 +1329,17 @@ if (GameLib.Utils.UndefinedOrNull(this.subscriptions)) {
/** /**
* Set the game parameters * Set the game parameters
*/ */
this.beforeRender.entityLoaded = null; this.ccBeforeRender.entityLoaded = null;
this.beforeRender.initialized = false; this.ccBeforeRender.initialized = false;
/** /**
* Link the classes * Link the classes
*/ */
this.beforeRender.entityLoaded = this; this.ccBeforeRender.entityLoaded = this;
this.keyDown.entityLoaded = this; this.ccKeyDown.entityLoaded = this;
this.touchEnd.entityLoaded = this; this.ccTouchStart.entityLoaded = this;
this.touchStart.entityLoaded = this; this.ccTouchEnd.entityLoaded = this;
console.log('custom game start complete'); console.log('custom game start complete');
@ -1399,7 +1405,4 @@ GameLib.Event.Emit(
}.bind(this) }.bind(this)
) )
//@ sourceURL=entityLoaded.js //@ sourceURL=entityLoaded.js