hook up pause menu restart. default multiplier as 1x, display as {multiplier}x

This commit is contained in:
Kevin Ngo
2018-10-04 00:35:18 -07:00
parent 733741012b
commit 318f6f030f
3 changed files with 38 additions and 19 deletions

View File

@@ -16,6 +16,17 @@ AFRAME.registerComponent('beat-loader', {
horizontalPositions: [-0.60, -0.25, 0.25, 0.60],
verticalPositions: [1.00, 1.35, 1.70],
init: function () {
this.audioSync = undefined;
this.beatData = null;
this.beatContainer = document.getElementById('beatContainer');
this.bpm = undefined;
this.first = null;
this.lastTime = undefined;
this.el.addEventListener('pausemenurestart', this.restart.bind(this));
},
update: function () {
if (!this.data.challengeId || !this.data.difficulty) { return; }
this.loadBeats();
@@ -51,6 +62,7 @@ AFRAME.registerComponent('beat-loader', {
this.beatData = beatData;
this.beatData._obstacles.sort(lessThan);
this.beatData._notes.sort(lessThan);
this.bpm = this.beatData._beatsPerMinute;
console.log('Finished loading challenge data.');
},
@@ -59,6 +71,7 @@ AFRAME.registerComponent('beat-loader', {
*/
tick: function (time, delta) {
var audioEl = this.el.components.song.audio;
var bpm;
var i;
var notes;
var obstacles;
@@ -70,7 +83,7 @@ AFRAME.registerComponent('beat-loader', {
notes = this.beatData._notes;
obstacles = this.beatData._obstacles;
this.bpm = this.beatData._beatsPerMinute;
bpm = this.beatData._beatsPerMinute;
msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute;
for (i = 0; i < notes.length; ++i) {
noteTime = notes[i]._time * msPerBeat;
@@ -161,22 +174,21 @@ AFRAME.registerComponent('beat-loader', {
requestBeat: function (type, color) {
var beatPoolName = 'pool__beat-' + type;
var pool;
if (color) {beatPoolName += '-' + color; }
if (color) { beatPoolName += '-' + color; }
pool = this.el.sceneEl.components[beatPoolName];
if (!pool) {
console.warn('Poo ' + beatPoolName + ' unavailable');
console.warn('Pool ' + beatPoolName + ' unavailable');
return;
}
return pool.requestEntity();
},
restart: function () {
this.audioSync = null;
this.first = null;
this.lastTime = 0;
for (let i = 0; i < this.beatContainer.children.length; i++) {
this.beatContainer.children[i].components.beat.returnToPool();
}
}
});
function updateQueryParam(uri, key, value) {
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
if (uri.match(re)) {
return uri.replace(re, '$1' + key + '=' + value + '$2');
} else {
return uri + separator + key + '=' + value;
}
}

View File

@@ -45,10 +45,11 @@ AFRAME.registerState({
songName: '',
songSubName: ''
},
multiplierText: '1x',
score: {
combo: 0,
score: 0,
multiplier: 0
multiplier: 1
},
search: {
active: true,
@@ -128,10 +129,12 @@ AFRAME.registerState({
},
pausemenurestart: (state) => {
resetScore(state);
state.isPaused = false;
},
pausemenuexit: (state) => {
resetScore(state);
state.isPaused = false;
state.menu.active = true;
},
@@ -141,10 +144,7 @@ AFRAME.registerState({
* Transfer staged challenge to the active challenge.
*/
playbuttonclick: (state) => {
// Reset score.
state.score.combo = 0;
state.score.score = 0;
state.score.multiplier = 0;
resetScore(state);
// Set challenge. `beat-loader` is listening.
Object.assign(state.challenge, state.menuSelectedChallenge);
@@ -201,6 +201,7 @@ AFRAME.registerState({
state.isPlaying = !state.menu.active && !state.isPaused;
state.leftRaycasterActive = !state.isPlaying && state.activeHand === 'left' && state.inVR;
state.rightRaycasterActive = !state.isPlaying && state.activeHand === 'right' && state.inVR;
state.multiplierText = `${state.score.multiplier}x`;
}
});
@@ -233,3 +234,9 @@ function difficultyComparator (a, b) {
if (aIndex > bIndex) { return 1; }
return 0;
}
function resetScore (state) {
state.score.combo = 0;
state.score.score = 0;
state.score.multiplier = 1;
}

View File

@@ -20,7 +20,7 @@
</a-entity>
<a-entity
id="multiplier"
bind__text="value: score.multiplier"
bind__text="value: multiplierText"
mixin="textFont"
text="width: 1; color: #feffc1; letterSpacing: -2; align: center"
position="1.8 1.2 -4"