From 6dc08b8a6b2c5a2641597b3dc6ad97653e2ea512 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 31 Jan 2018 10:49:13 +0100 Subject: [PATCH] Simple calculation function added. --- src/player.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/player.c b/src/player.c index 3a3a76f..7ec70af 100644 --- a/src/player.c +++ b/src/player.c @@ -24,11 +24,17 @@ player_levelup(Player *player) player->stats.def += 1; } +unsigned int +next_level_threshold(unsigned int current_level) +{ + return (current_level * 50) + ((current_level > 0 ? current_level - 1 : 0) * 150); +} + static void player_gain_xp(Player *player, unsigned int xp_gain) { player->xp += xp_gain; - if (player->xp >= (player->stats.lvl * 50) + ((player->stats.lvl - 1) * 150)) { + if (player->xp >= next_level_threshold(player->stats.lvl)) { player_levelup(player); gui_log("You have reached level %u", player->stats.lvl); }