restart game + game over events + time limit
parent
16853b1ae4
commit
0094e7a523
115
ff0fsum4zx.js
115
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)
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue