Move score calculation from state to payload of the beathit event
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user