diff --git a/assets-cg/converters.py b/assets-cg/converters.py index 1620cdf..37a38a5 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -14,16 +14,25 @@ def convert(input, output, params, target): def convert_map(input, output, params, target): TILE_AIR = 0 TILE_SOLID = 1 - TILE_DOOR = 2 - TILE_CHARACTER = 3 + TILE_DOOR_IN = 2 + TILE_DOOR_OUT = 3 + TILE_CHARACTER = 4 TILE_BRIDGE = -1 #only for bridge detection to avoid solid behind with open(input, "r") as jsonData: data = json.load(jsonData) - #find the tileset using the location of the input - tileset = open(input.replace(input.split("/")[-1], "tileset.json"), "r") + #find the tileset in use. it's a relative path (like ../tileset.tsx) + nameTileset = data["tilesets"][0]["source"].replace(".tsx","") + #the name of the tileset without the .something + nameTilesetFree = nameTileset.split("/")[-1] + #count the number of "back" (cd ..) to locate the tileset on the computer + nbRetour = nameTileset.count("..")+1 + #create the tileset absolute path + tilesetPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset.split("/")[-1] + ".json" + + tileset = open(tilesetPath, "r") data_tileset = json.load(tileset) tileset.close() @@ -39,8 +48,10 @@ def convert_map(input, output, params, target): value = TILE_AIR elif type == "solid": value = TILE_SOLID - elif type == "door": - value = TILE_DOOR + elif type == "door_in": + value = TILE_DOOR_IN + elif type == "door_out": + value = TILE_DOOR_OUT elif type == "character": value = TILE_CHARACTER elif type == "bridge": @@ -58,7 +69,7 @@ def convert_map(input, output, params, target): o = fxconv.ObjectData() o += fxconv.u32(w) + fxconv.u32(h) + fxconv.u32(nblayer) - o += fxconv.ref("img_tileset") + o += fxconv.ref(f"img_{nameTilesetFree}") #generation of the collision map (take the maximum of the layer except for bridges) #bridges are always walkable diff --git a/assets-cg/maps/inside/interior_1.tmx b/assets-cg/maps/inside/interior_1.tmx index 977b53f..e8bee6f 100644 --- a/assets-cg/maps/inside/interior_1.tmx +++ b/assets-cg/maps/inside/interior_1.tmx @@ -1,35 +1,49 @@ - + -285,285,285,285,285,285,285,285,285,286,285,285, -285,286,286,286,286,286,286,286,286,286,285,285, -285,286,285,286,286,286,286,286,286,286,285,285, -285,286,285,286,1,1,285,1,39,1,1,1, -285,286,285,1,36,39,1,1,1,33,1,1, -285,286,285,1,1,35,33,1,1,1,1,1, -285,286,285,286,1,30,1,286,285,286,285,285, -285,286,285,286,285,286,285,286,285,286,285,285, -285,286,285,285,285,286,285,286,285,286,285,285, -285,285,752,285,285,285,285,285,285,286,285,285 +2,3,2,1,3,3,2,3,2,1,1,3, +1,6,6,6,1,3,2,3,2,1,2,2, +3,6,6,74,76,1,1,74,76,3,1,1, +1,6,2,103,105,1,1,103,105,1,1,1, +1,6,2,103,105,39,1,103,105,33,1,1, +1,6,1,103,78,75,75,77,105,1,1,1, +2,6,3,132,133,106,107,133,134,1,3,1, +2,3,2,2,1,132,134,3,2,2,1,3, +2,3,2,1,3,2,3,2,2,1,1,3, +1,2,0,1,2,2,2,1,3,3,1,3 -224,225,225,225,225,225,225,225,225,226,0,29, -20,21,0,0,0,0,0,0,0,0,0,58, -49,50,0,0,0,0,0,0,0,0,0,0, +248,249,249,249,249,249,249,249,249,249,249,251, +277,0,0,0,635,636,637,638,0,0,0,280, +277,0,0,0,664,665,666,667,0,0,0,280, +277,0,0,0,693,694,695,696,0,0,0,280, +277,0,0,245,722,723,724,725,245,0,0,280, +277,0,0,274,751,752,753,754,274,0,0,280, +277,0,0,303,0,0,0,0,303,0,0,280, +277,0,0,0,0,0,0,0,0,0,0,280, +277,0,0,0,0,0,0,0,0,0,0,280, +306,307,238,308,250,250,250,250,250,250,250,309 + + + + 0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,24,25,0,0, -0,0,0,0,0,0,0,0,53,54,0,0 +0,0,0,0,0,0,0,0,294,294,294,0, +0,0,0,0,0,0,0,0,0,294,294,0, +0,0,0,0,0,0,0,0,0,294,294,0, +0,0,0,0,0,0,0,0,0,0,294,0, +0,0,0,0,0,0,0,29,0,0,294,0, +0,0,0,0,0,0,0,58,0,0,294,0, +0,0,0,0,0,0,0,0,0,0,294,0, +0,0,0,0,0,0,0,0,0,0,294,0, +0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/assets-cg/maps/inside/tileset.tsx b/assets-cg/maps/inside/tileset.tsx deleted file mode 100644 index 53c4100..0000000 --- a/assets-cg/maps/inside/tileset.tsx +++ /dev/null @@ -1,399 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/assets-cg/maps/tileset.tsx b/assets-cg/maps/tileset.tsx index e00d5ac..502667b 100644 --- a/assets-cg/maps/tileset.tsx +++ b/assets-cg/maps/tileset.tsx @@ -63,6 +63,7 @@ + @@ -190,15 +191,15 @@ - + - + - + diff --git a/assets-cg/tileset.png b/assets-cg/tileset.png index e66d5da..8a20252 100644 Binary files a/assets-cg/tileset.png and b/assets-cg/tileset.png differ diff --git a/include/define.h b/include/define.h index ed752a5..238b73e 100644 --- a/include/define.h +++ b/include/define.h @@ -1,8 +1,4 @@ -/*the x radius the player is able to see*/ -#define PLAYER_VIEW_X 13 -/*the y radius the player is able to see*/ -#define PLAYER_VIEW_Y 8 /*the width of the tileset*/ #define TILESET_WIDTH 29 - +/*the size of one tile*/ #define TILE_SIZE 16 \ No newline at end of file diff --git a/include/map.h b/include/map.h index 0171932..39e542c 100644 --- a/include/map.h +++ b/include/map.h @@ -2,6 +2,7 @@ #include #include "engine.h" +#include struct Map { /*width, height and the number of layer of the map (max 2)*/ @@ -17,8 +18,9 @@ struct Map { enum map_state { TILE_AIR = 0, TILE_SOLID = 1, - TILE_DOOR = 2, - TILE_CHARACTER = 3, + TILE_DOOR_IN = 2, + TILE_DOOR_OUT = 3, + TILE_CHARACTER = 4, }; /*check if a tile is walkable*/ @@ -26,4 +28,6 @@ int map_walkable(struct Map const *map, int x, int y); /*get the tile under the player*/ int map_get_player_tile(struct Game const *game); -void generate_interior_map(struct Game *game); \ No newline at end of file +void generate_interior_map(struct Game *game); + +bool is_map_larger(struct Map *map); \ No newline at end of file diff --git a/src/engine.c b/src/engine.c index f3f3749..cd6c70d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -41,9 +41,15 @@ void engine_draw_map(struct Game const *game) { unsigned int tile_y = TILE_SIZE * (tile_id / TILESET_WIDTH); //provisoire le temps de trouver une manière propre - dsubimage(x * TILE_SIZE - x_offset%TILE_SIZE - game->player->anim.dx * 3, - y * TILE_SIZE - y_offset%TILE_SIZE - game->player->anim.dy * 3, game->map->tileset, - tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE); + if(is_map_larger(game->map)) { + dsubimage(x * TILE_SIZE - x_offset%TILE_SIZE - game->player->anim.dx * 3, + y * TILE_SIZE - y_offset%TILE_SIZE - game->player->anim.dy * 3, game->map->tileset, + tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE); + } else { + dsubimage(x * TILE_SIZE - x_offset%TILE_SIZE, + y * TILE_SIZE - y_offset%TILE_SIZE, game->map->tileset, + tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE); + } } } } @@ -53,14 +59,19 @@ void engine_draw_map(struct Game const *game) { /*draw the player*/ void engine_draw_player(struct Game const *game) { - if(game->map->w > DWIDTH / TILE_SIZE + 1 && - game->map->h > DHEIGHT / TILE_SIZE + 1) { - dframe(game->player->show_x * 16, game->player->show_y * 16 - 5, game->player->anim.img); //draw the player 5 pixel up + if(is_map_larger(game->map)) { + dframe(game->player->show_x * TILE_SIZE, + game->player->show_y * TILE_SIZE - 5, + game->player->anim.img); //draw the player 5 pixel up + } else { - int offset_map_x = (DWIDTH / TILE_SIZE - game->map->w + 1)/2; - int offset_map_y = (DHEIGHT / TILE_SIZE - game->map->h + 1)/2; - dframe((game->player->x + offset_map_x) * 16, - (game->player->y + offset_map_y) * 16 - 5, game->player->anim.img); //draw the player 5 pixel up + const int offset_map_x = (DWIDTH / TILE_SIZE - game->map->w + 1)/2; + const int offset_map_y = (DHEIGHT / TILE_SIZE - game->map->h + 1)/2; + + dframe( + (game->player->x + offset_map_x) * TILE_SIZE + game->player->anim.dx*3, + (game->player->y + offset_map_y) * TILE_SIZE - 5 + game->player->anim.dy*3, + game->player->anim.img); //draw the player 5 pixel up } dprint(1,1,C_BLACK,"%d:%d",game->player->x, game->player->y); } @@ -77,8 +88,7 @@ int engine_move(struct Game *game, int direction) { game->player->x += dx; game->player->y += dy; - if(game->map->w > DWIDTH / TILE_SIZE + 1 && - game->map->h > DHEIGHT / TILE_SIZE + 1) { + if(is_map_larger(game->map)) { game->camera->x += dx*16; game->camera->y += dy*16; } @@ -123,10 +133,11 @@ void engine_action(struct Game const *game, int action) { /*check the current position of the player. To perform action depends of his location*/ void engine_check_position(struct Game *game) { int player_curr_tile = map_get_player_tile(game); - if(player_curr_tile == TILE_DOOR) { + if(player_curr_tile == TILE_DOOR_IN) { engine_set_background(game, C_BLACK); generate_interior_map(game); - } else { + } + if(player_curr_tile == TILE_DOOR_OUT) { engine_set_background(game, C_WHITE); } } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 9b63d8c..e296c15 100644 --- a/src/main.c +++ b/src/main.c @@ -28,8 +28,8 @@ int main(void) { struct Player player = { .x = 32, .y = 30, - .x_mid = 7, - .y_mid = 2, + .x_mid = 6, + .y_mid = 1, .show_x = 12, .show_y = 7, .direction = DIR_DOWN, diff --git a/src/map.c b/src/map.c index faa7330..8572b16 100644 --- a/src/map.c +++ b/src/map.c @@ -24,4 +24,13 @@ void generate_interior_map(struct Game *game) { 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; +} + +/*return true if the map is larger than the screen. false otherwise*/ +bool is_map_larger(struct Map *map) { + if(map->w > DWIDTH / TILE_SIZE + 1 && map->h > DHEIGHT / TILE_SIZE + 1) { + return true; + } else { + return false; + } } \ No newline at end of file