diff --git a/include/battle.h b/include/battle.h index 4379902..e011276 100644 --- a/include/battle.h +++ b/include/battle.h @@ -12,4 +12,4 @@ void create_battle(struct Game *game); int 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_executed_move(struct Move move, struct Monster *monster, int is_monster); \ No newline at end of file +void draw_executed_move(struct Move *move, struct Monster *monster, int is_monster); \ No newline at end of file diff --git a/include/capacite.h b/include/capacite.h index 42651f7..e3559ad 100644 --- a/include/capacite.h +++ b/include/capacite.h @@ -14,7 +14,10 @@ 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 execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move move, int ismonster); -int calc_damage(struct Stats *attacker, struct Stats *target, struct Move move); \ No newline at end of file +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 execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move *move, int ismonster); +int calc_damage(struct Stats *attacker, struct Stats *target, struct Move *move); +struct Move *copy_move(struct Move move); + +struct Move *get_move_id2(int id); \ No newline at end of file diff --git a/include/monster.h b/include/monster.h index 7b064ae..275eef2 100644 --- a/include/monster.h +++ b/include/monster.h @@ -14,6 +14,6 @@ struct Monster { }; struct Monster *generate_monster(struct Game *game); -struct Move monster_select(struct Player *player, struct Monster *monster); +struct Move *monster_select(struct Player *player, struct Monster *monster); struct Monster *copyMonster(struct Monster *source); void free_monster(struct Monster *monster); \ No newline at end of file diff --git a/include/player.h b/include/player.h index ecbc7ac..1463a22 100644 --- a/include/player.h +++ b/include/player.h @@ -14,7 +14,7 @@ struct Player { const struct Stats base_stats; struct Stats stats; - struct Move moves[NB_PLAYER_MOVES]; + struct Move *moves[NB_PLAYER_MOVES]; /*player mid - offset pixels*/ int x_mid, y_mid; /*the direction the player facing to*/ diff --git a/src/battle.c b/src/battle.c index 459cfe3..4648271 100644 --- a/src/battle.c +++ b/src/battle.c @@ -71,7 +71,7 @@ int battle(struct Player *player, struct Monster *monster) { return WIN; } - struct Move monster_move = monster_select(player, monster); + struct Move *monster_move = monster_select(player, monster); draw_executed_move(monster_move, monster, 1); dupdate(); wait_for_input(KEY_SHIFT); @@ -107,7 +107,7 @@ int select_move(struct Player *player, struct Monster *monster, int prec_selecte dtext(58 + (selection * 130), DHEIGHT-15 , C_RED, "[X]"); dupdate(); - if(keydown(KEY_SHIFT)) { + if(keydown(KEY_SHIFT) && player->moves[selection]->pp > 0) { if(buffer) buffer = 0; else break; } @@ -145,12 +145,12 @@ void draw_battle(struct Player *player, struct Monster *monster) { dimage(265,10,monster->sprite); } -void draw_executed_move(struct Move move, struct Monster *monster, int is_monster) { +void draw_executed_move(struct Move *move, struct Monster *monster, int is_monster) { extern bopti_image_t img_dialogue; dimage(42,DHEIGHT-75,&img_dialogue); if(is_monster) { - dprint(50,DHEIGHT-75/2-10, C_BLACK, "%s lance %s !", monster->name, move.name); + dprint(50,DHEIGHT-75/2-10, C_BLACK, "%s lance %s !", monster->name, move->name); } else { - dprint(50,DHEIGHT-75/2-10, C_BLACK, "Vous lancez %s !", move.name); + dprint(50,DHEIGHT-75/2-10, C_BLACK, "Vous lancez %s !", move->name); } } \ No newline at end of file diff --git a/src/capacite.c b/src/capacite.c index f31d34a..b5b7a9c 100644 --- a/src/capacite.c +++ b/src/capacite.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "capacite.h" @@ -15,29 +16,44 @@ struct Move get_move_id(int id) { return *capacities.moves[id]; } -void draw_move(int x, int y, int x2, int y2, struct Move move) { +struct Move *get_move_id2(int id) { + return capacities.moves[id]; +} + +struct Move *copy_move(struct Move move) { + struct Move *copyMove = malloc(sizeof(struct Move)); + copyMove->name = move.name; + copyMove->pp = move.pp; + copyMove->atk = move.atk; + + return copyMove; +} + +void draw_move(int x, int y, int x2, int y2, struct Move *move) { extern bopti_image_t img_capacite; const int font_size = 8; dimage(x, y, &img_capacite); - dprint(x+15, y+5, C_BLACK, "PP : %d", move.pp); - dprint(x+15, y2-20, C_BLACK, "ATK : %d", move.atk); - dprint((int)((x+x2)/2)-(int)(strlen(move.name)/2*font_size), + int color = move->pp > 0 ? C_BLACK : C_RED; + dprint(x+15, y+5, color, "PP : %d", move->pp); + dprint(x+15, y2-20, C_BLACK, "ATK : %d", move->atk); + dprint((int)((x+x2)/2)-(int)(strlen(move->name)/2*font_size), (int)((y+y2)/2)-font_size/2, - C_BLACK, "%s", move.name); + C_BLACK, "%s", move->name); } -void draw_classic_move(int x, int y, struct Move move) { +void draw_classic_move(int x, int y, struct Move *move) { draw_move(x, y, x+125, y+60, move); } -void execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move move, int ismonster) { +void execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move *move, int ismonster) { if(ismonster) { player_stats->pv-=calc_damage(monster_stats, player_stats, move); } else { + move->pp--; monster_stats->pv-=calc_damage(player_stats, monster_stats, move); } } -int calc_damage(struct Stats *attacker, struct Stats *target, struct Move move) { - return(floor(((2*attacker->level / 5 + 2) * attacker->atk * move.atk / target->def) / 50) + 2); +int calc_damage(struct Stats *attacker, struct Stats *target, struct Move *move) { + return(floor(((2*attacker->level / 5 + 2) * attacker->atk * move->atk / target->def) / 50) + 2); } \ No newline at end of file diff --git a/src/monster.c b/src/monster.c index e24358b..a2103c5 100644 --- a/src/monster.c +++ b/src/monster.c @@ -18,12 +18,12 @@ struct Monster *generate_monster(struct Game *game) { return monster; } -struct Move monster_select(struct Player *player, struct Monster *monster) { - struct Move stoMove = get_move_id(monster->moves[0]); +struct Move *monster_select(struct Player *player, struct Monster *monster) { + struct Move *stoMove = get_move_id2(monster->moves[0]); int stoDamage = 0; for(int i = 0; i < monster->nbMoves; i++) { - struct Move move = get_move_id(monster->moves[i]); + struct Move *move = get_move_id2(monster->moves[i]); int damage = calc_damage(monster->stats, &player->stats, move); if(damage >= player->stats.pv) { return move; diff --git a/src/player.c b/src/player.c index e5fde92..491d6ca 100644 --- a/src/player.c +++ b/src/player.c @@ -1,4 +1,5 @@ #include +#include #include "player.h" #include "define.h" @@ -35,7 +36,7 @@ struct Player init_player(void) { .anim.dir = DIR_DOWN }; player.idle = !anim_player_idle(&player.anim, 1); - player.moves[0] = default_move(); + player.moves[0] = copy_move(default_move()); set_stats_level_from(&player.base_stats, &player.stats); return player; @@ -62,7 +63,7 @@ int player_facing(struct Game const *game) { int get_nb_moves(struct Player *player) { for(int i = 0; i < NB_PLAYER_MOVES; i++) { - if(player->moves[i].name == NULL) { + if(player->moves[i] == NULL) { return i; } } @@ -71,7 +72,7 @@ int get_nb_moves(struct Player *player) { void add_move(struct Player *player, struct Move move) { int index = get_nb_moves(player); - if(index != NB_PLAYER_MOVES) player->moves[index] = move; + if(index != NB_PLAYER_MOVES) player->moves[index] = copy_move(move); else replace_capacities(player, move); } @@ -92,7 +93,7 @@ void replace_capacities(struct Player *player, struct Move move) { if(selection > NB_PLAYER_MOVES-1) selection = NB_PLAYER_MOVES-1; if(selection < 0) selection = 0; - draw_classic_move(200,DHEIGHT/2-30, move); + // draw_classic_move(200,DHEIGHT/2-30, move); for(int i = 0; i < NB_PLAYER_MOVES; i++) { draw_classic_move(0,65*i, player->moves[i]); } @@ -111,7 +112,8 @@ void replace_capacities(struct Player *player, struct Move move) { while(keydown_any(KEY_DOWN,KEY_UP, KEY_SHIFT,0)) clearevents(); } if(selection >= 0) { - player->moves[selection] = move; + free(player->moves[selection]); + player->moves[selection] = copy_move(move); } }