]> purplebirdman git - frog-ninja.git/blob - asset/character/model/hitbox.gd
532f987d61cf87c43284d310b5f799268cba25fb
[frog-ninja.git] / asset / character / model / hitbox.gd
1 extends Area3D
2 class_name Hitbox
3
4
5 @export var debug_color_hit: Color = Color(Color.YELLOW, 0.5)
6 @export var debug_color_standby: Color = Color(Color.GREEN, 0.5)
7
8
9 @onready var model: CharacterModel = $"../.."
10 @onready var shape: CollisionShape3D = $CollisionShape3D
11 @onready var hit_effect: HitEffect = $HitEffect
12
13 var _last_hit: float = 0
14
15
16 func _ready() -> void:
17         shape.debug_color = debug_color_standby
18
19
20 func _process(delta: float) -> void:
21         for area in get_overlapping_areas():
22                 if area is Hurtbox:
23                         on_hit(area)
24                 
25         _last_hit += delta
26         if _last_hit > 1.0:
27                 # TODO: all these guys share the same collision shape
28                 shape.debug_color = debug_color_standby
29
30
31 func on_hit(area: Hurtbox):
32         if is_being_attacked_by(area):
33                 _last_hit = 0
34                 shape.debug_color = debug_color_hit
35                 hit_effect.trigger()
36                 
37                 
38                 area.ignore_list.append(self)
39                 var hit_pkt := area.get_hit_packet()
40                 model.current_state.react_to_hit(hit_pkt)
41                 hit_pkt.queue_free()
42
43
44 func is_being_attacked_by(area: Hurtbox):
45         return area.is_attacking and not area.ignore_list.has(self)