O'Reilly logo
  • LI WEI thinks this is interesting:

We can also do other things as we're reducing the player's hp, such as take into account the player's armor, check whether the player is invulnerable, or have other effects occur when the player is damaged. What happens when the player is damaged should be abstracted away by the damage() function.

From

Cover of Learning C++ by Creating Games with UE4

Note

为什么不直接减去伤害而是要使用一个函数来包裹?因为在实现受伤的过程中,大部分游戏都不是这么直接,我们还会考虑当前玩家是否无敌的,防御和闪避分别是多少。这样我们将会为将来扩展公式留下余地。