55 lines
1.4 KiB
GDScript
55 lines
1.4 KiB
GDScript
class_name Trap extends Area3D
|
|
|
|
enum Type{
|
|
BOMB,
|
|
MINE,
|
|
GAS,
|
|
FORCE_PANEL,
|
|
SWITCH,
|
|
PITFALL
|
|
}
|
|
|
|
const trap_icons : Dictionary = {
|
|
Trap.Type.BOMB : preload("res://visuals/images/icons/t-bomb.png"),
|
|
Trap.Type.GAS : preload("res://visuals/images/icons/t-gas.png"),
|
|
Trap.Type.PITFALL : preload("res://visuals/images/icons/t-pitfall.png"),
|
|
Trap.Type.FORCE_PANEL : preload("res://visuals/images/icons/t-force_panel.png"),
|
|
Trap.Type.SWITCH : preload("res://visuals/images/icons/t-switch.png"),
|
|
Trap.Type.MINE : preload("res://visuals/images/icons/t-mine.png"),
|
|
}
|
|
|
|
@onready var model : MeshInstance3D = %Model
|
|
@onready var icon : Sprite3D = %Icon
|
|
@onready var material : StandardMaterial3D = model.get_surface_override_material(0)
|
|
@onready var reveal_timer : Timer = %RevealTimer
|
|
var type : Type
|
|
var square : Vector3i
|
|
var trap_owner : int
|
|
signal disarmed(type : Trap.Type)
|
|
|
|
|
|
func setup(type : Type, trap_owner : int) -> void:
|
|
self.type = type
|
|
self.trap_owner = trap_owner
|
|
|
|
func disarm() -> void:
|
|
disarmed.emit(type)
|
|
queue_free()
|
|
|
|
func reveal() -> void:
|
|
model.visible = true
|
|
reveal_timer.start(5)
|
|
|
|
func _on_reveal_timeout() -> void:
|
|
if Game.level.is_square_detected(square):
|
|
reveal_timer.start(5)
|
|
else:
|
|
model.visible = false
|
|
|
|
func _ready() -> void:
|
|
var owns_trap = trap_owner == Multiplayer.id
|
|
icon.texture = trap_icons[type]
|
|
model.visible = owns_trap
|
|
icon.visible = owns_trap
|
|
material.albedo_color = Color.YELLOW if owns_trap else Color.RED
|