feat: implement PlayerMovementController to handle movement input, audio cues, and UI feedback

This commit is contained in:
DottsGit
2026-06-04 17:22:30 -04:00
parent 5ae6e20039
commit 7b7107c5d6
+15 -3
View File
@@ -22,6 +22,7 @@ var double_jump_player: AudioStreamPlayer
# UI
var hit_marker: Control
var _hit_marker_tween: Tween
func _ready() -> void:
@@ -65,6 +66,7 @@ func _setup_audio() -> void:
hit_player = AudioStreamPlayer.new()
hit_player.stream = load("res://assets/sounds/hit_confirm.wav")
hit_player.max_polyphony = 8
add_child(hit_player)
slide_player = AudioStreamPlayer.new()
@@ -104,6 +106,8 @@ func _setup_hit_marker() -> void:
rect.rotation = angle
hit_marker.add_child(rect)
var _last_hit_sound_time: int = 0
func spawn_damage_number(amount: float, hit_pos: Vector3) -> void:
if not camera or not _damage_layer: return
@@ -121,11 +125,19 @@ func spawn_damage_number(amount: float, hit_pos: Vector3) -> void:
_damage_layer.add_child(label)
# Play sound and flash hit marker
# Only play the hit sound and flash the marker once per frame (or roughly every 16ms)
# This prevents the shotgun from stacking 8 hit sounds in a single frame.
var now = Time.get_ticks_msec()
if now - _last_hit_sound_time > 10:
_last_hit_sound_time = now
hit_player.play()
if _hit_marker_tween and _hit_marker_tween.is_valid():
_hit_marker_tween.kill()
hit_marker.modulate.a = 1.0
var tween = create_tween()
tween.tween_property(hit_marker, "modulate:a", 0.0, 0.4)
_hit_marker_tween = create_tween()
_hit_marker_tween.tween_property(hit_marker, "modulate:a", 0.0, 0.4)
func _ensure_machine() -> MovementStateMachine:
if is_instance_valid(_machine):