Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 2985 bytes modified

beta.r3js.org
Theunis Johannes Botha 2018-05-25 12:18:01 +02:00
parent 3d8b1a3033
commit b8ff03924d
1 changed files with 129 additions and 5 deletions

View File

@ -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,12 @@ this.endRayZ = -2.5;
this.playerY = 0.389;
this.totalTime = R3.CustomCode.TIME_LIMIT;
this.score = 0;
this.secondCounter = 0;
this.ballY = this.football.instance.geometry.boundingSphere.radius / 2;
if (this.debug) {
@ -82,6 +90,45 @@ if (this.debug) {
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;
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 +447,96 @@ 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'
}
);
R3.Event.Emit(
R3.Event.STOP_AUDIO,
{
name : 'Audio - Crowd'
}
);
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.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) {
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 +547,7 @@ R3.Event.Subscribe(
this.mouseMove.entityLoaded = this;
this.touchMove.entityLoaded = this;
this.beforeRender.entityLoaded = this;
}.bind(this)
);