65 lines
1.8 KiB
GDScript
65 lines
1.8 KiB
GDScript
extends Node2D
|
|
|
|
var follower = false
|
|
var health = 100
|
|
static var NAMES = ["Forkman", "Cobold", "Ork"]
|
|
|
|
func _ready() -> void:
|
|
follower = true
|
|
if name.contains("Mine"):
|
|
get_node("CharacterBody2D/AnimatedSprite2D").connect("animation_finished", Callable(self, "Remove_Mine"))
|
|
set_process_input(true)
|
|
|
|
if name.contains("Wall"):
|
|
get_node("CharacterBody2D/ProgressBar").hide()
|
|
|
|
func _process(delta: float) -> void:
|
|
if follower:
|
|
position = get_viewport().get_mouse_position()
|
|
|
|
func get_if_moving_state():
|
|
return follower
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
if abs(position) <= get_viewport().get_mouse_position():
|
|
follower = false
|
|
|
|
func Explode_Mine() -> void:
|
|
get_node("CharacterBody2D/AnimatedSprite2D").scale = Vector2(1,1)
|
|
get_node("CharacterBody2D/AnimatedSprite2D").play("Explode")
|
|
|
|
func Remove_Mine() -> void:
|
|
queue_free()
|
|
|
|
|
|
func _on_area_2d_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
|
|
if follower == false:
|
|
get_node("CharacterBody2D/Timer").start()
|
|
for i in get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
|
|
for j in NAMES:
|
|
if i.get_parent().name.contains(j):
|
|
get_node("CharacterBody2D/ProgressBar").show()
|
|
i.get_parent().set_process(false)
|
|
|
|
|
|
func _on_timer_timeout() -> void:
|
|
var minus = 0
|
|
|
|
for i in get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
|
|
for j in NAMES:
|
|
if i.get_parent().name.contains(j):
|
|
minus += 1
|
|
|
|
health -= minus
|
|
get_node("CharacterBody2D/ProgressBar").value = health
|
|
if minus == 0:
|
|
get_node("CharacterBody2D/Timer").stop()
|
|
|
|
if health <= 0:
|
|
for i in get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
|
|
for j in NAMES:
|
|
if i.get_parent().name.contains(j):
|
|
i.get_parent().set_process(true)
|
|
queue_free()
|