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;