diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a99b9c..8e1d2c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ set(SOURCES src/animation.c src/battle.c src/stats.c + src/capacite.c ) set(ASSETS_cg @@ -53,6 +54,7 @@ set(ASSETS_cg assets-cg/maps/inside/2.json assets-cg/spritesheet.png assets-cg/uf8x9 + assets-cg/capacites/capacites.txt ) fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) diff --git a/assets-cg/capacites/capacites.txt b/assets-cg/capacites/capacites.txt new file mode 100644 index 0000000..363d7ae --- /dev/null +++ b/assets-cg/capacites/capacites.txt @@ -0,0 +1,2 @@ +Test capacité;5;2 +Deuxième;10;3 diff --git a/assets-cg/capacites/fxconv-metadata.txt b/assets-cg/capacites/fxconv-metadata.txt new file mode 100644 index 0000000..f1fd406 --- /dev/null +++ b/assets-cg/capacites/fxconv-metadata.txt @@ -0,0 +1,3 @@ +capacites.txt: + custom-type: capacites + name: capacites diff --git a/assets-cg/converters.py b/assets-cg/converters.py index 7abd3e6..b50f90b 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -5,6 +5,9 @@ def convert(input, output, params, target): if params["custom-type"] == "map": convert_map(input, output, params, target) return 0 + elif params["custom-type"] == "capacites": + convert_capa(input, output, params, target) + return 0 else: return 1 @@ -160,4 +163,25 @@ def parseTeleporter(layer): teleporter += fxconv.u32(j["value"]) except KeyError : raise Exception("parseTeleporter() : Un téléporteur est mal configuré") - return teleporter \ No newline at end of file + return teleporter + +def convert_capa(input, output, params, target): + with open(input, "r") as file: + capacities = fxconv.Structure() + + lines = file.read().splitlines() + matrix = [i.split(";") for i in lines] + + capacities += fxconv.u32(len(lines)) + + for i in matrix: + moves = fxconv.Structure() + for j in range(len(i)): + if j == 0: + moves += fxconv.string(i[j]) + else: + moves += fxconv.u32(int(i[j])) + + capacities += fxconv.ptr(moves) + + fxconv.elf(capacities, output, "_" + params["name"], **target) diff --git a/include/capacite.h b/include/capacite.h new file mode 100644 index 0000000..29083a3 --- /dev/null +++ b/include/capacite.h @@ -0,0 +1,15 @@ +#pragma once + +struct Move { + char *name; + int pp; + int atk; +}; + +struct Capacites { + int nbCapacites; + struct Move *moves[]; +}; + +struct Move default_move(); +struct Move get_move_id(int id); \ No newline at end of file diff --git a/include/player.h b/include/player.h index c9f89dd..8ccfb8c 100644 --- a/include/player.h +++ b/include/player.h @@ -3,6 +3,8 @@ #include "engine.h" #include "vec2.h" #include "stats.h" +#include "capacite.h" + struct Player { /*current position of the player on the map - Tile*/ @@ -11,6 +13,7 @@ struct Player { struct Vec2f pos_visual; struct Stats stats; + struct Move moves[2]; /*player mid - offset pixels*/ int x_mid, y_mid; /*the direction the player facing to*/ @@ -29,3 +32,4 @@ struct Player { /*return the info tile value the player is facing to*/ int player_facing(struct Game const *game); struct Player init_player(void); +void add_move(struct Player *player, struct Move move); \ No newline at end of file diff --git a/src/battle.c b/src/battle.c index 04dde29..ab2431b 100644 --- a/src/battle.c +++ b/src/battle.c @@ -4,7 +4,15 @@ #include "engine.h" #include "battle.h" #include "util.h" +#include "capacite.h" +#include "player.h" void create_battle(struct Player *player) { player->stats.level++; + drect(DWIDTH-110,0,DWIDTH,DHEIGHT,C_WHITE); + dprint(300,20,C_BLACK,"%s",player->moves[0].name); + dprint(300,40,C_BLACK,"%s",player->moves[1].name); + dupdate(); + wait_for_input(KEY_SHIFT); + add_move(player, get_move_id(1)); } \ No newline at end of file diff --git a/src/capacite.c b/src/capacite.c new file mode 100644 index 0000000..3b5d9ac --- /dev/null +++ b/src/capacite.c @@ -0,0 +1,20 @@ +#include "capacite.h" + +#include +#include + +#include "engine.h" +#include "battle.h" +#include "util.h" +#include "capacite.h" +#include "player.h" + +extern struct Capacites capacites; + +struct Move default_move() { + return *capacites.moves[0]; +} + +struct Move get_move_id(int id) { + return *capacites.moves[id]; +} \ No newline at end of file diff --git a/src/engine.c b/src/engine.c index f08727d..2955bd3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -11,6 +11,7 @@ #include "camera.h" #include "vec2.h" #include "battle.h" +#include "capacite.h" /*draw the current state of the game*/ void engine_draw(struct Game const *game) { diff --git a/src/player.c b/src/player.c index 7e014e9..8575050 100644 --- a/src/player.c +++ b/src/player.c @@ -2,6 +2,7 @@ #include "define.h" #include "map.h" #include "stats.h" +#include "capacite.h" struct Player init_player(void) { @@ -26,6 +27,7 @@ struct Player init_player(void) { .anim.dir = DIR_DOWN }; player.idle = !anim_player_idle(&player.anim, 1); + player.moves[0] = default_move(); return player; } @@ -47,4 +49,12 @@ int player_facing(struct Game const *game) { return game->map->info_map[index]; } return TILE_SOLID; +} + +void add_move(struct Player *player, struct Move move) { + if(player->moves[1].name == NULL) { + player->moves[1] = move; + } else { + //TODO remplacer une capacité + } } \ No newline at end of file