Fix NPC proximity to measure from player screen position not world origin
This commit is contained in:
@@ -425,11 +425,22 @@ class Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_playerScreenOffset() {
|
||||||
|
const {viewW, viewH} = this._getViewport();
|
||||||
|
return { px: viewW / 2, py: viewH - (viewH * 0.35) - 32 };
|
||||||
|
}
|
||||||
|
|
||||||
|
_npcScreenDist() {
|
||||||
|
const {viewW, viewH} = this._getViewport();
|
||||||
|
const {px, py} = this._playerScreenOffset();
|
||||||
|
const npcSX = viewW / 2 + (this.state.npcWorldX - this.state.worldX);
|
||||||
|
const npcSY = viewH / 2 + (this.state.npcWorldY - this.state.worldY);
|
||||||
|
return Math.sqrt((npcSX - px) ** 2 + (npcSY - py) ** 2);
|
||||||
|
}
|
||||||
|
|
||||||
_checkNPCProximity() {
|
_checkNPCProximity() {
|
||||||
const {viewW, viewH} = this._getViewport();
|
const {viewW, viewH} = this._getViewport();
|
||||||
const dx = this.state.npcWorldX - this.state.worldX;
|
const dist = this._npcScreenDist();
|
||||||
const dy = this.state.npcWorldY - this.state.worldY;
|
|
||||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
||||||
const near = !(this.state.npcWorldX === 0 && this.state.npcWorldY === 0) && dist < 300;
|
const near = !(this.state.npcWorldX === 0 && this.state.npcWorldY === 0) && dist < 300;
|
||||||
|
|
||||||
const hint = document.getElementById('map-talk-hint');
|
const hint = document.getElementById('map-talk-hint');
|
||||||
@@ -481,9 +492,7 @@ class Game {
|
|||||||
|
|
||||||
_nearNPC() {
|
_nearNPC() {
|
||||||
if (this.state.npcWorldX === 0 && this.state.npcWorldY === 0) return false;
|
if (this.state.npcWorldX === 0 && this.state.npcWorldY === 0) return false;
|
||||||
const dx = this.state.npcWorldX - this.state.worldX;
|
return this._npcScreenDist() < 300;
|
||||||
const dy = this.state.npcWorldY - this.state.worldY;
|
|
||||||
return Math.sqrt(dx * dx + dy * dy) < 300;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_talkToNPC() {
|
_talkToNPC() {
|
||||||
|
|||||||
Reference in New Issue
Block a user