Tutorial 17 Enemy AI and Stats
This commit is contained in:
@ -1,22 +1,36 @@
|
||||
extends Area2D
|
||||
|
||||
export(bool) var show_hit = true
|
||||
|
||||
const HitEffect = preload("res://Effects/HitEffect.tscn")
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
var invincible = false setget set_invincible
|
||||
|
||||
onready var timer = $Timer
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
signal invincibility_started
|
||||
signal invincibility_ended
|
||||
|
||||
func set_invincible(value):
|
||||
invincible = value
|
||||
if invincible == true:
|
||||
emit_signal("invincibility_started")
|
||||
else:
|
||||
emit_signal("invincibility_ended")
|
||||
|
||||
func _on_Hurtbox_area_entered(area):
|
||||
if show_hit:
|
||||
var effect = HitEffect.instance()
|
||||
var main = get_tree().current_scene
|
||||
main.add_child(effect)
|
||||
effect.global_position = global_position
|
||||
func start_invincibility(duration):
|
||||
self.invincible = true
|
||||
timer.start(duration)
|
||||
|
||||
func create_hit_effect():
|
||||
var effect = HitEffect.instance()
|
||||
var main = get_tree().current_scene
|
||||
main.add_child(effect)
|
||||
effect.global_position = global_position
|
||||
|
||||
func _on_Timer_timeout():
|
||||
self.invincible = false
|
||||
|
||||
func _on_Hurtbox_invincibility_ended():
|
||||
monitorable = true
|
||||
|
||||
func _on_Hurtbox_invincibility_started():
|
||||
set_deferred("monitorable", false)
|
||||
|
@ -9,4 +9,8 @@ script = ExtResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_Hurtbox_area_entered"]
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
|
||||
[connection signal="invincibility_ended" from="." to="." method="_on_Hurtbox_invincibility_ended"]
|
||||
[connection signal="invincibility_started" from="." to="." method="_on_Hurtbox_invincibility_started"]
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
||||
|
Reference in New Issue
Block a user