Fixed Audio breaking the entire game

This commit is contained in:
Florian 2025-09-19 10:14:17 +02:00
parent 16d9639dd1
commit 0c0decb12b
8 changed files with 50 additions and 4 deletions

View file

@ -12,8 +12,10 @@ var idle_dir_remaining = 0
var idle_move = true
var target_pos = Vector2.ZERO
var damage = 1
var dead = false
signal grounded
func choose_next_move() -> String:
if $EnemyHurtbox.hp < 2 * $EnemyHurtbox.max_hp / 3 and risen == 0:
risen += 1
@ -24,6 +26,7 @@ func choose_next_move() -> String:
return ["slam", "wave", "splash"].pick_random()
func _physics_process(delta: float) -> void:
if dead: return
up_direction = earthaligner.global_from_local(Vector2.UP)
if attack_ready:
attack_ready = false
@ -69,6 +72,7 @@ func slam():
attack_ready = true
func destroy_below():
if dead: return
for body in $DestructionChecker.get_overlapping_bodies():
if(body.has_method("destroy")): body.destroy()
@ -92,12 +96,15 @@ func splash():
await get_tree().create_timer(5).timeout
attack_ready = true
func hurt(_dmg, _dir):
$AudioStreamPlayer2D.play()
func die():
dead = true
for child in get_children():
if not child is AudioStreamPlayer2D:
child.queue_free()
await $AudioStreamPlayer2D.finished
queue_free()
func _on_enemy_hurtbox_damage_taken() -> void:
if dead: return
$AudioStreamPlayer2D.play()

View file

@ -61,4 +61,5 @@ shape = SubResource("RectangleShape2D_lnbgr")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
[connection signal="damage_taken" from="EnemyHurtbox" to="." method="_on_enemy_hurtbox_damage_taken"]
[connection signal="died" from="EnemyHurtbox" to="." method="die"]

View file

@ -11,6 +11,7 @@ var paused = false
var pause_time = 0.1
var iframes = 0.2
var iframe_time = 0
var dead = false
var check_grounded_delay = 8
@ -19,6 +20,7 @@ func _ready() -> void:
segment.segment_damaged.connect(hurt)
func _physics_process(delta: float) -> void:
if dead: return
iframe_time = max(0, iframe_time - delta)
if not paused:
angle -= TAU * delta * angular_speed * move_dir
@ -31,11 +33,13 @@ func _physics_process(delta: float) -> void:
var ratio = - move_dir * broadth / (2 * y)
var rot_angle = - 2 * asin(ratio)
position = position.rotated(rot_angle)
if dead:
return
if(move_dir == 1 and angle < 1 or move_dir == -1 and angle > PI - 1):
var y = position.length()
var ratio = - move_dir * broadth / (2 * y)
var rot_angle = - 2 * asin(ratio)
$RayCast2D.global_position = position.rotated(rot_angle)
$RayCast2D.rotation = rot_angle
if(move_dir == 1 and angle < 0.5 or move_dir == -1 and angle > PI - 0.5):
@ -44,9 +48,12 @@ func _physics_process(delta: float) -> void:
await get_tree().create_timer(pause_time).timeout
paused = false
move_dir *= -1
if dead:
return
for i in range(segment_count):
var segment_pos_data = calculate_segment_location_and_rotation(i)
if not is_instance_valid(segments[i]):
get_tree().get_root().print_tree_pretty()
segments[i].position = segment_pos_data.position
segments[i].rotation = segment_pos_data.rotation
if check_grounded_delay > 0:
@ -91,6 +98,7 @@ func hurt(damage : int, _dir):
hp -= damage
$AudioStreamPlayer2D.play()
if(hp<=0):
dead = true
for child in get_children():
if not child is AudioStreamPlayer2D:
child.queue_free()

View file

@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/ItemShine.png-41425a3fac8f6530e2b2e4df0c18025
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@ -25,6 +27,10 @@ mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false

View file

@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/updash.png-ddc6856a4b101f20557ef85572ee190a.c
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@ -25,6 +27,10 @@ mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false

View file

@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/backslash.png-149a372aa6b01851fbdc2c6a7a2e54d
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@ -25,6 +27,10 @@ mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false

View file

@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/extrajump.png-5c34a7cf40e9d4d17063d874a102c41
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@ -25,6 +27,10 @@ mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false

View file

@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/platform.png-5334741150dcada29b5e7aa3769fe64f
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@ -25,6 +27,10 @@ mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false