summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-01-09 14:37:32 -0700
committerIra Rice <irarice@gmail.com>2009-01-09 14:37:32 -0700
commit1e70a04b0e004787a158584f247ebc3ffa654029 (patch)
treeeb9bd33ea65f45e6fa0860caa6314e46e5f773d4 /src
parenta9716272cd2b5720a88f3d6904ec0f156177266d (diff)
downloadmana-1e70a04b0e004787a158584f247ebc3ffa654029.tar.gz
mana-1e70a04b0e004787a158584f247ebc3ffa654029.tar.bz2
mana-1e70a04b0e004787a158584f247ebc3ffa654029.tar.xz
mana-1e70a04b0e004787a158584f247ebc3ffa654029.zip
Made experience percentages report to the newest hundredth (as well as
placed in checks for bogus amounts of experience, and correct them). Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/ministatus.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index 6884f4d6..6d9fc5b1 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -95,19 +95,24 @@ void MiniStatusWindow::update()
mHpBar->setColor(0, 171, 34); // Green
}
+ float xp = (float) player_node->getXp() / player_node->mXpForNextLevel;
+
+ std::cout << xp << std::endl;
+
+ if (xp != xp) xp = 0.0f; // check for NaN
+ if (xp < 0.0f) xp = 0.0f; // make sure the experience isn't negative (uninitialized pointer most likely)
+ if (xp > 1.0f) xp = 1.0f;
+
mHpBar->setProgress((float) player_node->mHp / player_node->mMaxHp);
mMpBar->setProgress((float) player_node->mMp / player_node->mMaxMp);
- mXpBar->setProgress(
- (float) player_node->getXp() / player_node->mXpForNextLevel);
+ mXpBar->setProgress(xp);
// Update labels
mHpLabel->setCaption(toString(player_node->mHp));
mMpLabel->setCaption(toString(player_node->mMp));
std::stringstream updatedText;
- updatedText << (int) (
- (float) player_node->getXp() /
- player_node->mXpForNextLevel * 100) << "%";
+ updatedText << (float) ((int) (xp * 10000.0f)) / 100.0f << "%";
// Displays the number of monsters to next lvl
// (disabled for now but interesting idea)