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 */
/* 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) <
MAX_INTERACTION_DISTANCE * PXSIZE) &&
(abs((int)game->player.wy -
(abs((int)game->player.y -
(int)(game->map_level->npcs[i].cury >> PRECISION) * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE)) {
/* the player can do something */
@ -48,10 +48,10 @@ void interaction_available(Game *game) {
for(i = 0; i < game->map_level->nbSign; i++) {
/* simple distance check along X and Y axis */
/* 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) <
MAX_INTERACTION_DISTANCE * PXSIZE) &&
(abs((int)game->player.wy -
(abs((int)game->player.y -
(int)game->map_level->signs[i].y * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE)) {
/* the player can do something */

View file

@ -19,9 +19,8 @@ typedef struct {
/* Struct that define player parameters */
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 */
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 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 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},
{{}, {}, 0},
false,
@ -124,8 +124,10 @@ int main(void) {
dgray(DGRAY_ON);
#endif
#if DEBUGMODE
dupdate();
getkey();
#endif
do {
/* clear screen */

View file

@ -231,7 +231,7 @@ Map *map_get_for_tile(Game *game, int x, int y) {
do {
int rx = x - map->x;
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;
}
i++;

View file

@ -267,8 +267,8 @@ void npc_draw(Game *game) {
}
#endif // DEBUGMODE
int16_t delX = ((Data->curx * PXSIZE) >> PRECISION) - (int16_t)pl->wx;
int16_t delY = ((Data->cury * PXSIZE) >> PRECISION) - (int16_t)pl->wy;
int16_t delX = ((Data->curx * PXSIZE) >> PRECISION) - (int16_t)pl->x;
int16_t delY = ((Data->cury * PXSIZE) >> PRECISION) - (int16_t)pl->y;
bopti_image_t *face = npc_sprites[Data->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) {
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. */
char dx, dy;
@ -90,9 +87,6 @@ void player_move(Game *game, Direction direction) {
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 */
Map *target = map_get_for_tile(game,
game->map_level->x + player->x / T_WIDTH +