QUOTE: Enjoy small things, cherish moments.

freezo

A retro platform game

commit d4baeee3307563972cd5cfaea0af4f16ddace4e6
parent 3a75f561ce255d25b51dd4a8128b0c65c6d256ae
Author: Sophie <info@soophie.de>
Date:   Mon, 16 Dec 2024 11:02:11 +0100

fix: Fixed distance calculation for shooting

Diffstat:
Msrc/player.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/player.c b/src/player.c @@ -262,6 +262,8 @@ void player_update(player_t *player, game_t *game) { float entity_distance = fabs(entity_x - (player->dir > 0 ? player->pos.x + PLAYER_WIDTH : player->pos.x)); if (player->target_entity != NULL && player->target_entity == entity) { target_in_range = true; + // if target entity set distance to that + player->shooting_distance = entity_distance; } if (entity_distance < closest_distance) { closest_distance = entity_distance; @@ -270,8 +272,9 @@ void player_update(player_t *player, game_t *game) { } } if (closest_entity != NULL) { - player->shooting_distance = closest_distance; if (!target_in_range) { + // if no target entity use closest distance + player->shooting_distance = closest_distance; player->target_entity = closest_entity; } }