Dot beats can be cut from any direction

This commit is contained in:
Diego Marcos
2018-10-12 11:44:47 -10:00
parent 663d5d1775
commit e0e99e99a5
3 changed files with 15 additions and 12 deletions

View File

@@ -202,14 +202,14 @@ AFRAME.registerComponent('beat', {
this.setObjModelFromTemplate(cutRightEl, this.models.dot);
},
wrongCut: function (hand) {
wrongHit: function (hand) {
var wrongEl = hand === 'left' ? this.wrongElLeft : this.wrongElRight;
if (!wrongEl) { return; }
wrongEl.object3D.position.copy(this.el.object3D.position);
wrongEl.object3D.position.y += 0.2;
wrongEl.object3D.position.z -= 0.5;
wrongEl.object3D.visible = true;
wrongEl.emit('beatwrong', null, false);
wrongEl.emit('wronghit', null, false);
this.destroyed = true;
},
@@ -421,16 +421,19 @@ AFRAME.registerComponent('beat', {
saberBoundingBox = saberEls[i].components['saber-controls'].boundingBox;
if (!boundingBox || !saberBoundingBox) { break; }
if (saberBoundingBox.intersectsBox(boundingBox)) {
this.el.emit('beathit', null, false);
this.el.emit('goodhit', null, false);
this.el.parentNode.components['beat-hit-sound'].playSound(this.el);
this.destroyBeat(saberEls[i]);
break;
}
if (saberBoundingBox.intersectsBox(beatBoundingBox)) {
this.el.emit('beathit', null, false);
this.el.parentNode.components['beat-hit-sound'].playSound(this.el);
this.destroyBeat(saberEls[i]);
this.wrongCut(saberEls[i].getAttribute('saber-controls').hand);
if (this.data.type === 'dot') {
this.el.emit('goodhit', null, false);
} else {
this.wrongHit(saberEls[i].getAttribute('saber-controls').hand);
}
break;
}
}

View File

@@ -93,8 +93,8 @@
geometry="primitive: plane"
material="shader: flat; transparent: true"
visible="false"
animation__posz="property: object3D.position.z; to: -8; startEvents: beatwrong; easing: easeOutQuart; dur: 4000"
animation__alpha="property: components.material.material.opacity; from: 1; to: 0; startEvents: beatwrong; easing: easeOutQuart; dur: 4000"></a-mixin>
animation__posz="property: object3D.position.z; to: -8; startEvents: wronghit; easing: easeOutQuart; dur: 4000"
animation__alpha="property: components.material.material.opacity; from: 1; to: 0; startEvents: wronghit; easing: easeOutQuart; dur: 4000"></a-mixin>
</a-assets>
<a-entity id="arrowObjTemplate" obj-model="obj: #arrowObj" visible="false"></a-entity>

View File

@@ -83,7 +83,7 @@ AFRAME.registerState({
localStorage.setItem('activeHand', state.activeHand);
},
beathit: state => {
goodhit: state => {
if (state.damage > DAMAGE_DECAY) {
state.damage -= DAMAGE_DECAY;
}
@@ -98,10 +98,6 @@ AFRAME.registerState({
takeDamage(state);
},
beatwrong: state => {
takeDamage(state);
},
beatloaderfinish: (state) => {
state.challenge.isLoading = false;
},
@@ -248,6 +244,10 @@ AFRAME.registerState({
victory: function (state) {
state.isVictory = true;
},
wronghit: state => {
takeDamage(state);
}
},