blob: 5a82c31360b0c46f24c82bb4c9d92627b218bb41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
class_name ComponentCollision
extends Node
signal collided
@export_node_path("CharacterBody2D") var entityPath: NodePath
@onready var entity: CharacterBody2D = get_node(entityPath)
@export_node_path("CollisionShape2D") var collision_shape_path: NodePath
@onready var collision_shape: CollisionShape2D = get_node(collision_shape_path)
@export_node_path("ComponentHealth") var component_health_path: NodePath
var component_health: ComponentHealth
var collision_area: Area2D
func init():
collision_area = Utilities.Collision.Area.new(entity, collision_shape)
collision_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, true)
collision_area.connect("collided", func(area): emit_signal("collided", area))
entity.add_child(collision_area)
if component_health_path:
component_health = get_node(component_health_path)
collision_area.connect("collided", func(area):
if area.is_in_group("explosions"):
component_health.take_damage()
)
component_health.died.connect(func():
collision_area.set_collision_layer_value(Utilities.Collision.Layer.ENEMY, false)
collision_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, false)
)
|