Skip to content

Commit

Permalink
Game: Scale damage flash to max HP
Browse files Browse the repository at this point in the history
The flash intensity is calculated proportionally to the maximal HP.
SmallJoker authored Apr 5, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f0bad0e commit c11208c
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/client/content_cao.h
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 8 additions & 4 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c11208c

Please sign in to comment.