How do I program pickups ... this way?

0 favourites
  • 8 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • A possible solution is to add a function that checks if the current health is > max health... if so, set current health to max

  • 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 !

  • 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

  • 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

  • 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

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

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

  • ==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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)