bm-frontend-defence/Source/Main.gd
2022-01-28 00:35:46 +01:00

50 lines
1.1 KiB
GDScript

extends Node2D
var attackerScene = preload("res://attacker.tscn")
var speed = 3.5;
var base_scale = 0.346
# Called when the node enters the scene tree for the first time.
func _ready():
get_node("julian").position = get_viewport().size/2
get_node("julian").scale = Vector2.ONE * (base_scale * 16)
pass # Replace with function body.
func _timeout():
var child = attackerScene.instance()
var width = get_viewport().size.x
var height = get_viewport().size.y
var rot = rand_range(0, PI*2)
var center = Vector2(width, height)/2
var vec = Vector2(-max(width+70, height+70), 0)
vec = vec.rotated(rot) + center
vec = vec
child.rotation = rot
child.position = vec
child.target = center
child.speed = (min(width, height) / speed) * rand_range(0.8, 1.2)
add_child(child)
speed *= 0.985
var isleep = 0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
isleep += delta
if isleep > 12:
get_node("julian").rotation += delta*2/speed
if isleep < 1.5:
get_node("julian").scale = Vector2.ONE * (base_scale * 1+(15 * ((1.5 - isleep)/1.5)))