I want to make a health-bar/life system [Solved]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

I want to make a health-bar/life system [Solved]

#1 Post by beastcarving »

I want to know how to add a health bar type of thing that will lower every time a certain choice is maybe. (The bar would be animated through frames when lowered)I would like this to be a part of the quick menu that you can keep checking up on as you play. I want people to be surprised when it changes, not knowing what choice maybe the health bar lower, so the player has to keep checking up on it when they are curious of it being affected throughout the game. It might be impossible to make, but I would love if one of you geniuses could help me out.
Image
Image
Last edited by beastcarving on Tue May 28, 2019 5:51 am, edited 1 time in total.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#2 Post by beastcarving »

BTW I don't use GUI
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: I want to make a health-bar/life system [HELP]

#3 Post by Andredron »

Code: Select all


init:
    $ health = 100 # set the amount of health
 
screen healthbar:
    # if you replace vbar with bar,
    # that indicator will become horizontal
    vbar value StaticValue (health, 100): # maximum - 100 hp
        align (.05, .05) # position on the screen
        xmaximum 200 sizes
        ymaximum 200
        left_bar "heartempty.png" # empty heart
        right_bar "heart.png" # full heart
        thumb None # here you can put a separator
        thumb_shadow None # and shadow
 
label start:
    show screen healthbar # display heart on screen
    pause # wait for a click and start the demonstration
    while health> 0: # while health is greater than 0
        $ health - = 1 # decrease it by one
        pause .01 # short pause
    pause
    return


And viewtopic.php?f=51&t=22147

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#4 Post by beastcarving »

Thanks for the response. It's not exactly what I wanted. I wanted the "love meter" to be accessed through the quick menu instead of displayed on the screen whenever it's affected. What I want is way too complex, so I'll probably just take this function in my game out if no one can figure it out.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: I want to make a health-bar/life system [HELP]

#5 Post by trooper6 »

It isn't that complex. You just add a button to your quickmenu that brings up the love meter screen.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#6 Post by beastcarving »

I've connected it to the quick menu, but now the love meter is not working anymore. I really need help with this. I'd be grateful to anyone that could provide me with a solution.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: I want to make a health-bar/life system [HELP]

#7 Post by trooper6 »

Provide your code, so we can see if there is some sort of error in it.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#8 Post by beastcarving »

I put this in the Screen page

Code: Select all

screen aura:
    tag menu
    #use navigation
    imagemap:
        ground "pick.png"
        idle "ybr aura align 100.png"
        hover "ybr aura align 90.png"
        cache False
        hotspot (105, 27, 218, 69) action Return()
        hotspot (478, 187, 450, 434) action ShowMenu("Pure")

I added this one to the Script page

Code: Select all

    init:
        $ health = 100 # set the amount of health

    screen Pure:
        # if you replace vbar with bar,
        # that indicator will become horizontal
        vbar value StaticValue (health, 100): # maximum - 100 hp
            align (.05, .05) # position on the screen
            xmaximum 1400 #sizes
            ymaximum 800
            left_bar "ybr aura align.png"#("image.png", 0, 0) # empty heart
            right_bar "ybr aura align 60.png" # full heart
            thumb None # here you can put a separator
            thumb_shadow None # and shadow


    #show screen Pure # display heart on screen
    pause # wait for a click and start the demonstration
    while health> 0: # while health is greater than 0
        $ health -=1 # decrease it by one
        pause .01 # short pause
    pause
    #return
    hide screen Pure
    hide pick with dissolve
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: I want to make a health-bar/life system [HELP]

#9 Post by trooper6 »

Try something a bit more like this:

Go to your screens.rpy file. Find the Quickmenu. Add a button that will bring up your health screen.

Code: Select all

screen quick_menu():

    ## Ensure this appears on top of other screens.
    zorder 100

    if quick_menu:

        hbox:
            style_prefix "quick"

            xalign 0.5
            yalign 1.0

            textbutton _("Back") action Rollback()
            textbutton _("History") action ShowMenu('history')
            textbutton _("Skip") action Skip() alternate Skip(fast=True, confirm=True)
            textbutton _("Auto") action Preference("auto-forward", "toggle")
            textbutton _("Save") action ShowMenu('save')
            textbutton _("Q.Save") action QuickSave()
            textbutton _("Q.Load") action QuickLoad()
            textbutton _("Prefs") action ShowMenu('preferences')
            textbutton ("Health") action ToggleScreen('healthscreen')
Then create your health screen and your variables...I put this at the top of the script.rpy file, but it could in the screens.rpy file...wherever:

Code: Select all

default health = 100
default max_health = 100

screen healthscreen():
    frame:
        align (0.05, 0.05)
        xmaximum 300
        bar value AnimatedValue(value=health, range=max_health, delay=2.0)
Then, in the game itself you can do something like:

Code: Select all

label start():
    "So the game has started."
    "If you are interested you can click the 'Health' button in the quickmenu and pull up the health bar."
    $health -= 10
    "Did you just see the value decrease?"
    "Anyhow, you can also click on 'Health' again, anytime you want, to make the health bar disappear again."
    $health -= 10
    "So if you do not want the game and bar visible at the same time, there are ways to adjust the code...but this is just the basics here."
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#10 Post by beastcarving »

Thank you so much! :shock: :) It worked! That's exactly what I wanted it to do. You are amazing! I was also wondering if I could customize the health bar with an animation when it lowers. This bar will lower and change in appearance, becoming eerier in design as it empty. I made two health bars, and I want to know if I could also do it that way. Thanks. :D
Image
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: I want to make a health-bar/life system [HELP]

#11 Post by Alex »

In this case you can use a simple ConditionSwitch instead of bar - viewtopic.php?f=51&t=19063

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#12 Post by beastcarving »

I'm having issues connecting the Condition-switch to my quick menu. I want my Condition-switch to only be accessible through my quick menu the same as my love meter. Please help.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: I want to make a health-bar/life system [HELP]

#13 Post by Alex »

Well, the only thing you need to do is replace

Code: Select all

bar value AnimatedValue(value=health, range=max_health, delay=2.0)
in your healthscreen screen with the ConditionSwitch, that changes image depending of health variable. You don't need to change other things you've already done to make a button to show/hide healthscreen screen from quick_menu.

Try

Code: Select all

image health_meter = ConditionSwitch (
    "health < 10","health_low.png",
    "health < 50","health_half.png",
    "True", "health_full.png"
    )


screen healthscreen():
    frame:
        align (0.05, 0.05)
        xmaximum 300
        add "health_meter"
https://www.renpy.org/doc/html/screens.html#add

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: I want to make a health-bar/life system [HELP]

#14 Post by beastcarving »

Both love meters are working well. I'm grateful to all of you that helped. Thanks!
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

Post Reply

Who is online

Users browsing this forum: No registered users