Read a tap separately from a hold
LIVE BOXING SCRIPT / C OF G
Append both functions. The order of keys in held remembers the most recent guard. Physical key codes use the positions of WASD on a QWERTY keyboard.
func _input(e: InputEvent) -> void:
if not live or not (e is InputEventKey) or suspended():
return
var k = e.physical_keycode
if k not in [KEY_W, KEY_S, KEY_A, KEY_D, KEY_Q]:
return
get_viewport().set_input_as_handled()
if e.echo:
return
if k in [KEY_A, KEY_D]:
held.erase(k)
if e.pressed:
held.append(k)
if fighters[0].age >= READY:
defend(0, player_guard())
elif e.pressed and k == KEY_Q:
finish("You stepped away.")
elif e.pressed and fighters[0].age >= READY:
punch(0, "high" if k == KEY_W else "low")func player_guard():
if held.is_empty():
return ""
return "high" if held.back() == KEY_A else "low"Press A, press D, release D. The remaining entry is A, so the high guard returns. Punches ignore the keyboard’s automatic key repeat. To start another punch, release the key and tap again after recovery.
