Adds input buffering to allow you to queue a turn after a turn

master
TechieDamien 2025-08-02 10:56:52 +01:00
parent 3b2c5c2103
commit fafc415a92
Signed by: TechieDamien
GPG Key ID: 2ACE3574E164B780
1 changed files with 13 additions and 1 deletions

View File

@ -11,6 +11,8 @@ var state : States = States.ALIVE
var colour_index : int = 0
var current_direction : Vector2 = Vector2.RIGHT
var old_direction : Vector2 = Vector2.RIGHT
var buffered_direction : Vector2 = Vector2.ZERO
var should_buffer_direction : bool = false
var inputs : Dictionary[String, Vector2] = {"right": Vector2.RIGHT,
"left": Vector2.LEFT,
@ -199,6 +201,12 @@ func process_movement(new_direction : Vector2, prevent_movment : bool = false) -
# Update the sprite
update_sprite()
if buffered_direction != Vector2.ZERO:
current_direction = buffered_direction
buffered_direction = Vector2.ZERO
else:
should_buffer_direction = false
func update_sprite() -> void:
@ -399,7 +407,11 @@ func _unhandled_input(event: InputEvent) -> void:
if event is InputEventKey and part_type == PartTypes.HEAD:
for dir in inputs.keys():
if event.is_action_pressed(dir) and current_direction != -inputs[dir]:
current_direction = inputs[dir]
if should_buffer_direction:
buffered_direction = inputs[dir]
else:
current_direction = inputs[dir]
should_buffer_direction = true
# If we leave the arena