Adds input buffering to allow you to queue a turn after a turn
parent
3b2c5c2103
commit
fafc415a92
|
@ -11,6 +11,8 @@ var state : States = States.ALIVE
|
||||||
var colour_index : int = 0
|
var colour_index : int = 0
|
||||||
var current_direction : Vector2 = Vector2.RIGHT
|
var current_direction : Vector2 = Vector2.RIGHT
|
||||||
var old_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,
|
var inputs : Dictionary[String, Vector2] = {"right": Vector2.RIGHT,
|
||||||
"left": Vector2.LEFT,
|
"left": Vector2.LEFT,
|
||||||
|
@ -200,6 +202,12 @@ func process_movement(new_direction : Vector2, prevent_movment : bool = false) -
|
||||||
# Update the sprite
|
# Update the sprite
|
||||||
update_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:
|
func update_sprite() -> void:
|
||||||
|
|
||||||
sprite.modulate = COLOURS[colour_index]
|
sprite.modulate = COLOURS[colour_index]
|
||||||
|
@ -399,7 +407,11 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event is InputEventKey and part_type == PartTypes.HEAD:
|
if event is InputEventKey and part_type == PartTypes.HEAD:
|
||||||
for dir in inputs.keys():
|
for dir in inputs.keys():
|
||||||
if event.is_action_pressed(dir) and current_direction != -inputs[dir]:
|
if event.is_action_pressed(dir) and current_direction != -inputs[dir]:
|
||||||
|
if should_buffer_direction:
|
||||||
|
buffered_direction = inputs[dir]
|
||||||
|
else:
|
||||||
current_direction = inputs[dir]
|
current_direction = inputs[dir]
|
||||||
|
should_buffer_direction = true
|
||||||
|
|
||||||
|
|
||||||
# If we leave the arena
|
# If we leave the arena
|
||||||
|
|
Loading…
Reference in New Issue