DungeonCrawl
Loading...
Searching...
No Matches
level.h File Reference

Exposes functions for working with the character. More...

#include "character.h"

Go to the source code of this file.

Macros

#define BASE_XP   100
#define XP_MULTIPLIER   1.5

Functions

int calculate_xp_for_next_level (int level)
 Calculates the XP required for the next level.
void add_xp (character_t *player, int xp_earned)
 Adds XP to a character and handles level-up if the XP threshold is reached.
void level_up (character_t *player)
 Handles the level-up process for a character.

Detailed Description

Exposes functions for working with the character.

Definition in file level.h.

Macro Definition Documentation

◆ BASE_XP

#define BASE_XP   100

Definition at line 11 of file level.h.

◆ XP_MULTIPLIER

#define XP_MULTIPLIER   1.5

Definition at line 12 of file level.h.

Function Documentation

◆ add_xp()

void add_xp ( character_t * player,
int xp_earned )

Adds XP to a character and handles level-up if the XP threshold is reached.

Parameters
playerPointer to the character gaining XP
xp_earnedThe amount of XP earned

Definition at line 17 of file level.c.

17 {
18 player->xp += xp_earned;
19
20 // Check if the player has enough XP to level up
21 if (player->xp >= calculate_xp_for_next_level(player->level)) {
22 level_up(player);
23 }
24}
void level_up(character_t *player)
Handles the level-up process for a character.
Definition level.c:27
int calculate_xp_for_next_level(int level)
Calculates the XP required for the next level.
Definition level.c:11

◆ calculate_xp_for_next_level()

int calculate_xp_for_next_level ( int level)

Calculates the XP required for the next level.

Parameters
levelThe current level of the character
Returns
The XP required to reach the next level

Definition at line 11 of file level.c.

11 {
12 // TODO: Maybe change to a more complex formula
13 return 100 + 10 * level;
14}

◆ level_up()

void level_up ( character_t * player)

Handles the level-up process for a character.

Parameters
playerPointer to the character leveling up

Definition at line 27 of file level.c.

27 {
28 player->level++;
29 player->xp -= calculate_xp_for_next_level(player->level - 1);
30 player->skill_points += 1;
31}