From de47cdb5e21d0dbda4d2ce34a6def3b6a5959289 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 8 Oct 2018 16:24:31 -0700 Subject: [PATCH] victory logic --- src/components/song.js | 8 ++++++++ src/state/index.js | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/song.js b/src/components/song.js index e09c892..364805b 100644 --- a/src/components/song.js +++ b/src/components/song.js @@ -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) { diff --git a/src/state/index.js b/src/state/index.js index 2686a13..9d9bf6e 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -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`;