Turn-Based Battle - Damage Calculations

11

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

tb-battledamagecalc.c3p

Download now 169.66 KB
.c3p

tb-battledamageeq.c3p

Download now 171.48 KB

Stats

4,210 visits, 7,198 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 30 Mar, 2021.
.C3P

tb-battledamagecalc.c3p

Download now 169.66 KB

Damage Calculations can be as simple or as complicated as you need them to be. In Pokemon for example, a move's damage is calculated by a complex formula and is affected by a large number of modifiers. By contrast, if you wanted to keep things simple, you could just say:

Damage = Attacker's Attack Stat – Defender's Defence Stat.

Although, it's a bit dull though if we know exactly how much damage is going to be dealt with every turn. So, to make things a bit more interesting, a bit of random variance can be added. In Pokemon, this would be handled in the Modifier section of their big damage equation, but for this example, a simple Random expression can be added to the damage calculation.

We'll start by implementing the basic equation and work our way up to something akin to Pokemon's calculations.

This is actually a pretty easy change to implement. Firstly, we'll need to add a new Defence instance variable to both our Opponent and Player objects. This should mean that the two combatant objects now have the following 'stats':

  • HP
  • Attack
  • Defence
  • Speed
  • Accuracy

To make things easier as our damage calculations get more complicated, the actual value for an attack's damage will be stored in a global variable appropriately named Damage.

The only part of the event sheet that needs to change from the last tutorial project is the expression used for damage in the attack functions. Looking at the PlayerAttack function, it becomes:

In this action, the damage is defined by the following expression:

int((random(0.85,1.01)*(Player.Attack-Opponent.Defence)))

First, the Opponent's defence stat is subtracted from the Player's attack stat. This value is then multiplied by a random number between 0.85 and 1.01 to introduce a random element to the attack. The resulting value is then turned into an integer by the int expression.

This final value is then stored in the Damage global variable so it can be subtracted from the Opponent's health during the battle turn.

The reverse expression can be put into the OpponentAttack function, so you would subtract the Player's defence stat from the Opponent's attack stat.

This simple calculation will give you a good start for damage in your system. The random expression gives a nice little random element without being too intrusive and gives you something to mess around with to make the damage a little less predictable.

  • 0 Comments

Want to leave a comment? Login or Register an account!