34dc5b026e
Bull's boulder roll now homes on and ploughs through lobby barrels, and the slam shockwave bursts them within its radius. HUD tallies barrels on load and fires a confetti "WOooOoW!" + two gold bonus HP pips when the last one breaks; gates open from run state as fights are cleared. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
1.3 KiB
GDScript
42 lines
1.3 KiB
GDScript
extends StaticBody3D
|
|
## A smashable lobby barrel. Joins the &"barrel" group so the HUD can tally how many
|
|
## remain and fire the "cleared the lobby" reward once the last one bursts.
|
|
|
|
signal destroyed
|
|
|
|
# Preload the broken barrel scene
|
|
const BARREL_BROKEN_SCENE = preload("res://tscn_s/BarrelBroken.tscn")
|
|
|
|
var _destroyed := false
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group(&"barrel")
|
|
|
|
|
|
func destroy_barrel():
|
|
# Guard against a double hit in the same frame counting the same barrel twice.
|
|
if _destroyed:
|
|
return
|
|
_destroyed = true
|
|
|
|
# 1. Instantiate the broken pieces
|
|
var broken_instance = BARREL_BROKEN_SCENE.instantiate()
|
|
|
|
# 2. Place the fragments exactly where the intact barrel currently is
|
|
broken_instance.global_transform = self.global_transform
|
|
|
|
# 3. Add the fragments to the main game tree
|
|
get_parent().add_child(broken_instance)
|
|
|
|
# 4. (Optional) Apply a physics push to the fragments if you want an explosive effect
|
|
for child in broken_instance.get_children():
|
|
if child is RigidBody3D:
|
|
# Pushes pieces slightly outward and upward
|
|
var random_direction = Vector3(randf_range(-1, 1), randf_range(0.5, 1.5), randf_range(-1, 1)).normalized()
|
|
child.apply_central_impulse(random_direction * 5.0)
|
|
|
|
# 5. Announce the smash (the HUD counts down remaining barrels) and remove the barrel
|
|
destroyed.emit()
|
|
queue_free()
|