Map change working

This commit is contained in:
mibi88 2024-07-31 17:11:29 +02:00
parent aa448c4dc6
commit 3dd4b6466a
3 changed files with 40 additions and 4 deletions

View file

@ -12,7 +12,7 @@ extern Map level2;
extern Map level3; extern Map level3;
extern Map level4; extern Map level4;
Map *worldRPG[] = {&level0, &level1, &level2, &level3, &level4}; Map *worldRPG[] = {&level0, &level1, &level2, &level3, &level4, NULL};
// extern ExtraData *extraRPG[]; // 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_level->walkable[y * map_level->w + x]
: MAP_OUTSIDE; : 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;
}

View file

@ -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); short int map_get_walkable(Game *game, int x, int y);
Map *map_get_for_tile(Game *game, int x, int y);
#endif #endif

View file

@ -51,6 +51,9 @@ 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;
@ -89,11 +92,27 @@ void player_move(Game *game, Direction direction) {
player->wx = game->map_level->x * T_WIDTH * PXSIZE + player->x; player->wx = game->map_level->x * T_WIDTH * PXSIZE + player->x;
player->wy = game->map_level->y * T_HEIGHT * PXSIZE + player->y; 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) { void player_action(Game *game) {
size_t i;
/* already doing something, or can't do anything*/ /* already doing something, or can't do anything*/
if(game->player.isDoingAction || !game->player.canDoSomething) if(game->player.isDoingAction || !game->player.canDoSomething)
return; return;
@ -130,7 +149,7 @@ void player_action(Game *game) {
bopti_image_t *face = &npc_male; bopti_image_t *face = &npc_male;
/* It's a NPC */ /* It's a NPC */
face = faces[currentNPC->face]; face = (bopti_image_t*)faces[currentNPC->face];
uint32_t dialogStart = currentNPC->dialogID; uint32_t dialogStart = currentNPC->dialogID;
/* we set this NPC to paused to avoid changing its position while /* we set this NPC to paused to avoid changing its position while