Trap explosions with damage and health bar depletion.
This commit is contained in:
@@ -9,6 +9,14 @@ enum Type{
|
||||
PITFALL
|
||||
}
|
||||
|
||||
const range_shapes : Dictionary = {
|
||||
Trap.Type.BOMB : Vector3(5,1,5),
|
||||
Trap.Type.GAS : Vector3(1,1,1),
|
||||
Trap.Type.PITFALL : Vector3(1,1,1),
|
||||
Trap.Type.FORCE_PANEL : Vector3(1,1,1),
|
||||
Trap.Type.SWITCH : Vector3(3,1,3),
|
||||
Trap.Type.MINE : Vector3(5,1,5),
|
||||
}
|
||||
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"),
|
||||
@@ -18,6 +26,10 @@ const trap_icons : Dictionary = {
|
||||
Trap.Type.MINE : preload("res://visuals/images/icons/t-mine.png"),
|
||||
}
|
||||
|
||||
const explosion_template = preload("res://templates/explosion.tscn")
|
||||
|
||||
@onready var range_area : Area3D = %RangeArea
|
||||
@onready var range_shape : BoxShape3D = %RangeShape.shape
|
||||
@onready var model : MeshInstance3D = %Model
|
||||
@onready var icon : Sprite3D = %Icon
|
||||
@onready var material : StandardMaterial3D = model.get_surface_override_material(0)
|
||||
@@ -25,6 +37,12 @@ const trap_icons : Dictionary = {
|
||||
var type : Type
|
||||
var square : Vector3i
|
||||
var trap_owner : int
|
||||
|
||||
var disarming : bool
|
||||
var disarm_id : int
|
||||
|
||||
var damage : int = 10
|
||||
|
||||
signal disarmed(type : Trap.Type)
|
||||
|
||||
|
||||
@@ -51,4 +69,17 @@ func _ready() -> void:
|
||||
icon.texture = trap_icons[type]
|
||||
model.visible = owns_trap
|
||||
icon.visible = owns_trap
|
||||
range_shape.size = range_shapes[type]
|
||||
material.albedo_color = Color.YELLOW if owns_trap else Color.RED
|
||||
|
||||
func activate() -> void:
|
||||
var exp = explosion_template.instantiate()
|
||||
Game.level.add_vfx(exp, square)
|
||||
for body in range_area.get_overlapping_bodies():
|
||||
body.hurt(damage)
|
||||
#match(type):
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if !disarming or body.id != disarm_id:
|
||||
if !body.detecting:
|
||||
activate()
|
||||
|
||||
Reference in New Issue
Block a user