How do I program pickups ... this way?

Get help using Construct 2

Post » Wed May 21, 2014 9:44 am

Hey guys,

Long time lurker, first time poster.

I've built a patform game and I've just implemented health pickups.
Throughout the game you acquire hearts which add to your overall health.

Problem - When I 'pickup' a health potion, I can't figure out how to add to the health depending on how much
the player has acquired.

Ie; If the player has 6 health, but the potion gives you 3 and the player has a max 7 health.
How do I make it so theplayer only gets 1 health from the potion, making player health variable not go
over max health 7?

I hope explained that properly ! I have two variables, player health - the variable governing enemy damage, death and the darkening of acquired hearts.

And Health Marker variable, the variable governing how many hearts are acquired.

Please help I'm finally stumped :8
Last edited by RAN on Wed May 21, 2014 9:54 am, edited 1 time in total.
B
4
Posts: 20
Reputation: 240

Post » Wed May 21, 2014 9:52 am

A possible solution is to add a function that checks if the current health is > max health... if so, set current health to max
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Wed May 21, 2014 9:56 am

So > max health would be 'player health' but how do i define where player health is? Would it be okay if you explained how to set up the function in that regard? Thanks !
B
4
Posts: 20
Reputation: 240

Post » Wed May 21, 2014 10:01 am

it would be easier if you post a capx that I can tell you based on your code, but I try to explain.

I imagine, that your player object has these 2 variables: CurHealth (Players current health) and MaxHealth (The maximum of health a player can have)

set up a condition: compare instance variable -> CurHealth > MaxHealth ---> Set instance variable: CurHealth = MaxHealth

With this, you don't need to check every time when you add or substract health if it is allowed... this function would just set the health back to the maximum if it is every higher than the allowed value.

Hope my example makes sense :)
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Wed May 21, 2014 10:54 am

even easier.... just one variable... health... if health max is 100 just set event in everytick that when ever health is > 100 to set it to 100
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Wed May 21, 2014 11:11 am

RAN wrote:Hey guys,

Long time lurker, first time poster.

I've built a patform game and I've just implemented health pickups.
Throughout the game you acquire hearts which add to your overall health.

Problem - When I 'pickup' a health potion, I can't figure out how to add to the health depending on how much
the player has acquired.

Ie; If the player has 6 health, but the potion gives you 3 and the player has a max 7 health.
How do I make it so theplayer only gets 1 health from the potion, making player health variable not go
over max health 7?

I hope explained that properly ! I have two variables, player health - the variable governing enemy damage, death and the darkening of acquired hearts.

And Health Marker variable, the variable governing how many hearts are acquired.

Please help I'm finally stumped :8


When you acquire the potion, do this:

Player: set health to clamp(Player_current_health+normal_quantity_the_potion_will_regen, 0, Player_max_health)

See the manual for more details on the clamp expression: https://www.scirra.com/manual/126/system-expressions
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed May 21, 2014 11:26 am

==Solved== Thanks for the help guys, greatly appreciated, wouldn't have passed this step without it!

Ubivis, you're technique aided me greatly, cheers!
B
4
Posts: 20
Reputation: 240

Post » Wed May 21, 2014 11:28 am

RAN wrote:==Solved== Thanks for the help guys, greatly appreciated, wouldn't have passed this step without it!

Ubivis, you're technique aided me greatly, cheers!


Thanks :)
Irinas version is easier, but mine is more variable, as you can adjust the max health during runtime :)
B
44
S
10
G
8
Posts: 437
Reputation: 6,463


Return to How do I....?

Who is online

Users browsing this forum: DiabloOvermind, Mayfly, tarek2 and 14 guests