How to implement a multi-barrel energy system?

In a side-scrolling action game, how can I implement a system where the character has three energy bars? Each special attack consumes one bar, and the system slowly restores them over time, refilling the first bar before moving on to the second, and so on. Additionally, the character can gain extra restoration upon hitting enemies. How can this be implemented?

Let me share my design approach (though using GD scripts would be more convenient, I feel VS could also handle it).

1: Create three progress bars, let’s call them Progress Bar 1, Progress Bar 2, and Progress Bar 3 (representing your three-bar energy system). If your energy bars are arranged in parallel, it will be simpler. If they overlap, you might need more detailed handling.

Progress Bar Design:
(1) Display the progress bar images.
(2) Set the values, for example, set the maximum value to 100 for all of them. The values can be controlled via GD or VS properties. (I’m not entirely sure if VS properties can control the progress bars; I haven’t tried.)

2: Use a global variable to manage these three energy bars, such as [Total Energy] (with a range of 0-300).

3: Build the framework and implement your specific features.
(1) Consume one bar per special attack: Special Attack — [Total Energy] decreases by 100 (when [Total Energy] >= 100).
(2) Automatic energy recovery: Increase [Total Energy] by 1 every time interval (you can use GD’s process or VS’s time loop).
(3) Additional recovery: Trigger extra recovery — increase [Total Energy] by the corresponding amount.
(4) [Bind Values] (This step is crucial as it directly affects the visual display of the energy bars. It’s easier to do this with GD scripts; VS might require some thought.)

(I just thought of a simpler method: (Set values frame by frame))
Progress Bar 3 value = Total Energy - 200 (if Progress Bar 3 value < 0, then Progress Bar 3 = 0)
Progress Bar 2 value = Total Energy - 100 (if Progress Bar 2 value < 0, then Progress Bar 2 = 0)
Progress Bar 1 value = Total Energy (if Progress Bar 1 value < 0, then Progress Bar 1 = 0)
Remember to also limit the Total Energy value frame by frame: if Total Energy > 300, set Total Energy = 300; if < 0, set = 0.

(5) Since the progress bars display their progress based on their values, once the values are bound, they will automatically increase or decrease visually.

2 Likes

My advice is to put this system aside for now and do something else. Once the 2.0 sublayer system is released, you can just set up three conditions in the sublayer and you’re done.

If you don’t use scripts now, the visual scripting only supports attaching subscripts as a feature. Once the sublayer is out, you can build whatever you want.