Bug fixes

This commit is contained in:
mibi88 2024-07-31 17:26:08 +02:00
parent bbf366ed6e
commit 3dbf00f53d
6 changed files with 11 additions and 16 deletions

View file

@ -29,10 +29,10 @@ void interaction_available(Game *game) {
/* simple distance check along X and Y axis */ /* simple distance check along X and Y axis */
/* Be careful to use world coordinates, not local (i.e.map) ones */ /* Be careful to use world coordinates, not local (i.e.map) ones */
if((abs((int)game->player.wx - if((abs((int)game->player.x -
(int)(game->map_level->npcs[i].curx >> PRECISION) * PXSIZE) < (int)(game->map_level->npcs[i].curx >> PRECISION) * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE) && MAX_INTERACTION_DISTANCE * PXSIZE) &&
(abs((int)game->player.wy - (abs((int)game->player.y -
(int)(game->map_level->npcs[i].cury >> PRECISION) * PXSIZE) < (int)(game->map_level->npcs[i].cury >> PRECISION) * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE)) { MAX_INTERACTION_DISTANCE * PXSIZE)) {
/* the player can do something */ /* the player can do something */
@ -48,10 +48,10 @@ void interaction_available(Game *game) {
for(i = 0; i < game->map_level->nbSign; i++) { for(i = 0; i < game->map_level->nbSign; i++) {
/* simple distance check along X and Y axis */ /* simple distance check along X and Y axis */
/* Be careful to use world coordinates, not local (i.e.map) ones */ /* Be careful to use world coordinates, not local (i.e.map) ones */
if((abs((int)game->player.wx - if((abs((int)game->player.x -
(int)game->map_level->signs[i].x * PXSIZE) < (int)game->map_level->signs[i].x * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE) && MAX_INTERACTION_DISTANCE * PXSIZE) &&
(abs((int)game->player.wy - (abs((int)game->player.y -
(int)game->map_level->signs[i].y * PXSIZE) < (int)game->map_level->signs[i].y * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE)) { MAX_INTERACTION_DISTANCE * PXSIZE)) {
/* the player can do something */ /* the player can do something */

View file

@ -19,9 +19,8 @@ typedef struct {
/* Struct that define player parameters */ /* Struct that define player parameters */
typedef struct { typedef struct {
int16_t x, y; /* The position of the player int the current map */ int16_t x, y; /* The position of the player in the current map */
uint16_t px, py; /* The position of the player on screen */ uint16_t px, py; /* The position of the player on screen */
int16_t wx, wy; /* position of the player in the world */
int8_t life; /* How many lives the player still has between 0 and 100. */ int8_t life; /* How many lives the player still has between 0 and 100. */
int8_t speed; /* The speed of the movement of the player. */ int8_t speed; /* The speed of the movement of the player. */

View file

@ -33,7 +33,7 @@ extern Map *worldRPG[];
/* Game data (defined in "game.h")*/ /* Game data (defined in "game.h")*/
Game game = {NULL, Game game = {NULL,
{12 * PXSIZE, 36 * PXSIZE, 0, 0, 12 * PXSIZE, 36 * PXSIZE, 100, {12 * PXSIZE, 36 * PXSIZE, 0, 0, 100,
SPEED, false, 0, false, false, true}, SPEED, false, 0, false, false, true},
{{}, {}, 0}, {{}, {}, 0},
false, false,
@ -124,8 +124,10 @@ int main(void) {
dgray(DGRAY_ON); dgray(DGRAY_ON);
#endif #endif
#if DEBUGMODE
dupdate(); dupdate();
getkey(); getkey();
#endif
do { do {
/* clear screen */ /* clear screen */

View file

@ -231,7 +231,7 @@ Map *map_get_for_tile(Game *game, int x, int y) {
do { do {
int rx = x - map->x; int rx = x - map->x;
int ry = y - map->y; int ry = y - map->y;
if(rx >= 0 && rx < map->w && ry >= 0 && ry < map->h) { if(rx >= 0 && rx < (int)map->w && ry >= 0 && ry < (int)map->h) {
return map; return map;
} }
i++; i++;

View file

@ -267,8 +267,8 @@ void npc_draw(Game *game) {
} }
#endif // DEBUGMODE #endif // DEBUGMODE
int16_t delX = ((Data->curx * PXSIZE) >> PRECISION) - (int16_t)pl->wx; int16_t delX = ((Data->curx * PXSIZE) >> PRECISION) - (int16_t)pl->x;
int16_t delY = ((Data->cury * PXSIZE) >> PRECISION) - (int16_t)pl->wy; int16_t delY = ((Data->cury * PXSIZE) >> PRECISION) - (int16_t)pl->y;
bopti_image_t *face = npc_sprites[Data->face]; bopti_image_t *face = npc_sprites[Data->face];
dimage(pl->px - P_WIDTH / 2 + delX, pl->py - P_HEIGHT / 2 + delY, face); dimage(pl->px - P_WIDTH / 2 + delX, pl->py - P_HEIGHT / 2 + delY, face);
} }

View file

@ -51,9 +51,6 @@ void player_draw(Game *game) {
void player_move(Game *game, Direction direction) { void player_move(Game *game, Direction direction) {
Player *player = &game->player; Player *player = &game->player;
int old_x = player->x;
int old_y = player->y;
/* How this player movement will modify the player x and y. */ /* How this player movement will modify the player x and y. */
char dx, dy; char dx, dy;
@ -90,9 +87,6 @@ void player_move(Game *game, Direction direction) {
player->y += dy; player->y += dy;
} }
player->wx = game->map_level->x * T_WIDTH * PXSIZE + player->x;
player->wy = game->map_level->y * T_HEIGHT * PXSIZE + player->y;
/* Check if we should change map */ /* Check if we should change map */
Map *target = map_get_for_tile(game, Map *target = map_get_for_tile(game,
game->map_level->x + player->x / T_WIDTH + game->map_level->x + player->x / T_WIDTH +