The_Dark_Side_of_Earth/enemies/boss/blob.gd

36 lines
887 B
GDScript3
Raw Normal View History

2025-09-18 20:09:53 +02:00
extends Node2D
var moving = false
@onready var player = get_tree().get_root().get_node("main/Player")
var speed = 500
2025-10-11 19:37:25 +02:00
# The target is set on initialization and never updated.
@onready var target = player.position
2025-09-18 20:09:53 +02:00
var reached = false
signal target_reached
func _ready() -> void:
2025-10-11 19:37:25 +02:00
# Wait one second before firing
2025-09-18 20:09:53 +02:00
await get_tree().create_timer(1).timeout
moving = true
2025-09-23 12:36:15 +02:00
func _process(delta: float) -> void:
2025-10-11 19:37:25 +02:00
# Fire towards the center of the cross
2025-09-18 20:09:53 +02:00
if moving:
position += (target - global_position).normalized().rotated(-get_parent().rotation) * speed * delta
2025-10-11 19:37:25 +02:00
# When reaching the center, inform parent node
2025-09-18 20:09:53 +02:00
if((global_position - target).length() < 40):
moving = false
if not reached:
target_reached.emit()
reached = true
2025-10-11 19:37:25 +02:00
# Damage the player on contact
2025-09-18 20:09:53 +02:00
if has_node("Area2D") and $Area2D.overlaps_body(player):
player.hurt(1, global_position-player.position)