update stats depends of level

This commit is contained in:
bgiraudr 2022-02-13 21:46:52 +01:00
parent 68f80917d6
commit 0dcb6cc235
10 changed files with 57 additions and 17 deletions

View File

@ -1,3 +1,4 @@
Test capacité;5;3
Deuxième;100;11
Charge;25;15
Cheat;25;45

View File

@ -16,4 +16,5 @@ 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);
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);

View File

@ -12,6 +12,7 @@ struct Player {
/*current position of the player on the map - pixels */
struct Vec2f pos_visual;
const struct Stats base_stats;
struct Stats stats;
struct Move moves[NB_PLAYER_MOVES];
/*player mid - offset pixels*/

View File

@ -9,4 +9,7 @@ struct Stats {
int max_pv;
};
void draw_stats(struct Stats stats);
void draw_stats(struct Stats stats);
void set_stats_level(struct Stats *stats);
int calc_stats(int base, int level);
void set_stats_level_from(const struct Stats *from, struct Stats *to);

View File

@ -28,7 +28,7 @@ void create_battle(struct Game *game) {
game->player->stats.xp += xp;
//niveau suivant une progession N³
int calc_level = (int)pow(game->player->stats.xp, 0.34);
int calc_level = (int)pow(game->player->stats.xp, 0.33);
for(int i = game->player->stats.level; i < calc_level; i++) {
dclear(C_RGB(25,25,25));
draw_battle(game->player, monster);
@ -38,6 +38,7 @@ void create_battle(struct Game *game) {
wait_for_input(KEY_SHIFT);
}
game->player->stats.level = calc_level;
set_stats_level_from(&game->player->base_stats, &game->player->stats);
} else if(status == LOSE) {
game->player->stats.pv = 0;

View File

@ -1,6 +1,7 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <string.h>
#include <math.h>
#include "capacite.h"
@ -30,8 +31,12 @@ 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) {
if(ismonster) {
player_stats->pv-=move.atk;
player_stats->pv-=calc_damage(monster_stats, player_stats, move);
} else {
monster_stats->pv-=move.atk;
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);
}

View File

@ -127,8 +127,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;
add_move(game->player, get_move_id(3));
}
if(action == ACTION_OPTN) {
draw_stats(game->player->stats);

View File

@ -1,9 +1,10 @@
#include <string.h>
#include <stdlib.h>
#include "monster.h"
#include "stats.h"
#include "capacite.h"
#include "player.h"
#include <string.h>
#include <stdlib.h>
struct Monster *generate_monster(struct Game *game) {
@ -12,18 +13,24 @@ struct Monster *generate_monster(struct Game *game) {
struct Monster *monster = copyMonster(&monster_test);
// TODO formule pour niveau du monstre adverse
monster->stats->level = game->player->stats.level;
set_stats_level(monster->stats);
monster->stats->pv = monster->stats->max_pv;
return monster;
}
struct Move monster_select(struct Player *player, struct Monster *monster) {
struct Move stoMove = get_move_id(monster->moves[0]);
int stoDamage = 0;
for(int i = 0; i < monster->nbMoves; i++) {
struct Move move = get_move_id(monster->moves[i]);
if(move.atk >= player->stats.pv) {
int damage = calc_damage(monster->stats, &player->stats, move);
if(damage >= player->stats.pv) {
return move;
}
if(move.atk > stoMove.atk) {
if(damage > stoDamage) {
stoMove = move;
stoDamage = damage;
}
}
return stoMove;

View File

@ -9,18 +9,22 @@
struct Player init_player(void) {
struct Stats stats = {
.atk = 1,
.def = 1,
struct Stats bstats = {
.atk = 15,
.def = 15,
.level = 1,
.pv = 10,
.xp = 0,
.max_pv = 10,
.pv = 30,
};
struct Stats stats = {
.level = 1,
.xp = 0
};
struct Player player = {
.pos = VEC2(32, 30),
.pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
.base_stats = bstats,
.stats = stats,
.x_mid = 6,
.y_mid = 1,
@ -33,6 +37,7 @@ struct Player init_player(void) {
player.idle = !anim_player_idle(&player.anim, 1);
player.moves[0] = default_move();
set_stats_level_from(&player.base_stats, &player.stats);
return player;
}

View File

@ -1,5 +1,6 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <math.h>
#include "stats.h"
#include "util.h"
@ -11,4 +12,20 @@ void draw_stats(struct Stats stats) {
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);
}
void set_stats_level_from(const struct Stats *from, struct Stats *to) {
to->max_pv = calc_stats(from->pv, to->level);
to->atk = calc_stats(from->atk, to->level);
to->def = calc_stats(from->def, to->level);
}
void set_stats_level(struct Stats *stats) {
stats->max_pv = calc_stats(stats->pv, stats->level);
stats->atk = calc_stats(stats->atk, stats->level);
stats->def = calc_stats(stats->def, stats->level);
}
int calc_stats(int base, int level) {
return (int)(((2*base + level/4 + 100) * level)/100+10);
}