Created
February 19, 2017 13:56
-
-
Save JakeSteam/ffc0bef0977e3c9709d3202fbeb803bf to your computer and use it in GitHub Desktop.
"Calculating Weapon Damage With Ideal Ranges" for GameDevAlgorithms.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int baseDamage = weapon.getDamage(); | |
int weaponMinDistance = weapon.getWeaponDistance().getMinimum(); | |
int weaponMaxDistance = weapon.getWeaponDistance().getMaximum(); | |
// If in the weapon range, full damage | |
if (distance >= weaponMinDistance && distance <= weaponMaxDistance) { | |
return baseDamage; | |
} | |
int tilesOutOfRange = distance > weaponMaxDistance ? distance - weaponMaxDistance : weaponMinDistance - distance; | |
double multiplier = (1 - (tilesOutOfRange / (double)weapon.getWeaponDistance().getRange())); | |
if (multiplier <= 0) { | |
return 0; | |
} | |
return baseDamage * multiplier; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment