]> git.lizzy.rs Git - minetest.git/commitdiff
Game: Scale damage flash to max HP
authorSmallJoker <SmallJoker@users.noreply.github.com>
Mon, 5 Apr 2021 11:38:50 +0000 (13:38 +0200)
committerGitHub <noreply@github.com>
Mon, 5 Apr 2021 11:38:50 +0000 (13:38 +0200)
The flash intensity is calculated proportionally to the maximal HP.

src/client/content_cao.h
src/client/game.cpp

index 7c134fb48ec7f5fe4d9951fbd02f60e7aa52d34c..cc026d34edb31c463e89ad668c34e606b67fc956 100644 (file)
@@ -174,6 +174,8 @@ class GenericCAO : public ClientActiveObject
 
        const bool isImmortal();
 
+       inline const ObjectProperties &getProperties() const { return m_prop; }
+
        scene::ISceneNode *getSceneNode() const;
 
        scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const;
index 22b7ee875a5af5b0d11aa39ba97882f4acd768e5..949e53214452971ce98806a38731a795bb7024c2 100644 (file)
@@ -2568,14 +2568,18 @@ void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation
 
        // Damage flash and hurt tilt are not used at death
        if (client->getHP() > 0) {
-               runData.damage_flash += 95.0f + 3.2f * event->player_damage.amount;
-               runData.damage_flash = MYMIN(runData.damage_flash, 127.0f);
-
                LocalPlayer *player = client->getEnv().getLocalPlayer();
 
+               f32 hp_max = player->getCAO() ?
+                       player->getCAO()->getProperties().hp_max : PLAYER_MAX_HP_DEFAULT;
+               f32 damage_ratio = event->player_damage.amount / hp_max;
+
+               runData.damage_flash += 95.0f + 64.f * damage_ratio;
+               runData.damage_flash = MYMIN(runData.damage_flash, 127.0f);
+
                player->hurt_tilt_timer = 1.5f;
                player->hurt_tilt_strength =
-                       rangelim(event->player_damage.amount / 4.0f, 1.0f, 4.0f);
+                       rangelim(damage_ratio * 5.0f, 1.0f, 4.0f);
        }
 
        // Play damage sound