Enemys heal me arggg

Just started using Construct 2? Post your questions here

Post » Fri Mar 28, 2014 8:47 am

Well, It's a pity but today my neurons are asleep :?

I have variables:

PlayerLife: current hp of player
Max_Player_life: maximum hp the player have.
Defense: subtract from enemy damage a bit quantity.

So if a bullet do as damage:
Code: Select all
subtract 5-Defense from PlayerLife


If Defense is greater than 5, PlayerLife grows... :oops:

what would be your solution?
B
17
S
5
G
2
Posts: 173
Reputation: 2,085

Post » Fri Mar 28, 2014 8:51 am

A really easy way is to make defense a percentage of damage reduction. ie, 10% and ugradable to 15%, 20% etc etc.

Then you only need to do:

Subtract (Damage * PlayerDefense) from PlayerLife.

PlayerDefense default = 1.0 = no damage reduction. If you want 10%, then just make it 0.9 and the player will take only 90% of the damage.

Otherwise you will have to add a trigger prior to doing that calculation.

ie. If Damage < PlayerDefense = destroy bullet only, no damage calculation.
Else, do the damage - defense calculation and subtract it from life.

Edit: Both works, its what I do for my games. But the first method is better because it has one less event check, so it runs faster on mobiles. ;)
Last edited by Silverforce on Fri Mar 28, 2014 8:55 am, edited 2 times in total.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Fri Mar 28, 2014 8:52 am

5 - (minus) Defense?
Is "Defense" greater than 5?
Because MINUS + MINUS = PLUS
B
22
S
6
G
2
Posts: 185
Reputation: 3,632

Post » Fri Mar 28, 2014 9:05 am

Use the system expression clamp.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,287

Post » Fri Mar 28, 2014 12:42 pm

@Silverforce thanks very much!! I think percentage in damage reduction is a good choise :)

Anyway I am using just now the clamp, testing it...


thanks @Kyatric ;)
You do not have the required permissions to view the files attached to this post.
B
17
S
5
G
2
Posts: 173
Reputation: 2,085

Post » Sat Mar 29, 2014 8:56 pm

I remember the day I discovered clamp(), my life changed forever
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests