fishtank/src/NPCs/smallooze.gd
2024-07-07 20:54:47 +02:00

56 lines
1.3 KiB
GDScript

extends KinematicBody2D
onready var immunity = 50
onready var tilesmap = $"/root/World/tilemap"
onready var rootnode = get_node("/root/World")
const MOVEMENT_VECTORS = [
Vector2.UP,
Vector2.RIGHT,
Vector2.DOWN,
Vector2.LEFT
]
var directioncount = 0
var direction = Vector2.ZERO
func _physics_process(_delta):
if position != null:
if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0:
queue_free()
if immunity > 0:
immunity = immunity - 1
if directioncount == 0:
direction = MOVEMENT_VECTORS[randi() % 4]
directioncount = (directioncount + 1) % 5
move_and_collide(direction * 2)
func _on_Hurtbox_area_entered(_area):
if immunity == 0:
$Hurtbox/death.play()
func _on_death_finished():
queue_free()
func _on_Hitbox_area_entered(_area):
yield(get_tree().create_timer(2.0),"timeout")
var ooze = load("res://NPCs/ooze.tscn")
var instance = ooze.instance()
instance.position = position
rootnode.add_child(instance)
queue_free()
func _on_Romance_area_entered(area):
if immunity == 0:
# Ooze with smaller ID creates bigger ooze
if get_instance_id() < area.get_parent().get_instance_id() :
yield(get_tree().create_timer(2.0),"timeout")
var ooze = load("res://NPCs/ooze.tscn")
var instance = ooze.instance()
instance.position = position
rootnode.add_child(instance)
queue_free()