Hit Flash
This commit is contained in:
parent
ad2e1bc692
commit
65ba4684ea
3 changed files with 12 additions and 5 deletions
|
|
@ -41,8 +41,9 @@ collision_layer = 0
|
||||||
collision_mask = 4
|
collision_mask = 4
|
||||||
script = ExtResource("1_6attn")
|
script = ExtResource("1_6attn")
|
||||||
|
|
||||||
[node name="EnemyHurtbox" parent="." instance=ExtResource("2_34o1m")]
|
[node name="EnemyHurtbox" parent="." node_paths=PackedStringArray("canvasItem") instance=ExtResource("2_34o1m")]
|
||||||
max_hp = 50
|
max_hp = 50
|
||||||
|
canvasItem = NodePath("..")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyHurtbox"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyHurtbox"]
|
||||||
scale = Vector2(6, 6)
|
scale = Vector2(6, 6)
|
||||||
|
|
@ -50,7 +51,7 @@ shape = SubResource("CircleShape2D_6attn")
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
sprite_frames = SubResource("SpriteFrames_je28r")
|
sprite_frames = SubResource("SpriteFrames_je28r")
|
||||||
frame_progress = 0.0063938
|
frame_progress = 0.235914
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
scale = Vector2(5, 5)
|
scale = Vector2(5, 5)
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@ texture = ExtResource("2_sa5vt")
|
||||||
scale = Vector2(2, 1)
|
scale = Vector2(2, 1)
|
||||||
shape = SubResource("RectangleShape2D_fgt1l")
|
shape = SubResource("RectangleShape2D_fgt1l")
|
||||||
|
|
||||||
[node name="EnemyHurtbox" parent="." instance=ExtResource("3_sa5vt")]
|
[node name="EnemyHurtbox" parent="." node_paths=PackedStringArray("canvasItem") instance=ExtResource("3_sa5vt")]
|
||||||
hit_invulnerability = 0.0
|
canvasItem = NodePath("..")
|
||||||
|
flashColor = Color(2.00392, 2.00392, 2.00392, 1)
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyHurtbox"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyHurtbox"]
|
||||||
scale = Vector2(2, 1)
|
scale = Vector2(2, 1)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ extends Area2D
|
||||||
|
|
||||||
@export var max_hp : int
|
@export var max_hp : int
|
||||||
@onready var hp = max_hp
|
@onready var hp = max_hp
|
||||||
@export var hit_invulnerability = 0.35
|
@export var hit_invulnerability = 0.2
|
||||||
|
@export var canvasItem : CanvasItem
|
||||||
|
@export var flashColor : Color = Color(1.5, 1.5, 1.5)
|
||||||
var inv_time = 0;
|
var inv_time = 0;
|
||||||
|
|
||||||
signal damage_taken
|
signal damage_taken
|
||||||
|
|
@ -10,9 +12,12 @@ signal died
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
inv_time = max(inv_time-delta, 0)
|
inv_time = max(inv_time-delta, 0)
|
||||||
|
if(inv_time <= 0 and canvasItem != null):
|
||||||
|
canvasItem.modulate = Color(1,1,1)
|
||||||
|
|
||||||
func hurt(damage : int, dir : Vector2 = Vector2.ZERO):
|
func hurt(damage : int, dir : Vector2 = Vector2.ZERO):
|
||||||
if(inv_time<=0):
|
if(inv_time<=0):
|
||||||
|
if canvasItem != null: canvasItem.modulate = flashColor
|
||||||
inv_time = hit_invulnerability
|
inv_time = hit_invulnerability
|
||||||
hp = max(hp-damage, 0)
|
hp = max(hp-damage, 0)
|
||||||
damage_taken.emit(damage, dir)
|
damage_taken.emit(damage, dir)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue