Add sound effects for player actions and collectables
This commit is contained in:
@@ -12,10 +12,8 @@ func _ready() -> void:
|
||||
await get_tree().process_frame
|
||||
if not lever:
|
||||
var levers_nodes := get_tree().get_nodes_in_group("levers")
|
||||
print("Found levers: ", levers_nodes)
|
||||
for lever_node in levers_nodes:
|
||||
var lever_component: LeverComponent = lever_node.get_node_or_null("LeverComponent")
|
||||
print("Lever component: ", lever_component)
|
||||
if lever_component:
|
||||
lever_component.activated.connect(on_lever_activated)
|
||||
else:
|
||||
@@ -27,7 +25,6 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func on_lever_activated() -> void:
|
||||
print("Lever activated, moving cage.")
|
||||
var tween: Tween = create_tween()
|
||||
var end_position: Vector2 = root.position + move_value
|
||||
tween.tween_property(root, "position", end_position, tween_duration)
|
||||
|
@@ -6,6 +6,7 @@ var has_fade_away: bool = false
|
||||
|
||||
@export var area2d: Area2D
|
||||
@export var collectable_data: CollectableResource
|
||||
@export var sfx: AudioStreamPlayer2D
|
||||
signal collected(amount: int)
|
||||
|
||||
|
||||
@@ -24,5 +25,8 @@ func _ready() -> void:
|
||||
func _on_area2d_body_entered(body: Node2D) -> void:
|
||||
if body.has_node("CanPickUpComponent"):
|
||||
collected.emit(collectable_data.amount)
|
||||
if sfx:
|
||||
sfx.play()
|
||||
if not has_fade_away:
|
||||
await sfx.finished
|
||||
root.queue_free()
|
||||
|
@@ -3,51 +3,70 @@ extends Node
|
||||
|
||||
@export var health: float = 1.0
|
||||
@export var max_health: float = 1.0
|
||||
|
||||
@export var hurt_fx: AudioStreamPlayer2D
|
||||
@export var heal_fx: AudioStreamPlayer2D
|
||||
signal on_health_change(delta: float, total_health: float)
|
||||
signal on_death
|
||||
|
||||
|
||||
func _get_delta(value: float) -> float:
|
||||
var old_value = health
|
||||
return value - old_value
|
||||
|
||||
|
||||
func set_health(new_value: float):
|
||||
var delta = _get_delta(new_value)
|
||||
|
||||
|
||||
if sign(delta) > 0:
|
||||
if heal_fx:
|
||||
heal_fx.play()
|
||||
elif sign(delta) < 0:
|
||||
if hurt_fx:
|
||||
hurt_fx.play()
|
||||
|
||||
await hurt_fx.finished
|
||||
|
||||
if new_value >= max_health:
|
||||
health = max_health
|
||||
on_health_change.emit(delta, health)
|
||||
return
|
||||
|
||||
|
||||
health = new_value
|
||||
|
||||
|
||||
if health <= 0:
|
||||
on_death.emit()
|
||||
return
|
||||
|
||||
|
||||
on_health_change.emit(delta, health)
|
||||
|
||||
|
||||
func decrease_health(value: float):
|
||||
var delta = _get_delta(value)
|
||||
|
||||
|
||||
health -= value
|
||||
|
||||
if hurt_fx:
|
||||
hurt_fx.play()
|
||||
await hurt_fx.finished
|
||||
|
||||
if health <= 0:
|
||||
on_death.emit()
|
||||
return
|
||||
|
||||
|
||||
on_health_change.emit(delta, health)
|
||||
|
||||
|
||||
|
||||
func increase_health(value: float):
|
||||
var delta = _get_delta(value)
|
||||
|
||||
|
||||
health += value
|
||||
|
||||
|
||||
if health >= max_health:
|
||||
health = max_health
|
||||
on_health_change.emit(delta, health)
|
||||
return
|
||||
|
||||
|
||||
health += value
|
||||
if heal_fx:
|
||||
heal_fx.play()
|
||||
on_health_change.emit(delta, health)
|
||||
|
||||
|
@@ -28,6 +28,8 @@ func _on_body_entered(body: Node2D) -> void:
|
||||
if body is PlayerController:
|
||||
handle_launchpad_animation()
|
||||
body.velocity.y = -jump_force
|
||||
if body.jump_sfx:
|
||||
body.jump_sfx.play()
|
||||
|
||||
|
||||
func handle_launchpad_animation() -> void:
|
||||
|
@@ -29,7 +29,6 @@ func _on_body_entered(body: Node2D) -> void:
|
||||
|
||||
|
||||
func activate() -> void:
|
||||
print("Lever activated.")
|
||||
activated.emit()
|
||||
sprite2d.frame = start_animation_index + 1
|
||||
var timer := get_tree().create_timer(animation_duration)
|
||||
|
Reference in New Issue
Block a user