Skip to content

Instantly share code, notes, and snippets.

@JakeSteam
Created February 19, 2017 13:56
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JakeSteam/ffc0bef0977e3c9709d3202fbeb803bf to your computer and use it in GitHub Desktop.
"Calculating Weapon Damage With Ideal Ranges" for GameDevAlgorithms.com
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