Skip to content

Commit

Permalink
Flash health bar when taking damage #678
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 25, 2024
1 parent de6abb5 commit cb19ba6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Protoc
uses: arduino/setup-protoc@v1.1.2
uses: arduino/setup-protoc@v3
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
17 changes: 12 additions & 5 deletions src/cdogs/hud/health_gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
#include "gauge.h"

#define WAIT_MS 1000
#define FLASH_PERIOD_MS 100

void HealthGaugeInit(HealthGauge *h)
{
h->health = 0;
h->waitHealth = 0;
h->waitMs = 0;
memset(h, 0, sizeof *h);
}

void HealthGaugeUpdate(HealthGauge *h, const TActor *a, const int ms)
Expand Down Expand Up @@ -93,6 +92,12 @@ void HealthGaugeDraw(
hsv.h =
(maxHealthHue - minHealthHue) * health / maxHealth + minHealthHue;
}
// Flash bar white if just took damage
if (h->waitMs > 0 && (h->waitMs & FLASH_PERIOD_MS) < FLASH_PERIOD_MS / 2)
{
hsv.s = 0.0;
hsv.v = 1.0;
}
color_t barColor;
if (h->health != health)
{
Expand All @@ -115,8 +120,10 @@ void HealthGaugeDraw(
{
const int healthOverMax = actor->health - maxHealth;
const int excessHealth = ActorGetMaxHeal(actor, true);
const int excessHealthRange = MAX(excessHealth - maxHealth, healthOverMax);
const int innerWidth2 = MAX(1, width * healthOverMax / excessHealthRange);
const int excessHealthRange =
MAX(excessHealth - maxHealth, healthOverMax);
const int innerWidth2 =
MAX(1, width * healthOverMax / excessHealthRange);
hsv.h = 120.0;
hsv.v = 1.0;
barColor = ColorTint(colorWhite, hsv);
Expand Down
44 changes: 22 additions & 22 deletions src/cdogs/hud/health_gauge.h
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 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.
*/
#pragma once

Expand Down

0 comments on commit cb19ba6

Please sign in to comment.