Fix the dash cooldown gate in a Godot game
Your task
Your Godot game's dash ticked its cooldown down by 1 every frame and fired whenever the button was held. On slow phones it recharged at the wrong speed and fired twice. The fix counts the cooldown in milliseconds of real time and fires only when the button goes from up to down.
An assistant wrote simulate_dash_frames(frame_dts_ms, button_down, cooldown_ms). It is in the editor. It has a bug. Find it and fix it.
Input and output:
frame_dts_ms: each frame's delta time in milliseconds, in order.button_down: whether the dash button is held during each frame.cooldown_ms: how long the dash takes to recharge after it fires.- Return one boolean per frame: whether the dash fires on that frame.
Rules the tests check:
- If the lists differ in length, use only as many frames as the shorter one has.
- The remaining cooldown starts at 0, and the button counts as up before the first frame.
- Each frame, in this order:
- Subtract the frame's delta from the remaining cooldown, never going below 0. A negative delta counts as 0.
- The dash fires when the button is down this frame, was up the frame before, and the remaining cooldown is 0. A cooldown that runs out during this frame's delta can be used this frame.
- When it fires, the remaining cooldown becomes
cooldown_ms, or 0 if that is negative.
Examples
simulate_dash_frames(frame_dts_ms: list[int], button_down: list[bool], cooldown_ms: int) -> list[bool]Example 1
Input
simulate_dash_frames([16, 16, 16, 16], [False, True, True, True], 32)Output
[False, True, False, False]Example 2
Input
simulate_dash_frames([8, 8, 8, 8, 8, 8], [True, False, True, False, True, False], 16)Output
[True, False, True, False, True, False]