[SOLVED] Stealth bar minigame

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
MisterHarold
Regular
Posts: 51
Joined: Tue Jul 17, 2018 10:32 am
Location: Philippines
Contact:

[SOLVED] Stealth bar minigame

#1 Post by MisterHarold »

barsa.png
barsa.png (5.44 KiB) Viewed 495 times
This game mechanic is often used in stealth games where you have to do certain task like scavenging without getting caught.

So I have two bars. The objective is to fill the "win" bar. Everytime you click, both bars fill up. The "fail" bar fills much faster but decreases after a certain amount of time. The "win" bar fills much slower, also decreases after some time. You win the game by filling the "win" bar and you lose if the "fail" bar fills up first.

Does anyone know how to do this? Thanks.
Last edited by MisterHarold on Wed Jun 08, 2022 3:37 am, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1031
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Stealth bar minigame

#2 Post by m_from_space »

I mean do you want us to actually write all the code? ^^

What did you come up with so far? What are you struggling with exactly? Happy to help nevertheless!

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Stealth bar minigame

#3 Post by zmook »

Try this thread as a starting point: viewtopic.php?t=30970
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

MisterHarold
Regular
Posts: 51
Joined: Tue Jul 17, 2018 10:32 am
Location: Philippines
Contact:

Re: Stealth bar minigame

#4 Post by MisterHarold »

This is what I came up with:

Code: Select all

screen game():
  #win bar
  default max_value = 100
  default value = max_value * 0
  default dec_value = 3
  default inc_value = 5 
  default interval = 2.0 

  
  vbar:
    value AnimatedValue(value, max_value, 0.1)
    range max_value

    align (0.5, 0.5)
    right_bar "#00f"
    left_bar "#FFFFFF"
    
    xysize (25, 300)
  
  if value > 0: 
    timer interval:
      repeat True
      action SetScreenVariable("value", value - dec_value)
  
  if value < max_value: 
    key "mouseup_1" action SetScreenVariable("value", value + inc_value)
  
  if value >= max_value: 
    timer 0.01 action Jump('youwin')

  elif value <= 0:
    pass

  #fail bar
  default max_value2 = 80
  default value2 = max_value2 * 0
  default dec_value2 = 3
  default inc_value2 = 7 
  default interval2 = 1.0 
  
  
  vbar:
    value AnimatedValue(value, max_value2, 0.1)
    range max_value2

    align (0.4, 0.5)
    right_bar "#FF0000"
    left_bar "#FFFFFF"
    
    xysize (25, 300)
  
  if value2 > 0: 
    timer interval2:
      repeat True
      action SetScreenVariable("value", value - dec_value2)
  
  if value2 < max_value2: 
    key "mouseup_1" action SetScreenVariable("value", value + inc_value2)
  
  if value2 >= max_value2: 
    timer 0.01 action Jump("youlose")

  elif value2 <= 0:
    pass    

label start:
  call screen game

     
label youwin:
    "Congratulations."
return

label youlose:
    "You got caught."
return    
The problem is the fail bar wont go to the lose screen after filling up completely. Also, both of the bars fills and decreases at the same pace. They're not supposed to be the same.

Note: I modified the code from this viewtopic.php?f=8&t=60232

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1031
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Stealth bar minigame

#5 Post by m_from_space »

The reason the lose condition does not trigger is that you actually do not raise value2 and also that the lose bar shows value instead of value2. Check all the variables you are using inside the code! I also would suggest not to use the name "value" for a variable, since it's a renpy keyword.

Here is your code with better named variables (unaltered), so you can easily spot the mistakes you make:

Code: Select all

screen game():
    #win bar
    default max_win_points = 100
    default win_points = max_win_points * 0
    default dec_win_points = 3
    default inc_win_points = 5
    default interval = 2.0

    vbar:
        value AnimatedValue(win_points, max_win_points, 0.1)
        range max_win_points

        align (0.5, 0.5)
        right_bar "#00f"
        left_bar "#FFFFFF"

        xysize (25, 300)

    if win_points > 0:
        timer interval:
            repeat True
            action SetScreenVariable("win_points", win_points - dec_win_points)

    if win_points < max_win_points:
        key "mouseup_1" action SetScreenVariable("win_points", win_points + inc_win_points)

    if win_points >= max_win_points:
        timer 0.01 action Jump('youwin')

    elif win_points <= 0:
        pass

    #fail bar
    default max_fail_points = 80
    default fail_points = max_fail_points * 0
    default dec_fail_points = 3
    default inc_fail_points = 7
    default interval2 = 1.0

    vbar:
        value AnimatedValue(win_points, max_fail_points, 0.1)
        range max_fail_points

        align (0.4, 0.5)
        right_bar "#FF0000"
        left_bar "#FFFFFF"

        xysize (25, 300)

    if fail_points > 0:
        timer interval2:
            repeat True
            action SetScreenVariable("win_points", win_points - dec_fail_points)

    if fail_points < max_fail_points:
        key "mouseup_1" action SetScreenVariable("win_points", win_points + inc_fail_points)

    if fail_points >= max_fail_points:
        timer 0.01 action Jump("youlose")

    elif fail_points <= 0:
        pass

MisterHarold
Regular
Posts: 51
Joined: Tue Jul 17, 2018 10:32 am
Location: Philippines
Contact:

Re: Stealth bar minigame

#6 Post by MisterHarold »

m_from_space wrote: Wed Jun 08, 2022 2:50 am The reason the lose condition does not trigger is that you actually do not raise value2 and also that the lose bar shows value instead of value2. Check all the variables you are using inside the code! I also would suggest not to use the name "value" for a variable, since it's a renpy keyword.
Thanks for the advice. I renamed the "value". Here is the final code that works:

Code: Select all

screen game():
  #win bar
  default max_value = 100
  default winbar = max_value * 0
  default dec_value = 3
  default inc_value = 5 
  default interval = 1.5 

  vbar:
    value AnimatedValue(winbar, max_value, 0.1)
    range max_value

    align (0.5, 0.5)
    right_bar "#00f"
    left_bar "#FFFFFF"
    
    xysize (25, 300)
  
  if winbar > 0: 
    timer interval:
      repeat True
      action SetScreenVariable("winbar", winbar - dec_value)
  
  if winbar >= max_value: 
    timer 0.01 action Jump('youwin')

  elif winbar <= 0:
    pass

  #fail bar
  default max_value2 = 80
  default failbar = max_value2 * 0
  default dec_value2 = 3
  default inc_value2 = 7 
  default interval2 = 0.5   
    
  vbar:
    value AnimatedValue(failbar, max_value2, 0.1)
    range max_value2

    align (0.4, 0.5)
    right_bar "#FF0000"
    left_bar "#FFFFFF"
    
    xysize (25, 300)
  
  if failbar > 0: 
    timer interval2:
      repeat True
      action SetScreenVariable("failbar", failbar - dec_value2)
  
  if winbar < max_value: 
    key "mouseup_1" action [SetScreenVariable("failbar", failbar + inc_value2),SetScreenVariable("winbar", winbar + inc_value)]   

  if failbar >= max_value2: 
    timer 0.01 action Jump("youlose")

  elif failbar <= 0:
    pass    

label start:
  call screen game

     
label youwin:
    "Congratulations."
return

label youlose:
    "You got caught."
return    

Post Reply

Who is online

Users browsing this forum: No registered users