- Jul 4, 2017
- 2,547
- 4,631
So, I've taken on a personal project to try to recreate in Renpy the core "minigame" of the abandoned game "OnEdge". However I am at a loss on how to recreate on aspect of the game, and humbly ask for help.
In the game there are a two score counters: a "progress bar" and a "hearts counter". As each round comes up, the player chooses an action which will add a certain amount of "progress". When the "progress bar" fills up to 100%, a "heart" is added to the heart counter and progress resets to 0%. There is a nice animation with the progress bar incrementing smoothly to the new value.
However, the player action might add more "progress points" than can fit in the remaining space of the progress bar i.e. there is an "overflow". The "overflow" value is not lost, it is added onto the progress after the heart is generated and the bar resets to zero. There is even the possibility that the number of points added in one action might be 200 or 250% i.e. multiple hearts are generated for the action.
In my thinking , there needs to be a series of events take place on the screens:
- bar animated increment (can use AnimatedValue),
- bar reaches top and "triggers" the heart to be added. (update the global variable holding the heart state. Ideally this causes the Heart screen to show the new state)
- bar value and visual state is reset to 0 (does not need to be animated)
- bar animated increment to the new value (the "overflow" amount)
I'm just not sure how to do things like:
- "trigger" a global variable change when the progress bar animation reaches 100%
- then reset the progress bar value to 0
- then start a new progress bar animation to the next value.
From my previous programming experience I really want to add "event listeners", but it seems like Renpy screens do not work like that... I have tried many things with timers, but I can't get them to do what I want - especially as the number and sequence of timers will be different in different progress points situations.
Anyway, here is some sample code that shows a simplified example, I hope that someone with more experience can suggest what to try next:
In the game there are a two score counters: a "progress bar" and a "hearts counter". As each round comes up, the player chooses an action which will add a certain amount of "progress". When the "progress bar" fills up to 100%, a "heart" is added to the heart counter and progress resets to 0%. There is a nice animation with the progress bar incrementing smoothly to the new value.
However, the player action might add more "progress points" than can fit in the remaining space of the progress bar i.e. there is an "overflow". The "overflow" value is not lost, it is added onto the progress after the heart is generated and the bar resets to zero. There is even the possibility that the number of points added in one action might be 200 or 250% i.e. multiple hearts are generated for the action.
In my thinking , there needs to be a series of events take place on the screens:
- bar animated increment (can use AnimatedValue),
- bar reaches top and "triggers" the heart to be added. (update the global variable holding the heart state. Ideally this causes the Heart screen to show the new state)
- bar value and visual state is reset to 0 (does not need to be animated)
- bar animated increment to the new value (the "overflow" amount)
I'm just not sure how to do things like:
- "trigger" a global variable change when the progress bar animation reaches 100%
- then reset the progress bar value to 0
- then start a new progress bar animation to the next value.
From my previous programming experience I really want to add "event listeners", but it seems like Renpy screens do not work like that... I have tried many things with timers, but I can't get them to do what I want - especially as the number and sequence of timers will be different in different progress points situations.
Anyway, here is some sample code that shows a simplified example, I hope that someone with more experience can suggest what to try next:
Code:define state_on = 1 define state_off = 0 default hearts_counter_states = [state_off, state_off, state_off] default progress = 0 default progress_max = 100 # using placeholders instead of images for this example image heart_on = Solid("#A22", xsize=100, ysize=100) image heart_off = Solid("#777", xsize=100, ysize=100) transform heart_dissolve(): anchor (0.5, 0.5) on show: alpha 0.0 zoom 0.0 time 0.2 easein 0.2 alpha 1.0 zoom 1.0 on hide: easeout 0.2 alpha 0.0 zoom 0.0 screen hearts_counter(): fixed xpos 0.3 ypos 0.1: vbox: text "Hearts" hbox: for i in range(0,3): fixed xsize 120 xpos 50 ypos 50: showif hearts_counter_states[i] == state_off: add "heart_off" at heart_dissolve elif hearts_counter_states[i] == state_on: add "heart_on" at heart_dissolve screen progress_bar(): fixed xpos 0.3 ypos 0.3: vbox: text "Progress" hbox: bar value AnimatedValue(value=progress, range=progress_max, delay=0.8) xsize 340 screen player_actions(): fixed xpos 0.3 ypos 0.5: text "Actions" hbox: spacing 20 frame xsize 200 ysize 150: textbutton "Add progress 60" xfill True yfill True: action [SetVariable("progress", progress + 60), Return(True)] frame xsize 200 ysize 150: textbutton "Add progress 110" xfill True yfill True: action [SetVariable("progress", progress + 110), Return(True)] frame xsize 200 ysize 150: textbutton _("Quit") xfill True yfill True: action Return(False) label start: show screen hearts_counter() with dissolve show screen progress_bar() label .loop: call screen player_actions() if _return == False: jump .end jump .loop label .end: hide screen hearts_counter hide screen progress_bar "done" return