# [SOLVED] Creating a damage taken/inflicted formula for turn-based bullet hell?

#### OblivionSkull21

##### Member
I'm at the point where I can begin working on the actual health system, ATK, DEF, etc. in my game.

I have a level up system that goes from 1 to 12. I have not yet decided what ATK and DEF the player should have after reaching level 2 or higher, but right now their attack and defense are both 1.

Here's how the max hp scales:
Code:
``````switch(global.levelup){
case 1: global.max_hp = 10;
break;
case 2: global.max_hp = 15;
break;
case 3: global.max_hp = 20;
break;
case 4: global.max_hp = 25;
break;
case 5: global.max_hp = 30;
break;
case 6: global.max_hp = 35;
break;
case 7: global.max_hp = 40;
break;
case 8: global.max_hp = 45;
break;
case 9: global.max_hp = 50;
break;
case 10: global.max_hp = 60;
break;
case 11: global.max_hp = 75;
break;
case 12: global.max_hp = 90;
break;
}``````
What I'm really trying to figure out is how much damage to apply to an enemy when the player attacks and how much damage to receive from an enemy each time the player is hit by one of their "bullets"

I'd like to come up with two formulas to test out:

1.) One where the damage taken from an enemy grows exponentially based on the player's current level
2.) One where the damage taken from an enemy does not grow exponentially

When inflicting damage on an enemy, I want to consider two things: the player's ATK (the level-based amount + whatever weapon ATK they have) vs. the enemy's DEF (no extra DEF armor).

When receiving damage from an enemy, I want to consider two things: the player's DEF (level-based DEF + armor DEF) vs. the enemy's ATK (no weapon)

Also, because of a spell that causes enemies to attack each other, I also need to calculate the damage an enemy can give another enemy.

Finally, I want the player's attack damage to have a min and max range, so that it is slightly random.

The issue is I have no idea how to create a formula from this that isn't too over or underpowered.
Does anyone have any ideas or experience with this?

Last edited:

#### Neptune

##### Member
There's a million zillion ways to do it, but this is what a pretty linear way might look like. You could make it "exponential" depending on how much atk you give enemies.

[Better way down below]

Last edited:

#### OblivionSkull21

##### Member
There's a million zillion ways to do it, but this is what a pretty linear way might look like. You could make it "exponential" depending on how much atk you give enemies.
Code:
``````//player stat totals
total_atk = atk_weapon + atk_base + atk_level;
total_def = def_armor + def_base + def_level;

var def_factor = 10;
//damage to player
var damage = atk_enemy/(total_def/def_factor);

//damage to enemy
var damage = total_atk/(def_enemy/def_factor);``````
Basically higher defense means you will take smaller percent of atk value as damage...
The defense factor is just a limiter if youre using big number or small numbers... If your values are small, set it to maybe... 3.
What are atk_weapon and def_armor? The specific weapon and armor doesn't matter, the only thing that is taken into account is the extra boost those things give. I'm assuming the base is how much you'd have with nothing equipped.

With the def_factor... I'm using single digit numbers for stats at the moment with the highest enemy attack being 4 (they'll be much higher later on in the game though)... so should I lower def_factor, and by how much? Right now, if the enemy's attack is 4, I would need at least 5 defense to survive from ONE HIT, which is VERY overpowered.

Also, how would the player's current level be applied?

#### Neptune

##### Member
For the player's stuff, I'd just calculate that in their step event constantly... Something like this:
Code:
``````var def_per_level = 3;
player_total_def = player_base_def + player_armor_def + player_level*def_per_level;``````

If the total_def is greater than def_factor, you'll notice their damage goes UP.
So, maybe like this:
Code:
``````//damage to player
var def_factor = 10;
var damage_reduction = (player_total_def/def_factor);
var damage = atk_enemy;

if damage_reduction > 1
{
damage = round(damage/damage_reduction);
}``````
The more you lower 'def_factor', the more impact armor will have on reducing damage.

Last edited:

#### OblivionSkull21

##### Member
So I managed to come up with three formulas for three different scenarios. I've only really heavily-tested the third one, but it appears to be well-balanced and working.

*NOTE* ATK is always the attacker's ATK, DEF is always the defender's DEF

1.) For an enemy attacking the player:
Code:
``````INITIAL_DAMAGE = ATK * (ATK / (ATK + DEF) )
CRITICAL = round(INITIAL _DAMAGE * 1.5); //round the critical
DAMAGE = round(random_range(INITIAL_DAMAGE,CRITICAL));``````
2.) For the player attacking an enemy:
Code:
``````INITIAL_DAMAGE = (ATK * (ATK / (ATK + (DEF))) * (global.levelup + 2 + bonus); //the bonus relates to if the player uses an attack-boosting spell, otherwise it is 0
CRITICAL = round(INITIAL _DAMAGE * 1.5); //round the critical
DAMAGE = round(random_range(INITIAL_DAMAGE,CRITICAL));``````
3.) For an enemy attacking an enemy:
A.) Not attacking itself:
Code:
``````INITIAL_DAMAGE = ATK * (ATK / (ATK+DEF) ) *4;
CRITICAL = round(INITIAL _DAMAGE * 1.5); //round the critical
DAMAGE = round(random_range(INITIAL_DAMAGE,CRITICAL));``````
B.) Attacking itself:
Code:
``````INITIAL_DAMAGE = ATK * (ATK/DEF) * 4; //the attack will be stronger on themselves
CRITICAL = round(INITIAL _DAMAGE * 1.5); //round the critical
DAMAGE = round(random_range(INITIAL_DAMAGE,CRITICAL));``````

For details on how each works, see below.
---------------------------------------

Formula 1:
Code:
``````//ATK is the ATK power of the enemy, DEF is the total defense of the player (base + equipped armor)

INITIAL_DAMAGE = ATK * (ATK / (ATK + DEF) )

if INITIAL_DAMAGE < 2{
INITIAL_DAMAGE = 2;
}

else{
DAMAGE = round(INITIAL_DAMAGE);
}``````
Formula #2:
Code:
``````if global.spell_picked == "Iron Heart"{ //adds an ATK boost
bonus = 2;
}

else{
bonus = 0;
}

//ATK is the total ATK power of the player(base + equipped weapon), DEF is the defense of the enemy

INITIAL_DAMAGE = (ATK * (ATK / (ATK + (DEF))) * (global.levelup + 2 + bonus);

if INITIAL_DAMAGE < 2{
INITIAL_DAMAGE = 2; //no damage lower than 2
CRITICAL = 5;
}

else{
INITIAL_DAMAGE = round(INITIAL_DAMAGE); //round all decimals greater than 1
CRITICAL = round(INITIAL _DAMAGE * 1.5); //round the critical
}

DAMAGE = round(random_range(INITIAL_DAMAGE,CRITICAL)); //range of possible HP the enemy could lose from one attack``````

Formula #3:
Code:
``````//ATK refers to the attacking enemy's ATK power, DEF refers to the enemy being attacked's DEF power

if the enemy is not attacking itself{ //not my actual code... the real code is too complicated to get into
INITIAL_DAMAGE = ATK * (ATK / (ATK+DEF) ) *4;
}

else{
INITIAL_DAMAGE = ATK * (ATK/DEF) * 4; //attack should be stronger if it's on themselves
}

if INITIAL_DAMAGE < 2{
INITIAL_DAMAGE = 2;
CRITICAL = 5;
}

else{
INITIAL_DAMAGE = round(INITIAL_DAMAGE); //round all decimals greater than 1
CRITICAL = round(INITIAL_DAMAGE * 1.5); //round the critical
}

DAMAGE = round(random_range(INITIAL_DAMAGE,CRITICAL));``````

Last edited: