2021-08-15 02:42:26 +02:00
|
|
|
#include "map.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "player.h"
|
2021-08-21 02:54:03 +02:00
|
|
|
#include "camera.h"
|
|
|
|
#include "define.h"
|
2021-08-15 02:42:26 +02:00
|
|
|
|
|
|
|
/*check if a tile is walkable*/
|
2021-08-15 03:46:49 +02:00
|
|
|
int map_walkable(struct Map const *map, int x, int y) {
|
2021-08-15 02:42:26 +02:00
|
|
|
int tile = map->info_map[x + map->w * y];
|
|
|
|
if(x < 0 || x > map->w-1 || y < 0 || y > map->h-1) return 0;
|
|
|
|
return (tile != TILE_SOLID && tile != TILE_CHARACTER);
|
2021-08-18 02:10:31 +02:00
|
|
|
return 1;
|
2021-08-15 02:42:26 +02:00
|
|
|
}
|
|
|
|
|
2021-08-15 03:10:05 +02:00
|
|
|
/*get the tile under the player*/
|
2021-08-15 03:46:49 +02:00
|
|
|
int map_get_player_tile(struct Game const *game) {
|
2021-08-15 02:42:26 +02:00
|
|
|
return game->map->info_map[game->player->x + game->map->w * game->player->y];
|
2021-08-18 02:10:31 +02:00
|
|
|
return 0;
|
2021-08-15 03:46:49 +02:00
|
|
|
}
|
2021-08-21 02:54:03 +02:00
|
|
|
|
|
|
|
void generate_interior_map(struct Game *game) {
|
|
|
|
extern struct Map in_1;
|
|
|
|
game->map = &in_1;
|
|
|
|
set_player_xy(game->player, 3,3);
|
|
|
|
game->camera->x = in_1.w/2 * TILE_SIZE + game->player->x_mid;
|
|
|
|
game->camera->y = in_1.h/2 * TILE_SIZE + game->player->y_mid;
|
|
|
|
}
|