extends Area2D

var enemy_preload = preload("res://Enemy.tscn")

export var health : float = 100

var spawnchance = 0

var spawn_time = 0

func _physics_process(delta):
	var score = $"../../Score".score
	
	spawnchance += sqrt(score)*delta*1.5
	
	spawn_time += delta
	
	if spawn_time >= 1:
		spawn_time -= 1
		
		var random_pick = rand_range(50, 32000)
		
		#print("    ogre: " + str(spawnchance))
		#print(" soldier: " + str(spawnchance*3))
		#print("   ghost: " + str(spawnchance*9))
		#print("skeleton: " + str(spawnchance*27))
		#print("random_pick : " + str(random_pick) + "\n")
		
		if random_pick < spawnchance:
			spawnchance = 0
			
			var new_enemy = enemy_preload.instance()
			new_enemy.enemy_type = "ogre"
			$"..".add_child(new_enemy)
			
			spawn_time -= 10
		
		elif random_pick < spawnchance*3:
			spawnchance = 0
			
			var new_enemy = enemy_preload.instance()
			new_enemy.enemy_type = "soldier"
			$"..".add_child(new_enemy)
			
			spawn_time -= 5
		
		elif random_pick < spawnchance*9:
			spawnchance = 0
			
			var new_enemy = enemy_preload.instance()
			new_enemy.enemy_type = "ghost"
			$"..".add_child(new_enemy)
			
			spawn_time -= 2
			
		
		elif random_pick < spawnchance*27:
			spawnchance = 0
			
			var new_enemy = enemy_preload.instance()
			new_enemy.enemy_type = "skeleton"
			$"..".add_child(new_enemy)
			
			spawn_time -= 2
