In my current game, the amount of energy that a character loses shall be determined by certain attributes:
The hero has an attack value.
The hero has a defense value.
The hero has current life energy.
The opponent has an attack value.
The oponent has current life energy.
(Since the same opponent type always has the same initial values, a defense value isn't necessary here. A higher defense is simply realized by giving him more initial energy.)
When the hero gets hit by an opponent, the hero's energy loss is calculated by the opponent's attack value and the hero's defense value.
When the hero attacks an opponent, the opponent's energy loss is calculated by the hero's attack value.
Now, what is the best formula to calculate the energy loss per hit?
I've found some formulas:
damage = attack * attack / (attack + defense)
damage = attack / (100 / (100 + defense)
However, they use arbitrary multiplication and division, which is not really ideal for NES games since it eats up too much CPU time.
So, is there any good formula that can be calculated in a fast way and that has no drawbacks?
What did action adventures on the NES or Game Boy use here?
Since my game uses screen-by-screen scrolling like in "Zelda" and since weapons and items are equipped in a menu, I could maybe do an alternate approach:
I could use one of the above formulas to store the current potential hero damage and opponent damage values into the opponents' properties.
During a screen transition, the game stops for a moment anyway, so the calculation doesn't need to be ultra fast here.
Same when I equip items in a menu: I could just update each opponent's properties there.
This way, the game would simply use this one pre-calculated value to subtract from the energy and doesn't need to do any complicated calculations during live gameplay.
However, if I decide to make it possible that a new opponent enters the screen during gameplay, this could require a calculation of this forumla during live gameplay.
In the moment, new opponents cannot enter the screen, but I'm not sure if this will stay like this. Maybe bosses can spawn smaller henchmen.
One situation where new "characters" entering the screen is definitely already the case is when the opponent shoots a weapon.
And opponents and weapons have no direct relation:
An opponent has an array of movement patterns. And one step in one of those patterns might be "shoot this and that weapon".
Therefore, I cannot store a weapon damage value in an opponent's properties since the opponent definition doesn't even know directly if the opponent can shoot arrows or fireballs. Everything is independent from each other:
Certain opponent properties points to a collection of movement patterns. And any pattern can have any "spawn weapon xyz" as a command.
Another likely situation that might require calculation during live gameplay: If the hero is influenced by a temporary status value (like "cursed" or whatever those RPGs use) where, for example, his defense goes down for 20 seconds.
So, what would you suggest here? And how did old games do it?
The hero has an attack value.
The hero has a defense value.
The hero has current life energy.
The opponent has an attack value.
The oponent has current life energy.
(Since the same opponent type always has the same initial values, a defense value isn't necessary here. A higher defense is simply realized by giving him more initial energy.)
When the hero gets hit by an opponent, the hero's energy loss is calculated by the opponent's attack value and the hero's defense value.
When the hero attacks an opponent, the opponent's energy loss is calculated by the hero's attack value.
Now, what is the best formula to calculate the energy loss per hit?
I've found some formulas:
damage = attack * attack / (attack + defense)
damage = attack / (100 / (100 + defense)
However, they use arbitrary multiplication and division, which is not really ideal for NES games since it eats up too much CPU time.
So, is there any good formula that can be calculated in a fast way and that has no drawbacks?
What did action adventures on the NES or Game Boy use here?
Since my game uses screen-by-screen scrolling like in "Zelda" and since weapons and items are equipped in a menu, I could maybe do an alternate approach:
I could use one of the above formulas to store the current potential hero damage and opponent damage values into the opponents' properties.
During a screen transition, the game stops for a moment anyway, so the calculation doesn't need to be ultra fast here.
Same when I equip items in a menu: I could just update each opponent's properties there.
This way, the game would simply use this one pre-calculated value to subtract from the energy and doesn't need to do any complicated calculations during live gameplay.
However, if I decide to make it possible that a new opponent enters the screen during gameplay, this could require a calculation of this forumla during live gameplay.
In the moment, new opponents cannot enter the screen, but I'm not sure if this will stay like this. Maybe bosses can spawn smaller henchmen.
One situation where new "characters" entering the screen is definitely already the case is when the opponent shoots a weapon.
And opponents and weapons have no direct relation:
An opponent has an array of movement patterns. And one step in one of those patterns might be "shoot this and that weapon".
Therefore, I cannot store a weapon damage value in an opponent's properties since the opponent definition doesn't even know directly if the opponent can shoot arrows or fireballs. Everything is independent from each other:
Certain opponent properties points to a collection of movement patterns. And any pattern can have any "spawn weapon xyz" as a command.
Another likely situation that might require calculation during live gameplay: If the hero is influenced by a temporary status value (like "cursed" or whatever those RPGs use) where, for example, his defense goes down for 20 seconds.
So, what would you suggest here? And how did old games do it?