diff --git a/.gitignore b/.gitignore index e0ea0c7..00945df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /*.g3a *.json *~ +/images # Python bytecode __pycache__/ diff --git a/assets-cg/capacites/capacites.txt b/assets-cg/capacites/capacites.txt index 175a12a..76c1c0f 100644 --- a/assets-cg/capacites/capacites.txt +++ b/assets-cg/capacites/capacites.txt @@ -1,3 +1,3 @@ -Test capacité;5;2 +Test capacité;5;3 Deuxième;10;3 -Charge;25;2 +Charge;25;15 diff --git a/include/battle.h b/include/battle.h index 5171e64..20378e9 100644 --- a/include/battle.h +++ b/include/battle.h @@ -1,4 +1,11 @@ #pragma once #include "player.h" -void create_battle(struct Player *player); \ No newline at end of file +void create_battle(struct Player *player); +int during_battle(struct Player *player); + +enum battle_state { + EXIT = 0, + LOSE = 1, + WIN = 2, +}; \ No newline at end of file diff --git a/include/capacite.h b/include/capacite.h index 9c6cda8..ff26230 100644 --- a/include/capacite.h +++ b/include/capacite.h @@ -1,4 +1,5 @@ #pragma once +#include "stats.h" struct Move { char *name; @@ -14,4 +15,5 @@ struct Capacities { struct Move default_move(); struct Move get_move_id(int id); void draw_move(int x, int y, int x2, int y2, struct Move move); -void draw_classic_move(int x, int y, struct Move move); \ No newline at end of file +void draw_classic_move(int x, int y, struct Move move); +void execute_move(struct Stats *player_stats, struct Move move); \ No newline at end of file diff --git a/include/player.h b/include/player.h index df3012d..d98b9e9 100644 --- a/include/player.h +++ b/include/player.h @@ -34,4 +34,5 @@ int player_facing(struct Game const *game); struct Player init_player(void); void add_move(struct Player *player, struct Move move); void draw_player_moves(struct Player *player); -void replace_capacities(struct Player *player, struct Move move); \ No newline at end of file +void replace_capacities(struct Player *player, struct Move move); +void draw_ui(struct Player *player); \ No newline at end of file diff --git a/include/stats.h b/include/stats.h index e33631c..0d51090 100644 --- a/include/stats.h +++ b/include/stats.h @@ -6,6 +6,7 @@ struct Stats { int pv; int level; int xp; + int max_pv; }; void draw_stats(struct Stats stats); \ No newline at end of file diff --git a/src/battle.c b/src/battle.c index f2dcf4f..37c3c82 100644 --- a/src/battle.c +++ b/src/battle.c @@ -8,6 +8,47 @@ #include "player.h" void create_battle(struct Player *player) { - player->stats.level++; - add_move(player, get_move_id(1)); + player->stats.pv = player->stats.max_pv; + during_battle(player); +} + +int during_battle(struct Player *player) { + int tour = 0; + + int selection = 0; + while(1) { + int buffer = keydown(KEY_SHIFT); + while(1) { + clearevents(); + + if(player->moves[1].name != NULL) { + selection += keydown(KEY_RIGHT) - keydown(KEY_LEFT); + } + + if(selection > 1) selection = 1; + if(selection < 0) selection = 0; + + dclear(C_RGB(25,25,25)); + draw_ui(player); + dtext(95 + (selection * 190), DHEIGHT-15 , C_RED, "[X]"); + dupdate(); + + if(keydown(KEY_SHIFT)) { + if(buffer) buffer = 0; + else break; + } + if(keydown(KEY_EXIT)) { + player->stats.pv--; + break; + } + while(keydown(KEY_SHIFT)) clearevents(); + } + + execute_move(&player->stats, player->moves[selection]); + if(player->stats.pv <= 0) { + return LOSE; + } + tour++; + } + return LOSE; } \ No newline at end of file diff --git a/src/capacite.c b/src/capacite.c index ca35f74..e1d5bc4 100644 --- a/src/capacite.c +++ b/src/capacite.c @@ -26,4 +26,8 @@ void draw_move(int x, int y, int x2, int y2, struct Move move) { void draw_classic_move(int x, int y, struct Move move) { draw_move(x, y, x+170, y+60, move); +} + +void execute_move(struct Stats *player_stats, struct Move move) { + player_stats->pv-=move.atk; } \ No newline at end of file diff --git a/src/engine.c b/src/engine.c index 416a456..4c583cd 100644 --- a/src/engine.c +++ b/src/engine.c @@ -128,6 +128,7 @@ void engine_action(struct Game const *game, int action) { if(action == ACTION_F1) { game->player->sprint = game->player->sprint ? 0 : 1; add_move(game->player, get_move_id(2)); + game->player->stats.max_pv=150; } if(action == ACTION_OPTN) { draw_stats(game->player->stats); diff --git a/src/main.c b/src/main.c index 19b0091..c391eea 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,12 @@ static int callback_tick(volatile int *tick) { return TIMER_CONTINUE; } +void take_capture(void) { + if (keydown(KEY_VARS) && usb_is_open()) { + usb_fxlink_screenshot(1); + } +} + int main(void) { /*Structure definition*/ struct Player player = init_player(); @@ -33,6 +39,8 @@ int main(void) { extern font_t uf8x9; dfont(&uf8x9); + dupdate_set_hook(GINT_CALL(take_capture)); + /*Main loop*/ while(!keydown(KEY_MENU)) { while(!tick) sleep(); @@ -40,8 +48,6 @@ int main(void) { engine_draw(&game); dupdate(); - if (keydown(KEY_VARS) && usb_is_open()) - usb_fxlink_screenshot(1); int action = get_inputs(); if(action >= 0 && action <= 3) diff --git a/src/player.c b/src/player.c index beb39ed..d13542f 100644 --- a/src/player.c +++ b/src/player.c @@ -14,7 +14,8 @@ struct Player init_player(void) { .def = 1, .level = 1, .pv = 10, - .xp = 0 + .xp = 0, + .max_pv = 10, }; struct Player player = { @@ -99,4 +100,18 @@ void replace_capacities(struct Player *player, struct Move move) { if(selection >= 0) { player->moves[selection] = move; } +} + +void draw_ui(struct Player *player) { + draw_classic_move(20,DHEIGHT-80, player->moves[0]); + if(player->moves[1].name != NULL) { + draw_classic_move(210,DHEIGHT-80, player->moves[1]); + } + + const int WIDTH_HP = 100; + int posHP = (float)player->stats.pv / player->stats.max_pv * WIDTH_HP; + drect(10,10,10+WIDTH_HP,20,C_BLACK); + drect(10,10,10+posHP,20,C_GREEN); + + dprint(15+WIDTH_HP,10,C_BLACK,"%d/%d", player->stats.pv, player->stats.max_pv); } \ No newline at end of file