diff --git a/src/map.c b/src/map.c index 89dce2f..6a53804 100644 --- a/src/map.c +++ b/src/map.c @@ -12,7 +12,7 @@ extern Map level2; extern Map level3; extern Map level4; -Map *worldRPG[] = {&level0, &level1, &level2, &level3, &level4}; +Map *worldRPG[] = {&level0, &level1, &level2, &level3, &level4, NULL}; // extern ExtraData *extraRPG[]; @@ -224,3 +224,18 @@ short int map_get_walkable(Game *game, int x, int y) { ? map_level->walkable[y * map_level->w + x] : MAP_OUTSIDE; } + +Map *map_get_for_tile(Game *game, int x, int y) { + int i = 0; + Map *map = worldRPG[i]; + do{ + int rx = x - map->x; + int ry = y - map->y; + if(rx >= 0 && rx < map->w && ry >= 0 && ry < map->h){ + return map; + } + i++; + map = worldRPG[i]; + }while(map != NULL); + return game->map_level; +} diff --git a/src/map.h b/src/map.h index c49d0af..249f148 100644 --- a/src/map.h +++ b/src/map.h @@ -50,4 +50,6 @@ short int map_get_tile(Game *game, int x, int y, int l); */ short int map_get_walkable(Game *game, int x, int y); +Map *map_get_for_tile(Game *game, int x, int y); + #endif diff --git a/src/player.c b/src/player.c index 8957bb3..59bf857 100644 --- a/src/player.c +++ b/src/player.c @@ -51,6 +51,9 @@ 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; @@ -89,11 +92,27 @@ void player_move(Game *game, Direction direction) { 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+one_px_mov[direction * 2], game->map_level->y+player->y/T_HEIGHT+one_px_mov[direction * 2 + 1]); + if(target != game->map_level){ + if(target->x > game->map_level->x){ + player->x = 0; + } + if(target->x < game->map_level->x){ + player->x = target->w*T_WIDTH; + } + if(target->y > game->map_level->y){ + player->y = 0; + } + if(target->y < game->map_level->y){ + player->y = target->h*T_HEIGHT; + } + game->map_level = target; + } } void player_action(Game *game) { - size_t i; - /* already doing something, or can't do anything*/ if(game->player.isDoingAction || !game->player.canDoSomething) return; @@ -130,7 +149,7 @@ void player_action(Game *game) { bopti_image_t *face = &npc_male; /* It's a NPC */ - face = faces[currentNPC->face]; + face = (bopti_image_t*)faces[currentNPC->face]; uint32_t dialogStart = currentNPC->dialogID; /* we set this NPC to paused to avoid changing its position while