diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2021-04-05 13:38:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 13:38:50 +0200 |
commit | c11208c4b55bc6b17e523761befed6156027edf9 (patch) | |
tree | 6ab740af2e455ae16239d7e429c7d5b9e26f8177 /src | |
parent | f0bad0e2badbb7d4777aac7de1b50239bca4010a (diff) | |
download | minetest-c11208c4b55bc6b17e523761befed6156027edf9.tar.gz minetest-c11208c4b55bc6b17e523761befed6156027edf9.tar.bz2 minetest-c11208c4b55bc6b17e523761befed6156027edf9.zip |
Game: Scale damage flash to max HP
The flash intensity is calculated proportionally to the maximal HP.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/content_cao.h | 2 | ||||
-rw-r--r-- | src/client/game.cpp | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 7c134fb48..cc026d34e 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -174,6 +174,8 @@ public: const bool isImmortal(); + inline const ObjectProperties &getProperties() const { return m_prop; } + scene::ISceneNode *getSceneNode() const; scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const; diff --git a/src/client/game.cpp b/src/client/game.cpp index 22b7ee875..949e53214 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -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 |