mirror of https://github.com/bgiraudr/Adoranda.git
generate monster from json
This commit is contained in:
parent
eb626a5d53
commit
66a80f534e
|
@ -57,6 +57,7 @@ set(ASSETS_cg
|
|||
assets-cg/uf8x9
|
||||
assets-cg/capacites/capacites.txt
|
||||
assets-cg/monsters/test.png
|
||||
assets-cg/monsters/test.json
|
||||
)
|
||||
|
||||
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
Test capacité;5;3
|
||||
Deuxième;10;3
|
||||
Deuxième;100;100
|
||||
Charge;25;15
|
||||
|
|
|
@ -8,6 +8,9 @@ def convert(input, output, params, target):
|
|||
elif params["custom-type"] == "capacities":
|
||||
convert_capa(input, output, params, target)
|
||||
return 0
|
||||
elif params["custom-type"] == "monster":
|
||||
convert_monster(input, output, params, target)
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
@ -185,3 +188,24 @@ def convert_capa(input, output, params, target):
|
|||
capacities += fxconv.ptr(moves)
|
||||
|
||||
fxconv.elf(capacities, output, "_" + params["name"], **target)
|
||||
|
||||
def convert_monster(input, output, params, target):
|
||||
file = open(input, "r")
|
||||
data = json.load(file)
|
||||
|
||||
stats = fxconv.Structure()
|
||||
if len(data["stats"]) != 6: raise Exception(f"convert_monster : Les statistiques de {data['name']} sont mauvaises")
|
||||
for i in data["stats"].values():
|
||||
stats+=fxconv.u32(i)
|
||||
|
||||
moves = bytes()
|
||||
for i in data["moves"]:
|
||||
moves+=fxconv.u16(i)
|
||||
|
||||
monster = fxconv.Structure()
|
||||
monster += fxconv.string(data["name"])
|
||||
monster += fxconv.ptr(f"img_{data['sprite']}")
|
||||
monster += fxconv.ptr(stats)
|
||||
monster += fxconv.ptr(moves)
|
||||
|
||||
fxconv.elf(monster, output, "_" + params["name"], **target)
|
||||
|
|
|
@ -2,3 +2,6 @@ test.png:
|
|||
type: bopti-image
|
||||
name: img_test
|
||||
|
||||
*.json:
|
||||
custom-type: monster
|
||||
name_regex: (.*)\.json monster_\1
|
||||
|
|
|
@ -11,4 +11,5 @@ enum battle_state {
|
|||
void create_battle(struct Game *game);
|
||||
int during_battle(struct Player *player, struct Monster monster);
|
||||
int select_move(struct Player *player, struct Monster *monster, int prec_selected);
|
||||
void draw_battle(struct Player *player, struct Monster *monster);
|
||||
void draw_battle(struct Player *player, struct Monster *monster);
|
||||
void draw_executed_move(struct Move move, struct Monster *monster, int is_monster);
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
struct Monster {
|
||||
char *name;
|
||||
struct Stats stats;
|
||||
struct Move moves[NB_PLAYER_MOVES];
|
||||
bopti_image_t *sprite;
|
||||
struct Stats *stats;
|
||||
short *moves;
|
||||
};
|
||||
|
||||
struct Monster generate_monster(struct Game *game);
|
21
src/battle.c
21
src/battle.c
|
@ -21,11 +21,13 @@ int during_battle(struct Player *player, struct Monster monster) {
|
|||
draw_battle(player, &monster);
|
||||
dupdate();
|
||||
selection = select_move(player, &monster, selection);
|
||||
execute_move(&player->stats, &monster.stats, player->moves[selection]);
|
||||
draw_executed_move(player->moves[selection], &monster, 0);
|
||||
wait_for_input(KEY_SHIFT);
|
||||
execute_move(&player->stats, monster.stats, player->moves[selection]);
|
||||
if(player->stats.pv <= 0) {
|
||||
return LOSE;
|
||||
}
|
||||
if(monster.stats.pv <= 0) {
|
||||
if(monster.stats->pv <= 0) {
|
||||
return WIN;
|
||||
}
|
||||
tour++;
|
||||
|
@ -73,11 +75,22 @@ void draw_battle(struct Player *player, struct Monster *monster) {
|
|||
|
||||
dprint(15+WIDTH_HP,15,C_BLACK,"%d/%d", player->stats.pv, player->stats.max_pv);
|
||||
|
||||
int posHPmonster = (float)monster->stats.pv / monster->stats.max_pv * WIDTH_HP;
|
||||
int posHPmonster = (float)monster->stats->pv / monster->stats->max_pv * WIDTH_HP;
|
||||
dtext(240,2,C_BLACK,monster->name);
|
||||
drect(240,15,240+WIDTH_HP,25,C_BLACK);
|
||||
drect(240,15,240+posHPmonster,25,C_GREEN);
|
||||
|
||||
dprint(245+WIDTH_HP,15,C_BLACK,"%d/%d", monster->stats.pv, monster->stats.max_pv);
|
||||
dprint(245+WIDTH_HP,15,C_BLACK,"%d/%d", monster->stats->pv, monster->stats->max_pv);
|
||||
dimage(260,30,monster->sprite);
|
||||
}
|
||||
|
||||
void draw_executed_move(struct Move move, struct Monster *monster, int is_monster) {
|
||||
const int rect_size = 100;
|
||||
drect(0,DHEIGHT,DWIDTH,DHEIGHT-rect_size,C_WHITE);
|
||||
if(is_monster) {
|
||||
dprint(10,DHEIGHT-rect_size/2-8, C_BLACK, "%s lance %s !", monster->name, move.name);
|
||||
} else {
|
||||
dprint(10,DHEIGHT-rect_size/2-8, C_BLACK, "Vous lancez %s !", move.name);
|
||||
}
|
||||
dupdate();
|
||||
}
|
|
@ -29,6 +29,6 @@ void draw_classic_move(int x, int y, struct Move move) {
|
|||
}
|
||||
|
||||
void execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move move) {
|
||||
// player_stats->pv-=move.atk;
|
||||
monster_stats->pv-=move.atk;
|
||||
player_stats->pv-=move.atk;
|
||||
//monster_stats->pv-=move.atk;
|
||||
}
|
|
@ -4,25 +4,6 @@
|
|||
|
||||
struct Monster generate_monster(struct Game *game) {
|
||||
|
||||
extern bopti_image_t img_test;
|
||||
|
||||
struct Stats s = {
|
||||
.atk=10,
|
||||
.def=10,
|
||||
.pv=20,
|
||||
.level=1,
|
||||
.max_pv=20,
|
||||
};
|
||||
|
||||
struct Monster m = {
|
||||
.name="pas content",
|
||||
.stats = s,
|
||||
.sprite = &img_test,
|
||||
};
|
||||
|
||||
m.moves[0] = get_move_id(0);
|
||||
m.moves[1] = get_move_id(1);
|
||||
m.moves[2] = get_move_id(2);
|
||||
|
||||
return m;
|
||||
extern struct Monster monster_test;
|
||||
return monster_test;
|
||||
}
|
Loading…
Reference in New Issue