directional shift for current player when trying to activate entities
This commit is contained in:
parent
72b4438d1e
commit
bf0d2eb412
@ -159,6 +159,19 @@ export abstract class Character extends Container implements OutlineableInterfac
|
|||||||
return { x: this.x, y: this.y };
|
return { x: this.x, y: this.y };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns position based on where player is currently facing
|
||||||
|
* @param shift How far from player should the point of interest be.
|
||||||
|
*/
|
||||||
|
public getDirectionalActivationPosition(shift: number): { x: number, y: number } {
|
||||||
|
switch (this.lastDirection) {
|
||||||
|
case PlayerAnimationDirections.Down: { return { x: this.x, y: this.y + shift }; }
|
||||||
|
case PlayerAnimationDirections.Left: { return { x: this.x - shift, y: this.y }; }
|
||||||
|
case PlayerAnimationDirections.Right: { return { x: this.x + shift, y: this.y }; }
|
||||||
|
case PlayerAnimationDirections.Up: { return { x: this.x, y: this.y - shift }; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public getObjectToOutline(): Phaser.GameObjects.GameObject {
|
public getObjectToOutline(): Phaser.GameObjects.GameObject {
|
||||||
return this.playerNameText;
|
return this.playerNameText;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ export class ActivatablesManager {
|
|||||||
private currentPlayer: Player;
|
private currentPlayer: Player;
|
||||||
|
|
||||||
private readonly outlineColor = 0xffff00;
|
private readonly outlineColor = 0xffff00;
|
||||||
|
private readonly directionalActivationPositionShift = 50;
|
||||||
|
|
||||||
constructor(currentPlayer: Player) {
|
constructor(currentPlayer: Player) {
|
||||||
this.currentPlayer = currentPlayer;
|
this.currentPlayer = currentPlayer;
|
||||||
@ -79,7 +80,7 @@ export class ActivatablesManager {
|
|||||||
return closestObject;
|
return closestObject;
|
||||||
}
|
}
|
||||||
public updateActivatableObjectsDistances(objects: ActivatableInterface[]): void {
|
public updateActivatableObjectsDistances(objects: ActivatableInterface[]): void {
|
||||||
const currentPlayerPos = this.currentPlayer.getPosition();
|
const currentPlayerPos = this.currentPlayer.getDirectionalActivationPosition(this.directionalActivationPositionShift);
|
||||||
for (const object of objects) {
|
for (const object of objects) {
|
||||||
const distance = MathUtils.distanceBetween(currentPlayerPos, object.getPosition());
|
const distance = MathUtils.distanceBetween(currentPlayerPos, object.getPosition());
|
||||||
this.activatableObjectsDistances.set(object, distance);
|
this.activatableObjectsDistances.set(object, distance);
|
||||||
@ -89,7 +90,10 @@ export class ActivatablesManager {
|
|||||||
public updateDistanceForSingleActivatableObject(object: ActivatableInterface): void {
|
public updateDistanceForSingleActivatableObject(object: ActivatableInterface): void {
|
||||||
this.activatableObjectsDistances.set(
|
this.activatableObjectsDistances.set(
|
||||||
object,
|
object,
|
||||||
MathUtils.distanceBetween(this.currentPlayer.getPosition(), object.getPosition())
|
MathUtils.distanceBetween(
|
||||||
|
this.currentPlayer.getDirectionalActivationPosition(this.directionalActivationPositionShift),
|
||||||
|
object.getPosition(),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user