My goal is to display the level as a number along with a progress bar that ranges from 0 to 99 based on the current level.
After researching online, I came across a math formula for leveling which is:
constant * Math.sqrt(xp);
In order to achieve this, I am working on creating two functions - one to calculate the current level and another to calculate the current percentage (for displaying the progress bar).
Here are the functions I have created so far:
function calculateLevel(xp: number): number {
return 3/2 * Math.sqrt(xp);
}
However, I am facing some difficulties with the following function:
// should return a value between 0-99
function calculatePercentage(xp: number): number {
let currentLevel = calculateLevel(xp);
// To calculate the progress
// we need to find the total xp needed to move from this level to the next
// and then subtract the currentXP from it
// example calculation
let percentage = Math.floor(50.85);
return percentage;
}