From 770a66cbcbc617c5f91d6777f269d466f59b1fb6 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Thu, 25 Oct 2018 03:03:50 -0700 Subject: [PATCH] apply warm up time only to beats --- src/components/beat-loader.js | 24 ++++++++++-------------- src/components/beat.js | 35 ++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index c9be8a8..0d671f4 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -133,13 +133,8 @@ AFRAME.registerComponent('beat-loader', { * Generate beats and stuff according to timestamp. */ tick: function (time, delta) { - var bpm; + const beatsTime = this.beatsTime; var i; - var notes; - var obstacles; - var events; - var beatsTime = this.beatsTime; - var msPerBeat; var noteTime; if (!this.data.isPlaying || !this.data.challengeId || !this.beatData) { return; } @@ -148,23 +143,23 @@ AFRAME.registerComponent('beat-loader', { if (this.beatsTimeOffset !== undefined && this.songCurrentTime !== this.el.components.song.context.currentTime) { this.songCurrentTime = this.el.components.song.context.currentTime; - this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000 - - BEAT_WARMUP_TIME; + this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000; } - notes = this.beatData._notes; - obstacles = this.beatData._obstacles; - events = this.beatData._events; - bpm = this.beatData._beatsPerMinute; - msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute; + const bpm = this.beatData._beatsPerMinute; + const msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute; + + const notes = this.beatData._notes; for (i = 0; i < notes.length; ++i) { noteTime = notes[i]._time * msPerBeat; - if (noteTime > beatsTime && noteTime <= beatsTime + delta) { + if (noteTime > (beatsTime - BEAT_WARMUP_TIME) && + noteTime <= (beatsTime - BEAT_WARMUP_TIME + delta)) { notes[i].time = noteTime; this.generateBeat(notes[i]); } } + const obstacles = this.beatData._obstacles; for (i = 0; i < obstacles.length; ++i) { noteTime = obstacles[i]._time * msPerBeat; if (noteTime > beatsTime && noteTime <= beatsTime + delta) { @@ -172,6 +167,7 @@ AFRAME.registerComponent('beat-loader', { } } + const events = this.beatData._events; for (i=0; i < events.length; ++i) { noteTime = events[i]._time * msPerBeat; if (noteTime > beatsTime && noteTime <= beatsTime + delta) { diff --git a/src/components/beat.js b/src/components/beat.js index 3a0f24b..ddece52 100644 --- a/src/components/beat.js +++ b/src/components/beat.js @@ -81,8 +81,7 @@ AFRAME.registerComponent('beat', { this.initColliders(); if (this.data.type === 'mine') { this.initMineFragments(); - } - else { + } else { this.initFragments(); }; }, @@ -163,6 +162,9 @@ AFRAME.registerComponent('beat', { if (Math.random > 0.5) { this.rotationZChange *= -1; } this.el.object3D.rotation.z -= this.rotationZChange; this.rotationZStart = this.el.object3D.rotation.z; + + // Reset mine. + if (this.data.type == 'mine') { this.resetMineFragments(); } }, initBlock: function () { @@ -284,16 +286,7 @@ AFRAME.registerComponent('beat', { var fragment; if (this.data.type === 'mine') { - for (var i = 0; i < this.mineFragments.length; i++) { - fragment = this.mineFragments[i]; - fragment.visible = false; - fragment.position.set(0, 0, 0); - fragment.scale.set(1, 1, 1); - fragment.speed.set( - Math.random() * 5 - 2.5, - Math.random() * 5 - 2.5, - Math.random() * 5 - 2.5); - } + this.resetMineFragments(); return; } @@ -332,6 +325,20 @@ AFRAME.registerComponent('beat', { this.setObjModelFromTemplate(cutRightEl, this.models.dot); }, + resetMineFragments: function () { + if (this.data.type !== 'mine') { return; } + for (let i = 0; i < this.mineFragments.length; i++) { + let fragment = this.mineFragments[i]; + fragment.visible = false; + fragment.position.set(0, 0, 0); + fragment.scale.set(1, 1, 1); + fragment.speed.set( + Math.random() * 5 - 2.5, + Math.random() * 5 - 2.5, + Math.random() * 5 - 2.5); + } + }, + wrongHit: function (hand) { var wrongEl = hand === 'left' ? this.wrongElLeft : this.wrongElRight; if (!wrongEl) { return; } @@ -466,9 +473,7 @@ AFRAME.registerComponent('beat', { })(), destroyMine: function () { - var fragment; - - for (var i = 0; i < this.mineFragments.length; i++) { + for (let i = 0; i < this.mineFragments.length; i++) { this.mineFragments[i].visible = true; }