Move score calculation from state to payload of the beathit event

This commit is contained in:
Diego Marcos
2018-10-31 15:45:59 -07:00
parent aa086d7567
commit 119979fce4
2 changed files with 11 additions and 8 deletions

View File

@@ -665,6 +665,7 @@ AFRAME.registerComponent('beat', {
var hitEventDetail = this.hitEventDetail;
var maxAngle;
var saberControls = this.hitSaberEl.components['saber-controls'];
var score = 0;
if (cutDirection === 'up' || cutDirection === 'down') {
maxAngle = saberControls.maxAnglePlaneX;
@@ -673,10 +674,17 @@ AFRAME.registerComponent('beat', {
} else {
maxAngle = saberControls.maxAnglePlaneXY;
}
hitEventDetail.angleBeforeHit = this.angleBeforeHit * 180 / Math.PI;
hitEventDetail.angleAfterHit = maxAngle * 180 / Math.PI;
const angleBeforeHit = this.angleBeforeHit * 180 / Math.PI;
const angleAfterHit = maxAngle * 180 / Math.PI;
score += angleBeforeHit >= 90 ? 70 : (angleBeforeHit / 90) * 70;
score += angleAfterHit >= 60 ? 30 : (angleAfterHit / 60) * 30;
hitEventDetail.score = score;
this.el.emit('beathit', hitEventDetail, true);
// console.log("BEAT SCORE: " + score + " " + angleBeforeHit + " " + angleAfterHit);
},
/**

View File

@@ -111,7 +111,6 @@ AFRAME.registerState({
},
beathit: (state, payload) => {
var score = 0;
if (state.damage > DAMAGE_DECAY) {
state.damage -= DAMAGE_DECAY;
}
@@ -121,15 +120,11 @@ AFRAME.registerState({
state.score.maxCombo = state.score.combo;
}
score += payload.angleBeforeHit >= 90 ? 70 : (payload.angleBeforeHit / 90) * 70;
score += payload.angleAfterHit >= 60 ? 30 : (payload.angleAfterHit / 60) * 30;
state.score.score += Math.floor(score * state.score.multiplier);
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));
// console.log("BEAT SCORE: " + score + " " + payload.angleBeforeHit + " " + payload.angleAfterHit);
},
beatmiss: state => {