Implement janky input buffering.

This commit is contained in:
2025-06-24 19:41:34 -06:00
parent 827f333e72
commit b182b4264a
19 changed files with 161 additions and 154 deletions
+25 -9
View File
@@ -6,7 +6,7 @@ extends CharacterBody2D
signal state_change(old: States, new: States)
enum States {NULL, IDLE, RUN_START, RUN, ROLL, JUMP_START, JUMP, FALL, LAND, DAMAGE, RAGDOLL, BOUNCE, LAY, SHOOT, JAB, STRAIGHT, KICK, POUND, POUND_FALL}
enum States {IDLE, RUN_START, RUN, ROLL, JUMP_START, JUMP, FALL, LAND, DAMAGE, RAGDOLL, BOUNCE, LAY, SHOOT, JAB, STRAIGHT, KICK, POUND, POUND_FALL}
const STATES_IMMOBILE = [States.ROLL, States.DAMAGE, States.RAGDOLL, States.BOUNCE, States.LAY, States.SHOOT, States.JAB, States.STRAIGHT, States.KICK, States.POUND, States.POUND_FALL]
const STATES_MOVEMENT = [States.RUN_START, States.RUN, States.JUMP_START, States.JUMP, States.FALL]
@@ -32,7 +32,7 @@ const ROLL_VELOCITY = 150.0
const ROLL_DECEL = 1080
var state: States = States.IDLE: set = _set_state
var state_buffer: States = States.NULL
var input_buffer: StringName = ""
var direction: float
func _set_state(s: States):
@@ -47,9 +47,23 @@ func _physics_process(delta):
if not is_on_floor():
velocity += get_gravity() * delta
# Buffer inputs
if Input.is_action_just_pressed(&"jump"):
input_buffer = &"jump"
if Input.is_action_just_pressed(&"roll"):
input_buffer = &"roll"
if Input.is_action_just_pressed(&"roll_jump"):
input_buffer = &"roll_jump"
if Input.is_action_just_pressed(&"melee"):
input_buffer = &"melee"
# Jumping
if state not in STATES_IMMOBILE and state not in STATES_AIRBORNE and Input.is_action_just_pressed("jump") and is_on_floor():
if state not in STATES_IMMOBILE and state not in STATES_AIRBORNE and input_buffer == "jump" and Input.is_action_pressed("jump") and is_on_floor():
state = States.JUMP_START
input_buffer = ""
audio_player.stream = JUMP_SOUND
audio_player.play()
@@ -62,7 +76,7 @@ func _physics_process(delta):
# Short hops
if state in [States.JUMP_START, States.JUMP] and Input.is_action_just_released("jump") and !is_on_floor():
velocity.y = velocity.y / 2
velocity.y /= 2
# Falling
if state in [States.IDLE] + STATES_MOVEMENT and velocity.y > 0:
@@ -74,11 +88,12 @@ func _physics_process(delta):
state = States.RUN
else:
state = States.LAND
# Rolls
if state not in STATES_IMMOBILE and state != States.ROLL and \
(Input.is_action_just_pressed("roll_jump") or (Input.is_action_just_pressed("roll") and direction)):
if state not in STATES_IMMOBILE and state != States.ROLL and input_buffer in ["roll", "roll_jump"] and \
(Input.is_action_pressed("roll_jump") or (Input.is_action_pressed("roll") and direction)):
state = States.ROLL
input_buffer = ""
if is_on_floor():
var roll_dust = ROLL_DUST.instantiate()
@@ -91,11 +106,12 @@ func _physics_process(delta):
else:
velocity.x = -ROLL_VELOCITY
if velocity.y >= 0 && Input.is_action_just_pressed("roll_jump"):
if velocity.y >= 0 && Input.is_action_pressed("roll_jump"):
velocity.y = -120
# Melee
if state not in STATES_IMMOBILE and Input.is_action_just_pressed("melee"):
if state not in STATES_IMMOBILE and input_buffer == "melee" and Input.is_action_pressed("melee"):
input_buffer = ""
if Input.is_action_pressed("roll"):
state = States.POUND
velocity.x = 0