Feat/2 weapons foundation #6
@@ -22,6 +22,7 @@ var double_jump_player: AudioStreamPlayer
|
|||||||
|
|
||||||
# UI
|
# UI
|
||||||
var hit_marker: Control
|
var hit_marker: Control
|
||||||
|
var _hit_marker_tween: Tween
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@@ -65,6 +66,7 @@ func _setup_audio() -> void:
|
|||||||
|
|
||||||
hit_player = AudioStreamPlayer.new()
|
hit_player = AudioStreamPlayer.new()
|
||||||
hit_player.stream = load("res://assets/sounds/hit_confirm.wav")
|
hit_player.stream = load("res://assets/sounds/hit_confirm.wav")
|
||||||
|
hit_player.max_polyphony = 8
|
||||||
add_child(hit_player)
|
add_child(hit_player)
|
||||||
|
|
||||||
slide_player = AudioStreamPlayer.new()
|
slide_player = AudioStreamPlayer.new()
|
||||||
@@ -104,6 +106,8 @@ func _setup_hit_marker() -> void:
|
|||||||
rect.rotation = angle
|
rect.rotation = angle
|
||||||
hit_marker.add_child(rect)
|
hit_marker.add_child(rect)
|
||||||
|
|
||||||
|
var _last_hit_sound_time: int = 0
|
||||||
|
|
||||||
func spawn_damage_number(amount: float, hit_pos: Vector3) -> void:
|
func spawn_damage_number(amount: float, hit_pos: Vector3) -> void:
|
||||||
if not camera or not _damage_layer: return
|
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)
|
_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()
|
hit_player.play()
|
||||||
|
|
||||||
|
if _hit_marker_tween and _hit_marker_tween.is_valid():
|
||||||
|
_hit_marker_tween.kill()
|
||||||
|
|
||||||
hit_marker.modulate.a = 1.0
|
hit_marker.modulate.a = 1.0
|
||||||
var tween = create_tween()
|
_hit_marker_tween = create_tween()
|
||||||
tween.tween_property(hit_marker, "modulate:a", 0.0, 0.4)
|
_hit_marker_tween.tween_property(hit_marker, "modulate:a", 0.0, 0.4)
|
||||||
|
|
||||||
func _ensure_machine() -> MovementStateMachine:
|
func _ensure_machine() -> MovementStateMachine:
|
||||||
if is_instance_valid(_machine):
|
if is_instance_valid(_machine):
|
||||||
|
|||||||
Reference in New Issue
Block a user