Skip to content

Commit

Permalink
Fix health gauge when exiting vehicles #30
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jul 26, 2021
1 parent 67d077e commit 515b123
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/cdogs/hud/health_gauge.c
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -33,7 +33,6 @@

#define WAIT_MS 1000


void HealthGaugeInit(HealthGauge *h)
{
h->health = 0;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 515b123

Please sign in to comment.