Hi and welcome to the GMC!
In your power object or in some controller object, you can use a variable to keep track of the currently remaining amount of power.
For example, in the create event of your power object (let's call it obj_power), you can write:
This will create the variable power in obj_power and set its value to 100, representing 100% power.
We can then also use a variable to keep track of the current power consumption.
In the create event of obj_power:
This will be the amount of power that gets consumed every step (or every frame).
In the door object, when you close the door, you can increase the consumption:
Code:
obj_power.consumption += 0.01;
When you open the door, you can decrease it again:
Code:
obj_power.consumption -= 0.01;
Then, in the step event of obj_power, we need to decrease the consumption from the power:
This subtracts consumption from power every step.
In the draw event, you can then draw the power percentage and power consumption to the screen.
So, in the draw event of obj_power, you can do something like:
Code:
draw_self(); // This will draw the "POWER" text
draw_text(x + 160, y, string(power) + "%"; // This draws the power percentage, but you will need to tweak the exact location this gets drawn to
draw_sprite(spr_power_consumption, 0, x + 160, y + 32); // This draws the first power consumption square to the screen
if (consumption > 0.01) { // If consumption is high enough to draw a second square
draw_sprite(spr_power_consumption, 0, x + 160 + 32, y + 32);
}
if (consumption > 0.02) { // If consumption is high enough to draw a third square
draw_sprite(spr_power_consumption, 0, x + 160 + 64, y + 32);
}
// And repeat this for all your squares
You will need to tweak some numbers in this code and it can be optimized a lot, but it may be a good starting point.
I hope this helps!
If you have any questions, don't hesitate to ask them!