From 97dd2c02a7bc5c33445669417ae82d341287feda Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Tue, 13 Nov 2018 00:17:24 +0800 Subject: [PATCH] multiplier ring (fixes #153) --- src/components/multiplier-ring.js | 66 +++++++++++++++++++++++++++++++ src/state/index.js | 19 +++++++-- src/templates/score.html | 8 ++-- 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/components/multiplier-ring.js diff --git a/src/components/multiplier-ring.js b/src/components/multiplier-ring.js new file mode 100644 index 0000000..bf4542b --- /dev/null +++ b/src/components/multiplier-ring.js @@ -0,0 +1,66 @@ +const COMBO_PROGRESS_MAP = { + 0: 0, + 1: 0.5, + 2: 0, + 3: 0.25, + 4: 0.5, + 5: 0.75, + 6: 0, + 7: 0.125, + 8: 0.25, + 9: 0.375, + 10: 0.5, + 11: 0.625, + 12: 0.75, + 13: 0.875 +}; + +/* + * Combo needed total for multiplier level: + * + * 0 - 1x + * 2 - 2x + * 6 - 4x + * 14 - 8x + */ +AFRAME.registerComponent('multiplier-ring', { + dependencies: ['geometry', 'material'], + + schema: { + combo: {default: 0}, + multiplier: {default: 1} + }, + + init: function () { + this.animationSet = {from: undefined, to: undefined}; + this.progress = this.el.getObject3D('mesh').material.uniforms.progress; + + // Set up animation. + this.el.setAttribute('animation', { + property: 'components.material.material.uniforms.progress.value', + dur: 100, + autoplay: false + }); + }, + + update: function () { + this.updateRing(); + }, + + updateRing: function () { + const data = this.data; + const el = this.el; + const progress = this.progress; + + if (data.multiplier === 8) { + progress.value = 1; + return; + } + + const animationSet = this.animationSet; + animationSet.from = progress.value; + animationSet.to = COMBO_PROGRESS_MAP[data.combo]; + el.setAttribute('animation', animationSet); + el.components.animation.beginAnimation(); + } +}); diff --git a/src/state/index.js b/src/state/index.js index 34efc0e..5b57734 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -123,9 +123,16 @@ AFRAME.registerState({ state.score.score += Math.floor(payload.score * state.score.multiplier); - state.score.multiplier = state.score.combo >= 8 - ? 8 - : 2 * Math.floor(Math.log2(state.score.combo)); + // Might be a math formula for this, but the multiplier system is easy reduced. + if (state.score.combo < 2) { + state.score.multiplier = 1; + } else if (state.score.combo < 6) { + state.score.multiplier = 2; + } else if (state.score.combo < 14) { + state.score.multiplier = 4; + } else { + state.score.multiplier = 8; + } }, beatmiss: state => { @@ -498,8 +505,12 @@ function difficultyComparator (a, b) { function takeDamage (state) { if (!state.isPlaying) { return; } + /* state.score.combo = 0; - state.score.multiplier = Math.ceil(state.score.multiplier / 2); + state.score.multiplier = state.score.multiplier > 1 + ? Math.ceil(state.score.multiplier / 2) + : 1; + */ if (AFRAME.utils.getUrlParameter('godmode')) { return; } state.damage++; checkGameOver(state); diff --git a/src/templates/score.html b/src/templates/score.html index fc52764..1f4d3dc 100644 --- a/src/templates/score.html +++ b/src/templates/score.html @@ -21,8 +21,8 @@ @@ -36,11 +36,11 @@ scale="5 5 5"> -