mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 00:36:47 +02:00
Add state constants to bow
This commit is contained in:
parent
25821eb01a
commit
c06a3a3a11
1 changed files with 29 additions and 24 deletions
|
@ -93,6 +93,14 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STRING_NAME = 'Hifi-Bow-String';
|
||||||
|
const ARROW_NAME = 'Hifi-Arrow';
|
||||||
|
|
||||||
|
const STATE_IDLE = 0;
|
||||||
|
const STATE_ARROW_KNOCKED = 1;
|
||||||
|
const STATE_ARROW_GRABBED = 2;
|
||||||
|
const STATE_ARROW_GRABBED_AND_PULLED = 3;
|
||||||
|
|
||||||
Bow.prototype = {
|
Bow.prototype = {
|
||||||
topString: null,
|
topString: null,
|
||||||
aiming: false,
|
aiming: false,
|
||||||
|
@ -107,12 +115,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 0 = start
|
state: STATE_IDLE,
|
||||||
// 1 = hand close to knock, arrow is drawn
|
|
||||||
// 2 = arrow is grabbed
|
|
||||||
// 3 = arrow is grabbed and pulled
|
|
||||||
|
|
||||||
state: 0,
|
|
||||||
sinceLastUpdate: 0,
|
sinceLastUpdate: 0,
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
@ -347,59 +350,61 @@
|
||||||
var handToNotch = Vec3.subtract(notchPosition, stringHandPosition);
|
var handToNotch = Vec3.subtract(notchPosition, stringHandPosition);
|
||||||
var pullBackDistance = Vec3.length(handToNotch);
|
var pullBackDistance = Vec3.length(handToNotch);
|
||||||
|
|
||||||
if (this.state === 0) {
|
if (this.state === STATE_IDLE) {
|
||||||
this.pullBackDistance = 0;
|
this.pullBackDistance = 0;
|
||||||
|
|
||||||
this.deleteStrings();
|
this.resetStringToIdlePosition();
|
||||||
|
//this.deleteStrings();
|
||||||
if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE - NEAR_TO_RELAXED_SCHMITT) && !this.backHandBusy) {
|
if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE - NEAR_TO_RELAXED_SCHMITT) && !this.backHandBusy) {
|
||||||
//the first time aiming the arrow
|
//the first time aiming the arrow
|
||||||
var handToDisable = (this.hand === 'right' ? 'left' : 'right');
|
var handToDisable = (this.hand === 'right' ? 'left' : 'right');
|
||||||
Messages.sendMessage('Hifi-Hand-Disabler', handToDisable);
|
Messages.sendLocalMessage('Hifi-Hand-Disabler', handToDisable);
|
||||||
this.arrow = this.createArrow();
|
this.arrow = this.createArrow();
|
||||||
this.playStringPullSound();
|
this.playStringPullSound();
|
||||||
this.state = 1;
|
this.state = STATE_ARROW_KNOCKED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.state === 1) {
|
if (this.state === STATE_ARROW_KNOCKED) {
|
||||||
|
|
||||||
if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||||
// delete the unpulled arrow
|
// delete the unpulled arrow
|
||||||
Messages.sendMessage('Hifi-Hand-Disabler', "none");
|
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||||
Entities.deleteEntity(this.arrow);
|
Entities.deleteEntity(this.arrow);
|
||||||
this.arrow = null;
|
this.arrow = null;
|
||||||
this.state = 0;
|
this.state = STATE_IDLE;
|
||||||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD) {
|
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD) {
|
||||||
// they've grabbed the arrow
|
// they've grabbed the arrow
|
||||||
this.pullBackDistance = 0;
|
this.pullBackDistance = 0;
|
||||||
this.state = 2;
|
this.state = STATE_ARROW_GRABBED;
|
||||||
} else {
|
} else {
|
||||||
this.drawStrings();
|
this.updateString();
|
||||||
this.updateArrowPositionInNotch(false, false);
|
this.updateArrowPositionInNotch(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.state === 2) {
|
if (this.state === STATE_ARROW_GRABBED) {
|
||||||
if (this.triggerValue < DRAW_STRING_THRESHOLD) {
|
if (this.triggerValue < DRAW_STRING_THRESHOLD) {
|
||||||
// they let go without pulling
|
// they let go without pulling
|
||||||
this.state = 1;
|
this.state = STATE_ARROW_KNOCKED;
|
||||||
} else if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
} else if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||||
// they've grabbed the arrow and pulled it
|
// they've grabbed the arrow and pulled it
|
||||||
this.state = 3;
|
this.state = STATE_ARROW_GRABBED_AND_PULLED;
|
||||||
} else {
|
} else {
|
||||||
this.drawStrings();
|
this.updateString();
|
||||||
this.updateArrowPositionInNotch(false, true);
|
this.updateArrowPositionInNotch(false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.state === 3) {
|
if (this.state === STATE_ARROW_GRABBED_AND_PULLED) {
|
||||||
if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||||
// they unpulled without firing
|
// they unpulled without firing
|
||||||
this.state = 2;
|
this.state = STATE_ARROW_GRABBED;
|
||||||
} else if (this.triggerValue < DRAW_STRING_THRESHOLD) {
|
} else if (this.triggerValue < DRAW_STRING_THRESHOLD) {
|
||||||
// they've fired the arrow
|
// they've fired the arrow
|
||||||
Messages.sendMessage('Hifi-Hand-Disabler', "none");
|
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||||
this.updateArrowPositionInNotch(true, true);
|
this.updateArrowPositionInNotch(true, true);
|
||||||
this.state = 0;
|
this.state = STATE_IDLE;
|
||||||
|
this.resetStringToIdlePosition();
|
||||||
} else {
|
} else {
|
||||||
this.drawStrings();
|
this.updateString();
|
||||||
this.updateArrowPositionInNotch(false, true);
|
this.updateArrowPositionInNotch(false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue