2026-09-14 18:36:02 +02:00
|
|
|
extends Area3D
|
|
|
|
|
class_name HazardZone
|
2026-09-15 12:02:57 +02:00
|
|
|
## Damages the player on enter. Optional billboard art via texture_path.
|
2026-09-14 18:36:02 +02:00
|
|
|
|
|
|
|
|
@export var damage: int = 1
|
|
|
|
|
@export var death_cause_key: String = "death_default"
|
|
|
|
|
@export var cooldown: float = 1.0
|
2026-09-15 12:02:57 +02:00
|
|
|
@export var texture_path: String = ""
|
|
|
|
|
@export var billboard_height: float = 1.4
|
2026-09-14 18:36:02 +02:00
|
|
|
|
|
|
|
|
var _ready_to_hurt: bool = true
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
body_entered.connect(_on_body_entered)
|
|
|
|
|
collision_layer = 0
|
|
|
|
|
collision_mask = 2
|
2026-09-15 12:02:57 +02:00
|
|
|
_ensure_billboard()
|
|
|
|
|
|
|
|
|
|
func _ensure_billboard() -> void:
|
|
|
|
|
if texture_path == "":
|
|
|
|
|
return
|
|
|
|
|
var bill := get_node_or_null("BillboardSprite")
|
|
|
|
|
if bill == null:
|
|
|
|
|
var packed: PackedScene = load("res://scenes/prefabs/billboard_sprite.tscn")
|
|
|
|
|
if packed == null:
|
|
|
|
|
return
|
|
|
|
|
bill = packed.instantiate()
|
|
|
|
|
bill.name = "BillboardSprite"
|
|
|
|
|
add_child(bill)
|
|
|
|
|
if bill.has_method("set_target_height"):
|
|
|
|
|
bill.set_target_height(billboard_height)
|
|
|
|
|
if bill.has_method("set_texture"):
|
|
|
|
|
var tex: Texture2D = load(texture_path)
|
|
|
|
|
if tex:
|
|
|
|
|
bill.set_texture(tex)
|
2026-09-14 18:36:02 +02:00
|
|
|
|
|
|
|
|
func _on_body_entered(body: Node3D) -> void:
|
|
|
|
|
if not _ready_to_hurt:
|
|
|
|
|
return
|
|
|
|
|
if not body.is_in_group("player"):
|
|
|
|
|
return
|
|
|
|
|
_ready_to_hurt = false
|
|
|
|
|
GameState.take_damage(damage, death_cause_key)
|
|
|
|
|
await get_tree().create_timer(cooldown).timeout
|
|
|
|
|
_ready_to_hurt = true
|