Created
August 22, 2018 04:17
-
-
Save jesseflorig/4b9fd832c3db8ee25a52994ec2f77cb4 to your computer and use it in GitHub Desktop.
Detect key press combos for further evaluation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends KinematicBody2D | |
const COMBO_TIMEOUT = 0.3 # Timeout between key presses | |
const MAX_COMBO_CHAIN = 2 # Maximum key presses in a combo | |
var last_key_delta = 0 # Time since last keypress | |
var key_combo = [] # Current combo | |
func _input(event): | |
if event is InputEventKey and event.pressed and !event.echo: # If distinct key press down | |
print(last_key_delta) | |
if last_key_delta > COMBO_TIMEOUT: # Reset combo if stale | |
key_combo = [] | |
key_combo.append(event.scancode) # Otherwise add it to combo | |
if key_combo.size() > MAX_COMBO_CHAIN: # Prune if necessary | |
key_combo.pop_front() | |
print(key_combo) # Log the combo (could pass to combo evaluator) | |
last_key_delta = 0 # Reset keypress timer | |
func _physics_process(delta): | |
last_key_delta += delta # Track time between keypresses |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment