beginning of state machine

This commit is contained in:
OddlyTimbot 2025-10-20 15:42:27 -04:00
parent b3ca85807f
commit b8cdde4763

View File

@ -28,9 +28,16 @@ func _physics_process(delta):
# As good practice, you should replace UI actions with custom gameplay actions. # As good practice, you should replace UI actions with custom gameplay actions.
handle_input() handle_input()
handle_movement(delta) handle_movement(delta)
update_states()
move_and_slide() move_and_slide()
handle_collisions() handle_collisions()
#Create a State Machine.........t.w.
func update_states()->void:
match current_state:
State.JUMP when velocity.y >0:
current_state = State.FALLING
func handle_input()->void: func handle_input()->void:
# Handle jump. # Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor(): if Input.is_action_just_pressed("jump") and is_on_floor():
@ -79,8 +86,6 @@ func handle_movement(_delta)->void:
if current_state == State.JUMP: if current_state == State.JUMP:
#apply normal velocity #apply normal velocity
velocity += get_gravity() * _delta velocity += get_gravity() * _delta
if velocity.y>0:
current_state = State.FALLING
else: else:
#apply hard gravity, character falling #apply hard gravity, character falling
velocity += get_gravity() * hard_gravity * _delta velocity += get_gravity() * hard_gravity * _delta