67 lines
1.3 KiB
GDScript
67 lines
1.3 KiB
GDScript
extends Area2D
|
|
|
|
var fish = CharacterBody2D
|
|
var sprite = Sprite2D
|
|
var explosion = CollisionObject2D
|
|
var size = 0.0
|
|
@export
|
|
var target = 0
|
|
@export
|
|
var ai = 0
|
|
@export
|
|
var speed = 1
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
fish = get_tree().get_first_node_in_group("Fish") #fish
|
|
sprite = $Explosion
|
|
explosion = $ExplosionCollision
|
|
|
|
match ai:
|
|
#set position
|
|
0:
|
|
position = Vector2(target, -595)
|
|
#fish position
|
|
1:
|
|
position = Vector2(fish.position.x,-595)
|
|
#predict position
|
|
2: pass
|
|
if position.x > 858:
|
|
position.x = 858
|
|
if position.x < -858:
|
|
position.x = -858
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(delta):
|
|
goFish()
|
|
|
|
|
|
func goFish():
|
|
position.y = position.y + speed
|
|
|
|
if position.y > 794:
|
|
position.y = 794
|
|
explode()
|
|
|
|
func explode():
|
|
if(size < 1):
|
|
explosion.scale = Vector2(size, size)
|
|
sprite.modulate.a= sprite.modulate.a - .02
|
|
sprite.scale = Vector2(size, size)
|
|
if size >1:
|
|
sprite.modulate.a= sprite.modulate.a - .1
|
|
size += .032
|
|
sprite.visible = true
|
|
if size < 1:
|
|
explosion.set_deferred("disabled", false)
|
|
else:
|
|
explosion.set_deferred("disabled", true)
|
|
if size > 2:
|
|
size = 2
|
|
queue_free()
|
|
|
|
func _on_body_entered(body):
|
|
if body.is_in_group("Fish"):
|
|
fish.hurt = true
|