victory logic

This commit is contained in:
Kevin Ngo
2018-10-08 16:24:31 -07:00
parent 89346178f6
commit de47cdb5e2
2 changed files with 14 additions and 1 deletions

View File

@@ -23,6 +23,14 @@ AFRAME.registerComponent('song', {
audio.play();
}
});
audio.addEventListener('ended', () => {
if (this.data.isPlaying) {
this.el.sceneEl.emit('victory', null, false);
audio.pause();
audio.currentTime = 0;
}
});
},
update: function (oldData) {

View File

@@ -36,6 +36,7 @@ AFRAME.registerState({
isGameOver: false,
isPaused: false, // Playing, but paused. Not active during menu.
isPlaying: false, // Not in the menu AND not paused.
isVictory: false,
keyboardActive: false,
menu: {
active: true,
@@ -221,6 +222,10 @@ AFRAME.registerState({
'exit-vr': (state) => {
state.inVR = false;
},
victory: function (state) {
state.isVictory = true;
}
},
@@ -228,7 +233,7 @@ AFRAME.registerState({
* Post-process the state after each action.
*/
computeState: (state) => {
state.isPlaying = !state.menu.active && !state.isPaused;
state.isPlaying = !state.menu.active && !state.isPaused && !state.isVictory;
state.leftRaycasterActive = !state.isPlaying && state.activeHand === 'left' && state.inVR;
state.rightRaycasterActive = !state.isPlaying && state.activeHand === 'right' && state.inVR;
state.multiplierText = `${state.score.multiplier}x`;