Some comments

This commit is contained in:
bgiraudr 2021-08-15 03:10:05 +02:00
parent 144ba20042
commit a8edfa9091
9 changed files with 28 additions and 3 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -1,5 +1,6 @@
#pragma once
/*get the input with a timeout*/
int get_inputs(void);
enum direction {

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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];
}