From 515b123117cb4c38c7221d8e9e14d4564d6c77b8 Mon Sep 17 00:00:00 2001 From: Cong Date: Mon, 26 Jul 2021 23:48:13 +1000 Subject: [PATCH] Fix health gauge when exiting vehicles #30 --- src/cdogs/hud/health_gauge.c | 52 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/cdogs/hud/health_gauge.c b/src/cdogs/hud/health_gauge.c index fa86c1afc..5868c4f86 100644 --- a/src/cdogs/hud/health_gauge.c +++ b/src/cdogs/hud/health_gauge.c @@ -1,30 +1,30 @@ /* - C-Dogs SDL - A port of the legendary (and fun) action/arcade cdogs. + C-Dogs SDL + A port of the legendary (and fun) action/arcade cdogs. - Copyright (c) 2017, 2019 Cong Xu - All rights reserved. + Copyright (c) 2017, 2019, 2021 Cong Xu + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. */ #include "health_gauge.h" @@ -33,7 +33,6 @@ #define WAIT_MS 1000 - void HealthGaugeInit(HealthGauge *h) { h->health = 0; @@ -79,7 +78,7 @@ void HealthGaugeDraw( return; } - HSV hsv = { 0.0, 1.0, 1.0 }; + HSV hsv = {0.0, 1.0, 1.0}; const int health = actor->health; const int maxHealth = ActorGetCharacter(actor)->maxHealth; if (actor->poisoned) @@ -98,11 +97,12 @@ void HealthGaugeDraw( if (h->health != health) { // Draw different-coloured health gauge representing health change - const int higherHealth = MAX(h->health, health); + const int higherHealth = MIN(MAX(h->health, health), maxHealth); const int innerWidthUpdate = MAX(1, width * higherHealth / maxHealth); barColor = h->health > health ? colorMaroon : colorGreen; barColor.a = opts.Mask.a; - HUDDrawGaugeInner(device, &gPicManager, pos, innerWidthUpdate, barColor); + HUDDrawGaugeInner( + device, &gPicManager, pos, innerWidthUpdate, barColor); } const int lowerHealth = MIN(h->health, health); const int innerWidth = MAX(1, width * lowerHealth / maxHealth);