From 18e4855e3aee712ec4e7e49dfb15274112f2170a Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Fri, 25 May 2018 09:51:10 +0200 Subject: [PATCH 1/3] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 241 bytes modified --- ff0fsum4zx.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 3fa4a5d..36624fc 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -14,7 +14,7 @@ this.beforeRender = R3.EntityManager.Instance.findComponentById('7l8ar325qf'); /** * Meshes */ -this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s'); +this.footballPlayer = R3.EntityManager.Instance.findComponentById('14xd9d1oqd'); this.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2'); this.goalL = R3.EntityManager.Instance.findComponentById('ackykfwyd4'); this.goalR = R3.EntityManager.Instance.findComponentById('040yhx0atm'); @@ -57,7 +57,7 @@ this.kickDistance = 0; this.raycaster = new THREE.Raycaster(); -this.debug = true; +this.debug = false; this.gravity = -9.8; @@ -67,7 +67,7 @@ this.startRayZ = -2; this.endRayZ = -2.5; -this.playerY = 0.375; +this.playerY = 0.389; this.ballY = this.football.instance.geometry.boundingSphere.radius / 2; @@ -136,6 +136,13 @@ R3.CustomCode.prototype.render = function(delta) { name : 'Audio - Crowd Cheer' } ); + R3.Event.Emit( + R3.Event.GAME_DATA, + { + type : 'score', + goal : 'left' + } + ); } } @@ -150,6 +157,13 @@ R3.CustomCode.prototype.render = function(delta) { name : 'Audio - Crowd Cheer' } ); + R3.Event.Emit( + R3.Event.GAME_DATA, + { + type : 'score', + goal : 'right' + } + ); } } @@ -410,7 +424,7 @@ R3.Event.Subscribe( this.mouseMove.entityLoaded = this; this.touchMove.entityLoaded = this; this.beforeRender.entityLoaded = this; - } + }.bind(this) ); R3.Event.Emit(R3.Event.GAME_LOADED); From 0094e7a5235d8ac1ebf5b08bd768a5c4ab835f0f Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Fri, 25 May 2018 11:54:55 +0200 Subject: [PATCH 2/3] restart game + game over events + time limit --- ff0fsum4zx.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 5 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 36624fc..32694db 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -41,6 +41,8 @@ this.playerRotation = { y : 0 }; +R3.CustomCode.TIME_LIMIT = 1.5 * 60; + this.balls = []; this.activeBall = this.football.instance; @@ -69,6 +71,10 @@ this.endRayZ = -2.5; this.playerY = 0.389; +this.totalTime = R3.CustomCode.TIME_LIMIT; + +this.score = 0; + this.ballY = this.football.instance.geometry.boundingSphere.radius / 2; if (this.debug) { @@ -82,6 +88,33 @@ if (this.debug) { R3.CustomCode.prototype.render = function(delta) { + this.totalTime -= delta; + + if (this.totalTime <= 0) { + + this.totalTime = 0; + + R3.Event.Emit( + R3.Event.GAME_OVER, + { + timeLimit : R3.CustomCode.TIME_LIMIT, + timeUsed : R3.CustomCode.TIME_LIMIT - this.totalTime, + score : this.score, + goals : this.balls.reduce( + function(result, ball){ + if (ball.scored) { + result.push(ball); + } + return result; + }, + [] + ) + } + ) + } + + if (this.totalTime) + this.balls.map( function(ball) { @@ -400,20 +433,91 @@ R3.CustomCode.prototype.move = function(data) { this.activeBall = null; } - - - }.bind(this) -this.footballPlayer.instance.translateY(this.playerY); -this.football.instance.position.y = this.ballY; +R3.Event.Subscribe( + R3.Event.GAME_OVER, + function(data) { + + R3.Event.Emit( + R3.Event.PLAY_AUDIO, + { + name : 'Audio - Crowd Cheer' + } + ); + + setTimeout( + function() { + R3.Event.Emit( + R3.Event.STOP_AUDIO, + { + name : 'Audio - Crowd' + } + ); + }, + 1500 + ); + + this.mouseMove.entityLoaded = null; + this.touchMove.entityLoaded = null; + this.beforeRender.entityLoaded = null; + + }.bind(this) +); R3.Event.Subscribe( R3.Event.GAME_START, function() { + /** + * Reset football player + * @type {number} + */ + this.footballPlayer.instance.rotation.x = 0; + this.footballPlayer.instance.rotation.y = 0; + this.footballPlayer.instance.rotation.z = 0; + + this.footballPlayer.instance.position.x = 0; + this.footballPlayer.instance.position.y = 0; + this.footballPlayer.instance.position.z = 0; + + this.footballPlayer.instance.position.y = this.playerY; + + /** + * Reset football + * @type {number} + */ + this.football.instance.rotation.x = 0; + this.football.instance.rotation.y = 0; + this.football.instance.rotation.z = 0; + + this.football.instance.position.x = 0; + this.football.instance.position.y = 0; + this.football.instance.position.z = 0; + + this.football.instance.position.y = this.ballY; + + this.score = 0; + + this.totalTime = R3.CustomCode.TIME_LIMIT; + + this.balls.map( + function(ball) { + + this.football.parentScene.instance.remove(ball.mesh); + + ball.mesh.material = null; + ball.mesh.geometry = null; + delete ball.mesh; + ball.mesh = null; + + }.bind(this) + ); + + this.balls = []; + R3.Event.Emit( R3.Event.PLAY_AUDIO, { @@ -424,6 +528,7 @@ R3.Event.Subscribe( this.mouseMove.entityLoaded = this; this.touchMove.entityLoaded = this; this.beforeRender.entityLoaded = this; + }.bind(this) ); From 31e23e29cfeaed0d3b2eea82d0bfa9a09b2b0efc Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Fri, 25 May 2018 12:14:30 +0200 Subject: [PATCH 3/3] generate timer events --- ff0fsum4zx.js | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 32694db..2fd2cf5 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -75,6 +75,8 @@ this.totalTime = R3.CustomCode.TIME_LIMIT; this.score = 0; +this.secondCounter = 0; + this.ballY = this.football.instance.geometry.boundingSphere.radius / 2; if (this.debug) { @@ -90,6 +92,18 @@ R3.CustomCode.prototype.render = function(delta) { this.totalTime -= delta; + this.secondCounter += delta; + if (this.secondCounter >= 1) { + this.secondCounter -= 1; + R3.Event.Emit( + R3.Event.GAME_DATA, + { + type : 'timer', + time : Math.round(this.totalTime) + } + ) + } + if (this.totalTime <= 0) { this.totalTime = 0; @@ -447,16 +461,11 @@ R3.Event.Subscribe( } ); - setTimeout( - function() { - R3.Event.Emit( - R3.Event.STOP_AUDIO, - { - name : 'Audio - Crowd' - } - ); - }, - 1500 + R3.Event.Emit( + R3.Event.STOP_AUDIO, + { + name : 'Audio - Crowd' + } ); this.mouseMove.entityLoaded = null; @@ -501,8 +510,18 @@ R3.Event.Subscribe( this.score = 0; + this.secondCounter = 0; + this.totalTime = R3.CustomCode.TIME_LIMIT; + R3.Event.Emit( + R3.Event.GAME_DATA, + { + type : 'timer', + time : this.totalTime + } + ); + this.balls.map( function(ball) {