Damage calculations?

Get help using Construct 2

Post » Fri Jul 25, 2014 3:37 pm

Hi, how would I go about making a system where a damage calculation is played based on the users attack variable, the attack's own damage value as a modifier of the users attack variable, and the targets defense, all calculated universally by calling the calc when ever damage is done.

So that the only thing every hero or enemy object needs is an HP, ATT, and DEF variable in their instances?

This is for a sidescroller by the way, so theres collision detection.

Say for example, player uses fireball(Technique) on an enemy and it overlaps on them, then the damage calculation should be called: Players Attack*Techniques Power / Enemy Defense = Damage total, which is substract from the HP variable of the enemy.

I don't want to go and use a simple system where I just type "-5" for the damage of a fireball on an enemy, independent of the user of the fireball. I want the fireballs damage to be based on the user, while the fireball itself has an attack value, it is a multiplier of the users own attack power, instead of being independent damage. Like say, Fireball's value is always 1.25, so if the player's attack is 100, then the total damage is 125, if the players attack is 8, then the total damage is 10. Then the enemies defense comes into play, dividing the damage by the defense value.

How would I go about implementing this? What method is the most efficient?

To reiterate: Player and enemies have HP, ATT, and DEF as stats. Attack techniques have POWER as a stat{damage modifier}. And theres a calculation that is called everytime damage occurs to a target, based on these values and subtracting the results from the self HP attribute of target.
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Fri Jul 25, 2014 3:50 pm

Well, construct does allow you to do math in most(all?) variable changes, so how I would do it is:

Stats associated with each player/enemy (HP, ATT, and DEF)
Stats associated with each ability (POWER, Anything else needed (maybe cooldown, mana cost, w/e) -> This could be organized in an array.

Then when you detect the collision, I would probably call a function "Damage Enemy" with the parameters EnemyID, ATT and POWER

In this function, you pick the correct enemy and run an event such as
Enemy -> Subtract from instance variable "HP" -> Amount = ATT * POWER / Enemy.DEF
Then make a sub event checking (if Enemy.HP <= 0)
Enemy -> Destroy

You can also add other things into this function such as creating floating text displaying the damage dealt or sound effects for the enemy being hit.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Fri Jul 25, 2014 4:05 pm

Yes! This is what I was looking for, thanks. So Functions and Arrays is what I should be trying to use? So for the attacks properties, they should be assigned to an array while the player/enemy stats can remain as instance variables, or would ATT and DEF be in arrays while HP as a variable?

Thanks, Robsta. Your post was very informative.
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Fri Jul 25, 2014 6:02 pm

Functions and arrays is what I use a lot of because I come from a programming background, and I used a ton of functions and arrays in code.

I would keep ATT and DEF as instance variables since you're likely going to have different ATT/DEF for every player/enemy.
Having the abilities in an array is better because that way you can give the same ability to multiple people and reference it. (And it packages the ability's variables together quite nicely.)

I'm glad my post was helpful.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Sat Jul 26, 2014 3:02 pm

Thanks, Robsta, another thing I wanted to know is if put this damage function in every event sheet of every level, or if there is a way to make a global event sheet? I notice that a level can only refer to a single event sheet, but maybe my limited knowledge is causing me to focus to much on that property in the menu.
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Sat Jul 26, 2014 3:05 pm

Fradno wrote:Thanks, Robsta, another thing I wanted to know is if put this damage function in every event sheet of every level, or if there is a way to make a global event sheet? I notice that a level can only refer to a single event sheet, but maybe my limited knowledge is causing me to focus to much on that property in the menu.


you can include event sheets in other event sheet (right click: include event sheet), and you can assign the same main event sheet to multiple layouts (through the layout proprieties)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Sat Jul 26, 2014 7:24 pm

Thanks, Aphrodite!
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Sun Jul 27, 2014 9:22 pm

Almost forgot to mention, will I need more than the free version to do some of these things? I heard families group objects into a single group for easier referencing and what not.

When I'm trying to set up the collision of the attack, it only allows me to choose 1 object. Which means I would have to copy and pasted a "Slash" Attack for every enemy in the game, even if a universal function is called to calculate the damage, I was hoping to make the attack overlapping have universal targetting so I wouldn't have to recopy and paste for everything. Anyway, thanks in advance for the info.
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Post » Sun Jul 27, 2014 9:51 pm

As someone who has not yet had the cash to get the license, I will tell you, you want the license.
Don't get me wrong, free version is pretty incredible, but you're gonna want those limits removed.

Also, there is certainly a way to set your slash attack up in such a way that doesn't require copy/pasting.
Probably with a function that picks the object UID to decide how much/where the damage goes.

There is (almost?) ALWAYS a better way than copy/pasting.
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Sun Jul 27, 2014 9:59 pm

How do I make it select UID? It only gives me the option of selecting the enemy itself, instead of all enemies in general, which I heard the family feature does.

Right now I'm trying to figure out what expressions are possible, like how all the variables of an object display when you pick an instance variable action. I'm to make that equation in a response post from above as I write this. {I was still trying to implement the character select screen at the time I posted the OP for when I got there.}
B
25
S
11
G
1
Posts: 82
Reputation: 2,639

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests