Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

closed as too localized by Byte56, jhocking, Jimmy, bummzack, Sean Middleditch Mar 7 '13 at 9:13

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

7  
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! –  Byte56 Mar 6 '13 at 22:44
7  
Are we seriously teaching percentage math now? –  jhocking Mar 6 '13 at 23:25
3  
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. –  Tetrad Mar 7 '13 at 0:23
5  
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. –  Anko Mar 7 '13 at 0:30
2  
@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 –  user27102 Mar 7 '13 at 0:32

2 Answers 2

up vote 9 down vote accepted

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.

share|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.

share|improve this answer

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