46 lines
1.3 KiB
GDScript

extends Node2D
var hp = 5
var immune = false
var immune_timer = 0
onready var fish = get_node("/root/Tank/Fish")
func _ready():
# $Piranha.set_process(false)
$Wire/AnimatedSprite.frame = 0
func _on_Hitbox_area_entered(area):
if area.is_in_group("Fish") and $InvulnTimer.time_left == 0:
$AnimationPlayer.play("recoil")
hp -= 1
if hp == 4:
$Wire/AnimatedSprite.frame = 0
_spawn_piranha()
elif hp > 0 and hp < 3:
$Wire/AnimatedSprite.frame = 1
elif hp < 1 and get_parent().phase == get_parent().Phase.HEATER:
$Wire/AnimatedSprite.frame = 2
get_parent().blackout()
func _spawn_piranha():
print("Spawning the piranha now...")
#$AnimationPlayer.play("drop")
#yield($AnimationPlayer, "animation_finished")
var piranha_scene = load("res://Hazards/Piranha/Piranha.tscn")
var piranha = piranha_scene.instance()
# piranha.set_process(false)
#call_deferred("add_child", piranha)
add_child(piranha)
piranha.position = $Position2D.position
#piranha.global_position.x = position.x - 300
#piranha.global_position.y = position.y + 300
#$TweenDrop.interpolate_property(piranha, "position:y", piranha.get_global_position().y, piranha.get_global_position().y+500, 1, Tween.TRANS_CIRC, Tween.EASE_IN)
#$TweenDrop.start()
#yield($TweenDrop, "tween_completed")
print("Piranha is now at " + str(piranha.get_global_position()))
# piranha.set_process(true)