From 42ff361e92b73beb2b5cfb6689035452e2f8ebae Mon Sep 17 00:00:00 2001 From: Diego Marcos Date: Tue, 16 Oct 2018 11:28:17 -0700 Subject: [PATCH] Check that saber and hit beat match color (fix #116) --- src/components/beat.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/beat.js b/src/components/beat.js index 2ea8e70..89f3e5c 100644 --- a/src/components/beat.js +++ b/src/components/beat.js @@ -60,6 +60,11 @@ AFRAME.registerComponent('beat', { this.particles = document.getElementById('saberParticles'); + this.saberColors = { + right: 'blue', + left: 'red' + }; + this.initBlock(); this.initColliders(); this.initFragments(); @@ -436,6 +441,7 @@ AFRAME.registerComponent('beat', { }, checkCollisions: function () { + const saberColors = this.saberColors; const saberEls = this.saberEls; const hitBoundingBox = this.hitColliderEl && this.hitBoundingBox.setFromObject( this.hitColliderEl.getObject3D('mesh')); @@ -448,7 +454,8 @@ AFRAME.registerComponent('beat', { if (!saberBoundingBox) { break; } if (hitBoundingBox && saberBoundingBox.intersectsBox(hitBoundingBox)) { - if (saberEls[i].components['saber-controls'].swinging) { + debugger; + if (saberEls[i].components['saber-controls'].swinging && this.data.color === saberColors[saberEls[i].getAttribute('saber-controls').hand]) { this.el.emit('beathit', null, true); } else { this.wrongHit(saberEls[i].getAttribute('saber-controls').hand); @@ -461,7 +468,7 @@ AFRAME.registerComponent('beat', { if (saberBoundingBox.intersectsBox(beatBoundingBox)) { this.el.parentNode.components['beat-hit-sound'].playSound(this.el); this.destroyBeat(saberEls[i]); - if (this.data.type === 'dot' && saberEls[i].components['saber-controls'].swinging) { + if (this.data.type === 'dot' && saberEls[i].components['saber-controls'].swinging && saberColors[saberEls[i].getAttribute('saber-controls').hand]) { this.el.emit('beathit', null, true); } else { this.wrongHit(saberEls[i].getAttribute('saber-controls').hand);