src/Player.cc
changeset 312 10743f190aab
parent 309 05a39422c81e
child 313 2562466a946d
--- a/src/Player.cc	Mon Dec 08 21:18:08 2008 +0000
+++ b/src/Player.cc	Mon Dec 08 21:20:55 2008 +0000
@@ -305,6 +305,10 @@
     Engine::log(DEBUG, "player.take_damage") << this << ": kills=" << kills << ", deaths=" << deaths;
 }
 
+float Player::getHealthPercent() const {
+    return this->health*100/(float)PLAYER_HEALTH;
+}
+
 void Player::addKill () {
     kills++;
 }
@@ -379,3 +383,35 @@
     }
 }
 
+void LocalPlayer::draw_player_info(Graphics *g) {
+    CL_GraphicContext *gc = g->get_gc();
+    int box_top = GRAPHICS_RESOLUTION_HEIGHT-100;
+    int box_left = 0;
+    int box_right = GRAPHICS_RESOLUTION_WIDTH;
+    int box_bottom = GRAPHICS_RESOLUTION_HEIGHT;
+    int box_width = box_right-box_left;
+    int box_height = box_bottom-box_top;
+    int life_bar_length = 3; // *100
+    gc->fill_rect(CL_Rect(box_left, 
+                          box_top, 
+                          box_right, 
+                          box_bottom),
+                  CL_Gradient(CL_Color(123, 43, 1, 10),
+                              CL_Color(22, 234, 111, 100),
+                              CL_Color(1, 231, 222, 200),
+                              CL_Color(190, 23, 240, 150)));
+    gc->draw_rect(CL_Rect(box_left+9,
+                          box_top+9,
+                          box_left+11+100*life_bar_length,
+                          box_top+31),
+                  CL_Color(190, 23, 20));
+    gc->fill_rect(CL_Rect(box_left+10,
+                          box_top+10,
+                          box_left+10+this->getHealthPercent()*life_bar_length,
+                          box_top+30),
+                  CL_Gradient(CL_Color(23, 143, 1),
+                              CL_Color(222, 34, 111),
+                              CL_Color(122, 231, 222),
+                              CL_Color(19, 23, 240)));
+
+}