extends Control

var up_left
var down_right
var up_right
var down_left
var viewport_rect

func _ready() -> void:
	viewport_rect = get_viewport_rect()

	print(get_viewport_rect())
	
	up_left = viewport_rect.position
	down_right = viewport_rect.end
	up_right = Vector2(viewport_rect.end.x, viewport_rect.position.y)
	down_left = Vector2(viewport_rect.position.x, viewport_rect.end.y)
	print(up_left)
	print(up_right)
	print(down_left)
	print(down_right)
	print(get_spawn_position())
	pass # Replace with function body.

func get_spawn_position() -> Vector2:
	var side = randi() % 4
	var spawn_x
	var spawn_y
	if side == 0:
		# oben
		spawn_x = randf_range(up_left.x, up_right.x)
		spawn_y = up_left.y
	elif side == 1:
		# rechts
		spawn_x = up_right.x
		spawn_y = randf_range(up_right.y, down_right.y)
	elif side == 2:
		#unten
		spawn_x = randf_range(up_left.x, up_right.x)
		spawn_y = down_left.y
	elif side == 3:
		#links
		spawn_x = up_left.x
		spawn_y = randf_range(up_right.y, down_right.y)
	return Vector2(spawn_x, spawn_y)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	
	pass

func spawn_enemy() -> void:
	var enemy_scene = preload("res://scenes/slime.tscn")
	var enemy = enemy_scene.instantiate()
	enemy.global_position = get_spawn_position()
	add_child(enemy)
	pass


func _on_spawn_timer_timeout() -> void:
	spawn_enemy()
	pass # Replace with function body.
