Corrected bug regarding interactions with items in maps - used local coordinates instead of world coordinates :(

This commit is contained in:
SlyVTT 2023-08-17 07:11:52 +02:00
parent 9d8464e0d5
commit ad525b8693

View file

@ -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; i<game->map_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;