Rework player state system to use an event subscription system to avoid directly calling methods on individual state and having to worry about validity
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
extends Node
|
||||
class_name MovementComponent
|
||||
|
||||
# movement_component.gd
|
||||
# A simple script that checks for movement input and emits a signal with the
|
||||
# direction vector
|
||||
|
||||
signal MovementQueued(direction_vector: Vector2)
|
||||
signal NoMovementQueued
|
||||
|
||||
var direction_vector: Vector2
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var dv := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
|
||||
if dv:
|
||||
direction_vector = dv
|
||||
MovementQueued.emit(dv)
|
||||
else:
|
||||
direction_vector = Vector2.ZERO
|
||||
NoMovementQueued.emit()
|
||||
Reference in New Issue
Block a user