Files
junisaber/src/components/gameover.js
2018-10-10 02:53:00 -07:00

40 lines
1006 B
JavaScript

AFRAME.registerComponent('gameover', {
schema: {
isGameOver: {default: false}
},
init: function () {
this.beatContainer = document.getElementById('beatContainer');
this.gameOverEls = document.querySelectorAll('[animation__gameover]');
},
update: function (oldData) {
var data = this.data;
if (!oldData.isGameOver && this.data.isGameOver) {
this.triggerAnimations();
this.countDown = 1;
}
if (oldData.isGameOver && !this.data.isGameOver) {
this.reset();
}
},
tick: function (time, delta) {
if (!this.data.isGameOver) { return; }
if (this.countDown >= 0) {
this.beatContainer.object3D.position.z = -Math.pow(1 - this.countDown, 2) * 1.5;
this.countDown -= delta / 1000;
}
},
reset: function () {
this.beatContainer.object3D.position.z = 0;
},
triggerAnimations: function () {
for (let i = 0; i < this.gameOverEls.length; i++) {
this.gameOverEls[i].emit('gameover', null, false);
}
}
});