little work

This commit is contained in:
Lilith Schier 2026-05-02 08:33:08 +02:00
parent f389e4e807
commit ab79ace226
4 changed files with 179 additions and 98 deletions

View file

@ -22,6 +22,12 @@ var jump_ascent_speed := 200.0
var late_jump_time_limit := 0.15
@export_custom(PROPERTY_HINT_NONE, "suffix:px/s")
var slash_speed_boost := 90.0
## The angle difference from perfect left/right that still counts.
@export_range(0, 360, 0.1, "radians_as_degrees")
var side_input_angle := PI / 4
## The angle difference from perfect down that still counts.
@export_range(0, 360, 0.1, "radians_as_degrees")
var down_input_angle := PI / 4
var _max_input_buffer_time_usec:
get():
@ -31,6 +37,7 @@ var _is_jumping := false
var _jump_allowed_time := 0.0
var _current_direction := Vector2.ZERO
var _is_facing_right := true
@onready var _playback: AnimationNodeStateMachinePlayback = %AnimationTree["parameters/playback"]
var _input_buffer: Array[BufferedInput] = []
@ -41,10 +48,6 @@ class BufferedInput:
var time: int
func _ready() -> void:
%Body.play()
func _unhandled_input(event: InputEvent) -> void:
if event.is_echo():
return
@ -52,14 +55,12 @@ func _unhandled_input(event: InputEvent) -> void:
or event.is_action(&"move_right")
or event.is_action(&"move_up")
or event.is_action(&"move_down") ):
_current_direction = Vector2(
Input.get_axis(&"move_left", &"move_right"),
Input.get_axis(&"move_up", &"move_down"),
_current_direction = Input.get_vector(
&"move_left",
&"move_right",
&"move_up",
&"move_down",
)
if _current_direction.x < 0:
_is_facing_right = false
elif _current_direction.x > 0:
_is_facing_right = true
if event.is_action(&"jump") or event.is_action(&"attack"):
var buffered_input := BufferedInput.new()
buffered_input.direction = _current_direction
@ -70,13 +71,18 @@ func _unhandled_input(event: InputEvent) -> void:
func _physics_process(delta: float) -> void:
if _current_direction.x < 0:
_is_facing_right = false
elif _current_direction.x > 0:
_is_facing_right = true
# Walking on the floor
if is_on_floor():
if sign(velocity.x) != sign(_current_direction.x):
velocity.x *= grounded_speed_stop_decay ** delta
else:
velocity.x *= grounded_speed_decay ** delta
var target_vel_x := _current_direction.x * walk_max_speed
var target_vel_x: float = sign(_current_direction.x) * walk_max_speed
var is_walking := target_vel_x != 0
if not is_walking or abs(velocity.x) < walk_max_speed:
velocity.x = move_toward(
@ -127,12 +133,6 @@ func _is_holding_wall() -> bool:
func _process(_delta: float) -> void:
handle_buffered_inputs()
%Body.scale.x = 1 if _is_facing_right else -1
if _is_holding_wall():
%Body.play(&"wall_grab")
elif is_on_floor() and _current_direction.x != 0.0:
%Body.play(&"walk")
else:
%Body.play(&"idle")
func handle_buffered_inputs() -> void:
@ -151,7 +151,7 @@ func handle_buffered_inputs() -> void:
# Grounded jump
if (input.event.is_pressed()
and _jump_allowed_time > 0
and (not is_on_floor() or input.direction.y <= 0) ):
and (not is_on_floor() or not is_input_vec_down(input.direction)) ):
input_found = true
_jump_allowed_time = 0
_jump_ascent_remaining_time = jump_ascent_max_time
@ -172,8 +172,15 @@ func handle_buffered_inputs() -> void:
elif input.event.is_action_pressed(&"attack"):
input_found = true
velocity.x += (1 if _is_facing_right else -1) * slash_speed_boost
_playback.travel(&"attack")
_input_buffer = _input_buffer.slice(i + 1)
break
$AnimationPlayer.play("slash")
if input_found:
_input_buffer = _input_buffer.slice(i + 1)
break
func is_input_vec_down(vec: Vector2) -> bool:
return abs(vec.angle_to(Vector2.DOWN)) < down_input_angle and vec.length() > 0.1