28 lines
783 B
GDScript
28 lines
783 B
GDScript
extends "res://objects/enemy/enemy.gd"
|
|
|
|
const Explosion = preload("res://objects/enemy/explosion.tscn")
|
|
|
|
onready var chain = $Chain
|
|
onready var hitbox = $Hitbox
|
|
|
|
func _ready():
|
|
var ground_cast = $GroundCast
|
|
ground_cast.force_raycast_update()
|
|
if ground_cast.is_colliding():
|
|
chain.points[1].y = chain.to_local(ground_cast.get_collision_point()).y
|
|
|
|
func _process(delta):
|
|
chain.points[0].x = hitbox.position.x
|
|
|
|
func _on_Hitbox_area_entered(area):
|
|
if area.is_in_group("explosion"):
|
|
var timer = get_tree().create_timer(0.2, false)
|
|
timer.connect("timeout", self, "die")
|
|
if area.is_in_group("player"):
|
|
die()
|
|
|
|
func die():
|
|
var explosion = Explosion.instance()
|
|
explosion.global_position = hitbox.global_position
|
|
get_parent().call_deferred("add_child", explosion)
|
|
queue_free()
|