2022-07-18 02:42:00 -04:00

46 lines
1.1 KiB
GDScript

extends Node2D
export var hp : int = 3 # Number of hits before dying
onready var fish = get_node("/root/Tank/Fish")
var moving = true
var dest_counter : int = 0
var next_dest = 60
var destination : Vector2
func _ready():
pass
func _process(delta: float) -> void:
$SwordPivot.rotation_degrees += 1
if dest_counter >= next_dest:
destination = _select_destination()
next_dest = rand_range(60,1200) # second number lower = move more frequently
dest_counter = 0
else:
dest_counter +=1
if moving:
$TweenSwim.interpolate_property(self, "position", get_global_position(), destination, .175, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) #number lower = faster
$TweenSwim.start()
func _select_destination() -> Vector2:
var dest = Vector2(rand_range(200, 1500), rand_range(200, 880))
return dest
func _on_SwordHitbox_area_entered(area: Area2D) -> void:
if area.is_in_group("Fish"):
fish.belly_up("Piranha")
func _on_Blindzone_area_entered(area: Area2D) -> void:
if area.is_in_group("Fish"):
moving = false
$TweenSwim.stop_all()
func _on_Blindzone_area_exited(area):
if area.is_in_group("Fish"):
moving = true