Question

I'm pretty new to programming, but I've learned some PHP and HTML. Now I am trying to make a text based "RPG" game. I've already made a few functions like gambling, killing, and doing crimes (Yes, it's a mafia related game). I've made it possible to "level up" in this game, and stunningly enough, I made it work perfectly, but then I ran over a small issue. I want to let the players see their progress, using a "rank bar", it's the same concept as experience points, but I want it to show as percent. As of now, it looks like this:

$percent = $currentxp / $nextlevelxp;
$percent2 = $percent * 100;
$percent3 = number_format($percent2, 0);

This actually worked for me (you can see your xp, and level up), but the problem is, when you level up, it will show percent to next level using the current XP, which means it might say 50% when you've just leveled up. Is there any way I can make it 0% at the next rank, and make it go up to 100% before you level up? I'd prefer a basic kind of code. Thank you in advance!

Was it helpful?

Solution

Change the first line to:

$percent = ($currentxp - $curlevelxp) / ($nextlevelxp - $curlevelxp);

This isn't a programming problem, it's just simple math.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top