Creating Armor Vs. Health

Get help using Construct 2

Post » Sat Jan 12, 2013 4:33 pm


So here is a question for all you fine folks out there with more construct knowledge than myself.

I want my player character to have both an energy shield and health. I want the Shields to regenerate points over time to a maximum value, and the health to have a limited number of hits, (Starting with 3) that do not regenerate over time. The end result is that when the player loses health to 0 it dies and it's game over.

The trouble I am having is that when I try to program this I can't figure out the part where it would change over between one type of life to the other. I can't seem how to create the following scenario in construct.

If PlayerShields = 0 Then When hit my creature or projectile subtract from PlayerHull

Basically I need a way to code the above statement but I'm still new to the construct format. Any and all help or comments is appreciated. If you know of somewhere else in the forums that this answer is located please direct me.

Thanks to all in advance!
Posts: 11
Reputation: 1,000

Post » Sat Jan 12, 2013 5:47 pm

Why not just have the armor subtract from the damage? This is what most RPG (paper and pencil) games do.

For instance:
Damage = 5
Armor = 4
Health = 3

Damage - Armor = Hits taken

5 - 4 = 1

Health - Hits Taken = New Health

3 - 1 = 2
Posts: 75
Reputation: 3,425

Post » Sat Jan 12, 2013 10:34 pm

I'm not sure if that would work.

My intention is to have the shield regenerate over time. (Similar to how it works in Halo.)

For example:

Player gets hit so -1 to shields. Then Player gets hit again so another -1 to shields. Now the player kills the creature and waits x seconds and his shields regenerate to full.

But in another example:

Shields = 3 hits
Hull = 3 hits.

This time player gets hit 4 times for -1 damage each without regenerating. so he has the following remaining after shield regenerate:

Shields = 3 hits.
Hull = 2 hits.

This is the mechanic I am trying to achieve. I appreciate the input though. :)
Posts: 11
Reputation: 1,000

Post » Sat Jan 12, 2013 11:19 pm

You'll need to create three local variables: health, shields, and regeneration timer. Knocking off the health and shields is simple enough: just check to see whether or not the player has any shields remaining. If they do, then -1 the shields, if not (shields=0), then -1 the health.

To do the shield regeneration, set the regen timer to gain 1 every second or whatever you want, and then create a new timer that raises the shields by 1 every few seconds, but only if the regen timer's value is greater than a certain amount, say 5. When the player gets hit, you reset the regen timer to 0, forcing it to count up to 5 again before the shields start to regenerate every 2 seconds.

Make sense? I hope so, it's kind of late for me here.

I've made a simple capx to show you: here
Posts: 912
Reputation: 12,051

Post » Tue Jan 15, 2013 3:20 pm

Not near my personal computer right at the moment, but I will try our the capx file when I get home this evening. I kinda see what I need to do, but I think it's going to require a few more variables than what i thought at first.

Healthmax = 3 initial, increases as game progresses.
Healthcurrent = x = Healthmax
Shieldmax = 3 initial, increases as game progresses.
Shield current = y = Shieldmax
Shieldregen = add 1 to shieldcurrent If regen timer = regenmax
regenmax = 5
regen timer = 0 to 5

Feel free to give me your thoughts on my logic in case i am missing something?

Thanks again for the help.jclausen2013-01-15 15:22:29
Posts: 11
Reputation: 1,000

Post » Fri Feb 08, 2013 9:38 am

I've actually just made something like this myself and found that one of the most annoying things to get right was the delay before the shield was able to charge (I assume you want this if Halo is inspiration).

In my project I have a physical shield that disappears when exhausted so it is slightly different but essentially I have:

A timer that registers time elapsed since last hit:
On contact with an enemy I reset this to zero
It counts up to three and then stops

On the timer hitting 3 I set a bool ShieldCanCharge to True
On being hit by an enemy I set it to false.

For whether to damage health or shields I'd do
if shields > 0 do damage to shields
do damage to health

As for the recharge, have a max charge variable, a charge rate variable, you then check the shield bool is set to true and the shield is not already at max strength and charge away.

Apologies if this reply is a bit rambling and useless, I've only just started tinkering myself and know nothing really. I have some shields that work though. I can post capx if interested but I'm at work atm.
Posts: 14
Reputation: 403

Post » Tue Nov 05, 2013 4:23 pm

can you share that capx again please, GeometriX?
Posts: 669
Reputation: 5,038

Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 1 guest