I am a newbie in Python, I am very bad at math too and I need some help. Also close/move this post if you feel this isn't the right place for it.

Hero1 = 5000   # His HP is 5k.
Hero1dmg = 200 # damage output

How can I subtract some value (let's say 20%) from Hero1's damage output?

  • 7
    \$\begingroup\$ Math is used extensively in programming and even more in game programming. You'll want to make sure you have a good understanding of the basics before continuing, otherwise you'll run into a lot of problems. Good luck! \$\endgroup\$ – MichaelHouse Mar 6 '13 at 22:44
  • 7
    \$\begingroup\$ Are we seriously teaching percentage math now? \$\endgroup\$ – jhocking Mar 6 '13 at 23:25
  • 3
    \$\begingroup\$ It's not that they're mad at you, they're debating whether or not this is the place to answer those kinds of questions. \$\endgroup\$ – Tetrad Mar 7 '13 at 0:23
  • 5
    \$\begingroup\$ It's OK to be bad at math. I think @jh wants to say that this is a game development site, not a math site and that most of this question is math. It's nothing personal - we're just trying to keep the site well organised. \$\endgroup\$ – Anko Mar 7 '13 at 0:30
  • 2
    \$\begingroup\$ @Anko I appreciate that, I really do, but instead of killing my hopes of ever being a programmer, he could have just said that he doesn't think this is the right place for that kind of question. Cheers \$\endgroup\$ – user27102 Mar 7 '13 at 0:32

A very basic formula would be:

damageAfterArmorCalc = damageAmt*(1-armorReductionPercent)

damageAmt Is the original amount of damage to be done.

armorReductionPercent is the percent of damage the armor negates, this percentage should be a value from 0 to 1, so the 20% in your example would be .2. If we're doing 100 damage initially, we can look at some examples for what that does.

So what's happening here, if the armor does not negate any damage, then we get:

100 * (1 - 0) = 100*1 = 100

As you know, any number multiplied by one is still that number. Now if the armor negates 100% of damage, we would get

100 * (1 - 1) = 100*0 = 0

Since any number multiplied by zero is zero. Now we know it works for both extremes, how about the inbetween values? Say it negates 20% of damage as in your example. , we can see how that looks:

100 * (1 - .2) = 100*.8 = 80

We know that 20% of 100 is 20, and that 100 minus 20 is 80. So it looks like this works just fine.

I suggest you look into some basic math tutorials and get the basics down. Khan academy is a great resource for this.

|improve this answer|||||

To subtract 20% off his damage output, multiply by .8 (20% = 0.2, so multiply by 1 - .2 = 0.8). That makes the new damage 160.

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.