extends Sprite


onready var tank    = get_node("/root/Tank")
onready var spawner = get_node("/root/Tank/HazardSpawner")
var playingforwards = true
onready var fish = get_node("/root/Tank/Fish")
onready var interception = get_node("/root/Tank/House/LeftEntrance").get_global_position()
onready var sticker = get_node("/root/Tank/FishFork")
var retracting = false


func _process(delta: float) -> void:
	if retracting:
		position.y -= 1
		if position.y < -100:
			var knife_scene = load("res://Hazards/Knife/Knife.tscn")
			var knife = knife_scene.instance()
			get_parent().add_child(knife)
			fish.invincible = false
			queue_free()

func _on_Timer_timeout() -> void:
	fish.do_not_rotate = true
	$TweenPrep.interpolate_property(fish, "position", fish.position.x, interception.x,  1, Tween.TRANS_BACK, Tween.EASE_IN, 0.5)
	$TweenPrep.interpolate_property(self, "position:x", position.x, interception.x+230, 0.5, Tween.TRANS_BACK, Tween.EASE_IN)
	$TweenPrep.start()
	yield($TweenPrep, "tween_completed")
#	$TweenStab.interpolate_property(self, "position:y", get_global_position().y, interception.y+530, 0.2, Tween.TRANS_CIRC, Tween.EASE_IN)
#	$TweenStab.start()
	$AnimationPlayer.play("Stab")
	yield($AnimationPlayer, "animation_finished")
	sticker.visible = true
	get_parent()._think()
	fish.dash_mutation = true


func _stab() -> void:
	$AnimationPlayer.play("Stab")
#	yield($AnimationPlayer, "animation_finished")
	sticker.visible = true
	print("Sticker's z_index = " + str(sticker.z_index))


func retract() -> void:
	$AnimationPlayer.play_backwards("Stab")
	yield($AnimationPlayer, "animation_finished")
	retracting = true
	

func destroy() -> void:
	queue_free()
