refactor gameover animations
This commit is contained in:
@@ -5,38 +5,35 @@ AFRAME.registerComponent('gameover', {
|
||||
|
||||
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){
|
||||
console.log('starting slow down...');
|
||||
this.el.sceneEl.setAttribute('stage-colors', 'red');
|
||||
if (!oldData.isGameOver && this.data.isGameOver) {
|
||||
this.triggerAnimations();
|
||||
this.countDown = 1;
|
||||
this.lastTime = performance.now();
|
||||
}
|
||||
if (oldData.isGameOver && !this.data.isGameOver){
|
||||
this.resetStage();
|
||||
if (oldData.isGameOver && !this.data.isGameOver) {
|
||||
this.reset();
|
||||
}
|
||||
},
|
||||
|
||||
tick: function (time, delta) {
|
||||
if (!this.data.isGameOver) { return; }
|
||||
if (this.countDown >= 0){
|
||||
this.el.sceneEl.emit('slowdown', {progress: this.countDown});
|
||||
//this.beatContainer.object3D.position.z = -Math.pow(1 - this.countDown, 2) * 1.5;
|
||||
if (this.countDown >= 0) {
|
||||
this.beatContainer.object3D.position.z = -Math.pow(1 - this.countDown, 2) * 1.5;
|
||||
this.countDown -= delta / 1000;
|
||||
this.el.sceneEl.systems.beat.speed = this.countDown;
|
||||
}
|
||||
else {
|
||||
this.data.start = false;
|
||||
setTimeout(()=>{ this.el.sceneEl.emit('pausegame'); }, 1000);
|
||||
}
|
||||
},
|
||||
resetStage: function () {
|
||||
this.data.start = false;
|
||||
|
||||
reset: function () {
|
||||
this.beatContainer.object3D.position.z = 0;
|
||||
this.el.sceneEl.systems.beat.speed = 1.0;
|
||||
this.el.sceneEl.setAttribute('stage-colors', 'blue');
|
||||
},
|
||||
|
||||
triggerAnimations: function () {
|
||||
for (let i = 0; i < this.gameOverEls.length; i++) {
|
||||
this.gameOverEls[i].emit('gameover', null, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user