# HG changeset patch # User terom # Date 1228771782 0 # Node ID 2562466a946d62e4749627ee922f190931f1f0b7 # Parent 10743f190aab7e3cf8883494ac2966b3b73a4c4d draw rope behind player, fix LocalPlayer::draw warnings, don't show negative health diff -r 10743f190aab -r 2562466a946d src/Player.cc --- a/src/Player.cc Mon Dec 08 21:20:55 2008 +0000 +++ b/src/Player.cc Mon Dec 08 21:29:42 2008 +0000 @@ -6,9 +6,11 @@ #include #include +#include #include #include + // player static state bool Player::skin_loaded = false; CL_Surface Player::skin_surface; @@ -305,8 +307,8 @@ Engine::log(DEBUG, "player.take_damage") << this << ": kills=" << kills << ", deaths=" << deaths; } -float Player::getHealthPercent() const { - return this->health*100/(float)PLAYER_HEALTH; +float Player::getHealthPercent () const { + return std::max(0.0f, this->health * 100 / (float) PLAYER_HEALTH); } void Player::addKill () { @@ -318,6 +320,9 @@ if (!isAlive()) return; + + // draw rope behind player + rope.draw(g, camera); // animation indexes int aim_img_idx = (int)((1 - (getAim() + KG_PI / 2) / KG_PI) * img_num_aim); @@ -357,10 +362,7 @@ crosshair.x + PLAYER_CROSSHAIR_WIDTH / 2, crosshair.y + PLAYER_CROSSHAIR_WIDTH / 2 ), CL_Color::red - ); - - // draw rope - rope.draw(g, camera); + ); } void LocalPlayer::draw (Graphics *g, bool displayWeapon, PixelCoordinate camera) { @@ -385,33 +387,51 @@ void LocalPlayer::draw_player_info(Graphics *g) { CL_GraphicContext *gc = g->get_gc(); - int box_top = GRAPHICS_RESOLUTION_HEIGHT-100; + + 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))); + + // draw status info at bottom of display + 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 + (int) (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) + ) + ); }