info box
authornireco
Mon, 08 Dec 2008 21:20:55 +0000
changeset 312 10743f190aab
parent 311 440763821484
child 313 2562466a946d
info box
src/Graphics.cc
src/Player.cc
src/Player.hh
--- a/src/Graphics.cc	Mon Dec 08 21:18:08 2008 +0000
+++ b/src/Graphics.cc	Mon Dec 08 21:20:55 2008 +0000
@@ -81,12 +81,17 @@
         );
     }
     
-    // White background
+    // Black background
     gc->clear(CL_Color::black);
 
     // Draw the game
     state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON);
 
+    // Draw box for player information
+    if (player != NULL) {
+        player->draw_player_info(this);
+    }
+
     // Flip window buffer, sync
     flip(1);
 }
--- 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)));
+
+}
--- a/src/Player.hh	Mon Dec 08 21:18:08 2008 +0000
+++ b/src/Player.hh	Mon Dec 08 21:20:55 2008 +0000
@@ -136,6 +136,11 @@
     void takeDamage (Projectile *source);
 
     /**
+     * Gives player's health in percents from maximum
+     */
+    float getHealthPercent() const;
+
+    /**
      * Increment player killcounter by one.
      */
     void addKill ();
@@ -157,28 +162,33 @@
  */
 class LocalPlayer : public virtual Player {
 private:
-    /*
+    /**
      * Calculates projectil position/velocity and calls handleCreateProjectile
      */
     void fireWeapon (Weapon *weapon);
         
-    /*
+    /**
      * Change weapon index, should be negative or positive 1
      */
     void changeWeapon (int delta);
 
 public:
-    /*
+    /**
      * Called to invoke some action on this player that we control, either by Graphics or NetworkServer.
      *
      * NetworkClientLocalPlayer overrides this to send the input to the server, which then handles it
      */
     virtual void handleInput (PlayerInput input, TimeMS dt);
         
-    /*
+    /**
      * As Player, but also draws the current weapon name if displayWeapon
      */
     virtual void draw (Graphics *g, bool displayWeapon, PixelCoordinate camera);
+
+    /**
+     * Draws downbar containing information about local player
+     */
+    void draw_player_info(Graphics *g);
 };
 
 /**