diff --git a/assets-cg/converters.py b/assets-cg/converters.py index 884df81..db411d3 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -22,6 +22,7 @@ def convert_map(input, output, params, target): 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") data_tileset = json.load(tileset) tileset.close() @@ -29,6 +30,7 @@ def convert_map(input, output, params, target): tile_value = {} info_map = bytearray() + #create a dictionnary between tile-type for i in data_tileset["tiles"]: try: id = i["id"]+1 @@ -51,6 +53,7 @@ def convert_map(input, output, params, target): except KeyError: pass + #Extract from the json the width, height and layers of the map w = data["layers"][0]["width"] h = data["layers"][0]["height"] nblayer = len(data["layers"]) @@ -59,7 +62,9 @@ def convert_map(input, output, params, target): o += fxconv.u32(w) + fxconv.u32(h) + fxconv.u32(nblayer) o += fxconv.ref("img_tileset") + #To preserve performance, max 2 layers if(nblayer <= 2): + #generate the array of tiles from the layer for i in range(nblayer): tiles = data["layers"][i]["data"] @@ -69,6 +74,7 @@ def convert_map(input, output, params, target): o += fxconv.ref(byte_tiles) #generation of the collision map (take the maximum of the layer except for bridges) + #bridges is always walkable for x in range(w*h): value1 = tile_value.get(data["layers"][0]["data"][x]) if(nblayer >= 2): @@ -81,10 +87,10 @@ def convert_map(input, output, params, target): if value1 == TILE_BRIDGE: value1 = TILE_AIR info_map += bytearray(fxconv.u16(value1)) o += fxconv.ref(info_map) - else: raise fxconv.FxconvError(f"There is too much layer ! {nblayer} found for a max of 2") + #generate ! fxconv.elf(o, output, "_" + params["name"], **target) def convert_character(input, output, params, target): @@ -93,8 +99,7 @@ def convert_character(input, output, params, target): o = fxconv.ObjectData() o += fxconv.u32((int)(file[0])) + fxconv.u32((int)(file[1])) - o += fxconv.ref(bytes(file[2], 'utf-8') + bytes(1)) + o += fxconv.ref(bytes(file[2], 'utf-8') + bytes(1)) #bytes(1) is necessary to end a char o += fxconv.ref(bytes(file[3], 'utf-8') + bytes(1)) - fxconv.elf(o, output, "_" + params["name"], **target) \ No newline at end of file diff --git a/include/animation.h b/include/animation.h index d545d81..cb8ec8e 100644 --- a/include/animation.h +++ b/include/animation.h @@ -33,6 +33,9 @@ struct anim_data int duration; }; +/*draw the frame*/ void dframe(int x, int y, struct anim_frame const frame); +/*animation for player walking*/ int anim_player_walking(struct anim_data *data, int init); +/*animation for player doing nothing*/ int anim_player_idle(struct anim_data *data, int init); \ No newline at end of file diff --git a/include/character.h b/include/character.h index 889926b..4bf4bbd 100644 --- a/include/character.h +++ b/include/character.h @@ -9,6 +9,9 @@ struct character { char *dialog; }; +/*draw the dialog of a specified character*/ void draw_dialog(struct character *character); +/*find the character using the player's position*/ struct character* get_character_xy(struct character *characters[], int x, int y); +/*get the characters for a specified map*/ struct character** get_map_characters(int id); \ No newline at end of file diff --git a/include/engine.h b/include/engine.h index f9f3aac..ba14751 100644 --- a/include/engine.h +++ b/include/engine.h @@ -13,11 +13,19 @@ struct game { int background; }; +/*draw the current state of the game*/ void engine_draw(struct game const *game); +/*draw the map around the player*/ void engine_draw_map_around_player(struct game const *game); +/*draw the player*/ void engine_draw_player(struct player const *player); +/*move the player to the direction*/ int engine_move(struct game *game, int direction); +/*update the player animation*/ void engine_tick(struct game *game, int dt); +/*set the background color*/ void engine_set_background(struct game *game, int color); +/*make an interaction with something*/ 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); \ No newline at end of file diff --git a/include/game.h b/include/game.h index aaa67b4..53c3bc4 100644 --- a/include/game.h +++ b/include/game.h @@ -1,5 +1,6 @@ #pragma once +/*get the input with a timeout*/ int get_inputs(void); enum direction { diff --git a/include/map.h b/include/map.h index cfdb9f1..ff7496c 100644 --- a/include/map.h +++ b/include/map.h @@ -23,5 +23,7 @@ enum map_state { TILE_CHARACTER = 3, }; +/*check if a tile is walkable*/ 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); \ No newline at end of file diff --git a/src/character.c b/src/character.c index e6b4ef3..0cf0254 100644 --- a/src/character.c +++ b/src/character.c @@ -40,6 +40,7 @@ struct character* get_character_xy(struct character *characters[], int x, int y) return &character_default; } +/*get the characters for a specified map*/ struct character** get_map_characters(int id) { if(id == 1) { extern struct character character_Tituya; diff --git a/src/engine.c b/src/engine.c index 51c03fe..1941414 100644 --- a/src/engine.c +++ b/src/engine.c @@ -144,6 +144,7 @@ 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) { diff --git a/src/map.c b/src/map.c index f461f11..1b1cde1 100644 --- a/src/map.c +++ b/src/map.c @@ -9,6 +9,7 @@ int map_walkable(struct map const *map, int x, int y) { return (tile != TILE_SOLID && tile != TILE_CHARACTER); } +/*get the tile under the player*/ int map_get_player_tile(struct game const *game) { return game->map->info_map[game->player->x + game->map->w * game->player->y]; } \ No newline at end of file