beginning of battle

This commit is contained in:
bgiraudr 2022-01-25 22:20:10 +01:00
parent f922b3839a
commit 99203a1793
11 changed files with 89 additions and 10 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
/*.g3a
*.json
*~
/images
# Python bytecode
__pycache__/

View File

@ -1,3 +1,3 @@
Test capacité;5;2
Test capacité;5;3
Deuxième;10;3
Charge;25;2
Charge;25;15

View File

@ -1,4 +1,11 @@
#pragma once
#include "player.h"
void create_battle(struct Player *player);
void create_battle(struct Player *player);
int during_battle(struct Player *player);
enum battle_state {
EXIT = 0,
LOSE = 1,
WIN = 2,
};

View File

@ -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);
void draw_classic_move(int x, int y, struct Move move);
void execute_move(struct Stats *player_stats, struct Move move);

View File

@ -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);
void replace_capacities(struct Player *player, struct Move move);
void draw_ui(struct Player *player);

View File

@ -6,6 +6,7 @@ struct Stats {
int pv;
int level;
int xp;
int max_pv;
};
void draw_stats(struct Stats stats);

View File

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

View File

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

View File

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

View File

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

View File

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