From bb32aef7ad9fa3f684da486bc6be254b6cb69bdc Mon Sep 17 00:00:00 2001 From: bgiraudr Date: Sun, 23 Jan 2022 00:53:07 +0100 Subject: [PATCH] begin stats --- CMakeLists.txt | 2 + assets-cg/converters.py | 3 + assets-cg/maps/tileset.tsx | 269 +------------------------------------ include/battle.h | 4 + include/game.h | 3 +- include/map.h | 1 + include/player.h | 3 + include/stats.h | 11 ++ src/battle.c | 10 ++ src/engine.c | 7 + src/game.c | 1 + src/player.c | 11 ++ src/stats.c | 16 +++ 13 files changed, 73 insertions(+), 268 deletions(-) create mode 100644 include/battle.h create mode 100644 include/stats.h create mode 100644 src/battle.c create mode 100644 src/stats.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ab1552e..4a99b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,8 @@ set(SOURCES src/player.c src/util.c src/animation.c + src/battle.c + src/stats.c ) set(ASSETS_cg diff --git a/assets-cg/converters.py b/assets-cg/converters.py index e3d09ec..7abd3e6 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -16,6 +16,7 @@ def convert_map(input, output, params, target): TILE_DOOR_OUT = 3 TILE_TALKABLE = 4 TILE_TELEPORTER = 5 + TILE_GRASS = 6 DIALOG_LAYOUT = "dialog" TELEPORTER_LAYOUT = "teleporter" @@ -56,6 +57,8 @@ def convert_map(input, output, params, target): value = TILE_BRIDGE elif type == "teleporter": value = TILE_TELEPORTER + elif type == "grass": + value = TILE_GRASS else: value = TILE_AIR diff --git a/assets-cg/maps/tileset.tsx b/assets-cg/maps/tileset.tsx index 4ea7542..87fcc1e 100644 --- a/assets-cg/maps/tileset.tsx +++ b/assets-cg/maps/tileset.tsx @@ -4,21 +4,6 @@ - - - - - - - - - - - - - - - @@ -30,211 +15,48 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -262,9 +84,6 @@ - - - @@ -276,7 +95,6 @@ - @@ -296,27 +114,19 @@ - - - - - - - + + - - - @@ -325,9 +135,6 @@ - - - @@ -346,7 +153,6 @@ - @@ -354,9 +160,6 @@ - - - @@ -375,17 +178,6 @@ - - - - - - - - - - - @@ -404,75 +196,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/include/battle.h b/include/battle.h new file mode 100644 index 0000000..5171e64 --- /dev/null +++ b/include/battle.h @@ -0,0 +1,4 @@ +#pragma once +#include "player.h" + +void create_battle(struct Player *player); \ No newline at end of file diff --git a/include/game.h b/include/game.h index 515f8fa..7eb42fa 100644 --- a/include/game.h +++ b/include/game.h @@ -19,7 +19,8 @@ enum action { DIR_RIGHT = 3, ACTION_SHIFT = 4, ACTION_ALPHA = 5, - ACTION_F1 = 6 + ACTION_F1 = 6, + ACTION_OPTN = 7 }; /*get the input with a timeout*/ diff --git a/include/map.h b/include/map.h index 5772cab..d7e85fa 100644 --- a/include/map.h +++ b/include/map.h @@ -30,6 +30,7 @@ enum map_state { TILE_DOOR_OUT = 3, TILE_TALKABLE = 4, TILE_TELEPORTER = 5, + TILE_GRASS = 6, }; /*check if a tile is walkable*/ diff --git a/include/player.h b/include/player.h index adf0b00..c9f89dd 100644 --- a/include/player.h +++ b/include/player.h @@ -2,12 +2,15 @@ #include "animation.h" #include "engine.h" #include "vec2.h" +#include "stats.h" struct Player { /*current position of the player on the map - Tile*/ struct Vec2 pos; /*current position of the player on the map - pixels */ struct Vec2f pos_visual; + + struct Stats stats; /*player mid - offset pixels*/ int x_mid, y_mid; /*the direction the player facing to*/ diff --git a/include/stats.h b/include/stats.h new file mode 100644 index 0000000..e33631c --- /dev/null +++ b/include/stats.h @@ -0,0 +1,11 @@ +#pragma once + +struct Stats { + int atk; + int def; + int pv; + int level; + int xp; +}; + +void draw_stats(struct Stats stats); \ No newline at end of file diff --git a/src/battle.c b/src/battle.c new file mode 100644 index 0000000..04dde29 --- /dev/null +++ b/src/battle.c @@ -0,0 +1,10 @@ +#include +#include + +#include "engine.h" +#include "battle.h" +#include "util.h" + +void create_battle(struct Player *player) { + player->stats.level++; +} \ No newline at end of file diff --git a/src/engine.c b/src/engine.c index e84b3d9..f08727d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -10,6 +10,7 @@ #include "talkable.h" #include "camera.h" #include "vec2.h" +#include "battle.h" /*draw the current state of the game*/ void engine_draw(struct Game const *game) { @@ -125,6 +126,9 @@ void engine_action(struct Game const *game, int action) { if(action == ACTION_F1) { game->player->sprint = game->player->sprint ? 0 : 1; } + if(action == ACTION_OPTN) { + draw_stats(game->player->stats); + } } /*check the current position of the player. To perform action depends of his location*/ @@ -155,6 +159,9 @@ void engine_check_position(struct Game *game) { } engine_center_camera(game); } + if(player_curr_tile == TILE_GRASS) { + create_battle(game->player); + } } void engine_center_camera(struct Game *game) { diff --git a/src/game.c b/src/game.c index bd877b2..745d611 100644 --- a/src/game.c +++ b/src/game.c @@ -39,5 +39,6 @@ int get_inputs(void) { if(key == KEY_SHIFT) return ACTION_SHIFT; if(key == KEY_ALPHA) return ACTION_ALPHA; if(key == KEY_F1) return ACTION_F1; + if(key == KEY_OPTN) return ACTION_OPTN; } } diff --git a/src/player.c b/src/player.c index 69884c6..7e014e9 100644 --- a/src/player.c +++ b/src/player.c @@ -1,11 +1,22 @@ #include "player.h" #include "define.h" #include "map.h" +#include "stats.h" struct Player init_player(void) { + + struct Stats stats = { + .atk = 1, + .def = 1, + .level = 1, + .pv = 10, + .xp = 0 + }; + struct Player player = { .pos = VEC2(32, 30), .pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE), + .stats = stats, .x_mid = 6, .y_mid = 1, .show_x = 12, diff --git a/src/stats.c b/src/stats.c new file mode 100644 index 0000000..58fe8b9 --- /dev/null +++ b/src/stats.c @@ -0,0 +1,16 @@ +#include +#include + +#include "stats.h" +#include "util.h" + +void draw_stats(struct Stats stats) { + drect(DWIDTH-110,0,DWIDTH,DHEIGHT,C_WHITE); + dprint(300,20,C_BLACK,"PV : %d",stats.pv); + dprint(300,40,C_BLACK,"Level : %d",stats.level); + dprint(300,60,C_BLACK,"XP : %d",stats.xp); + dprint(300,80,C_BLACK,"ATK : %d",stats.atk); + dprint(300,100,C_BLACK,"DEF : %d",stats.def); + dupdate(); + wait_for_input(KEY_OPTN); +} \ No newline at end of file