Check that saber and hit beat match color (fix #116)

This commit is contained in:
Diego Marcos
2018-10-16 11:28:17 -07:00
parent abc3f73800
commit 42ff361e92

View File

@@ -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);