From ad525b869338da437b8ae3bcc449f31a336326ff Mon Sep 17 00:00:00 2001 From: SlyVTT Date: Thu, 17 Aug 2023 07:11:52 +0200 Subject: [PATCH] Corrected bug regarding interactions with items in maps - used local coordinates instead of world coordinates :( --- src/game.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/game.c b/src/game.c index 8052712..e8e3c98 100644 --- a/src/game.c +++ b/src/game.c @@ -13,14 +13,22 @@ extern bopti_image_t SignAction_img; +#define MAX_INTERACTION_DISTANCE 16 + + void game_logic(Game *game) { /* we check if interactions are possible close to the player */ for( int i=0; imap_level->nbextradata; i++ ) { /* simple distance check along X and Y axis */ - if ( (abs((int) game->player.x - (int) game->map_level->extradata[i].x*PXSIZE) < 8*PXSIZE) - && (abs((int) game->player.y - (int) game->map_level->extradata[i].y*PXSIZE) < 8*PXSIZE)) + /* Be careful to use world coordinates, not local (i.e.map) ones */ + if ( (abs((int) game->player.wx - + (int) game->map_level->extradata[i].x*PXSIZE ) + < MAX_INTERACTION_DISTANCE*PXSIZE) + && (abs((int) game->player.wy - + (int) game->map_level->extradata[i].y*PXSIZE ) + < MAX_INTERACTION_DISTANCE*PXSIZE) ) { /* the player can do something */ game->player.canDoSomething = true;