fixed hitbox calculation

This commit is contained in:
Johannes Berthel 2021-04-09 20:41:30 +02:00 committed by Thomas Basler
parent 7fef260b38
commit 243d4d6565
1 changed files with 7 additions and 8 deletions

View File

@ -355,16 +355,15 @@ export class InteractiveLayer extends Container {
} }
/** /**
* Returns the charachters position. Response is prepared * Returns the charachters position.
* for SpriteEntity hitbox calculation.
* *
* @param {Character} char * @param {Character} char
* @returns {PositionInterface} * @returns {PositionInterface}
*/ */
private getCharacterPosition(char: Character): PositionInterface { private getCharacterPosition(char: Character): PositionInterface {
return { return {
x: char.x + char.width, x: char.x,
y: char.y + char.height * 2 y: char.y
} }
} }
@ -379,10 +378,10 @@ export class InteractiveLayer extends Container {
private isPlayerInsideInteractionRadius(playerPosition: PositionInterface, sprite: Sprite, radius: number): boolean { private isPlayerInsideInteractionRadius(playerPosition: PositionInterface, sprite: Sprite, radius: number): boolean {
const { x, y } = playerPosition; const { x, y } = playerPosition;
return sprite.x - sprite.width * radius <= x // left return sprite.x - sprite.width * radius <= x + sprite.width / 2 // left
&& sprite.y - sprite.height * radius <= y // top && sprite.y - sprite.height * radius <= y + sprite.height // top
&& sprite.x + sprite.width * (radius + 1) > x // right && sprite.x + sprite.width * (radius + 1) > x + sprite.width / 2 // right
&& sprite.y + sprite.height * (radius + 1) > y // bottom && sprite.y + sprite.height * (radius + 1) > y + sprite.height // bottom
} }
/** /**