extends Node

#The time, in seconds, it should take for the character to grow down
export var GrowDownTime = 2.0
export var IsSmallTime = 5.0
export var GrowBigTime = 1.0

#How much smaller should the player become
export var GrowDownFactor = 5

#How much faster should the player become
export var FastFactor = 8

func DwarfRoutine(player, delta):
	var elapsed = delta
	var fast_speed = player.MAX_SPEED * FastFactor
	var slow_speed = player.MAX_SPEED 
	var fast_friction = player.FRICTION * (FastFactor / 2)
	var slow_friction = player.FRICTION
	var small_scale = player.transform.get_scale() / GrowDownFactor
	var big_scale = player.transform.get_scale()
	var sprite = player.get_node("Sprite")
	var coll = player.get_node("CollisionShape2D")
	
	while elapsed < GrowDownTime:
		player.MAX_SPEED = lerp(slow_speed, fast_speed, elapsed / GrowDownTime)
		player.FRICTION = lerp(slow_friction, fast_friction, elapsed / GrowDownTime)
		setScale(sprite, coll, lerp(big_scale, small_scale, elapsed / GrowDownTime))
		elapsed += yield()
		
	elapsed -= GrowDownTime;
	while elapsed < IsSmallTime:
		elapsed += yield()
	elapsed -= IsSmallTime;
		
	while elapsed < GrowBigTime:
		player.MAX_SPEED = lerp(fast_speed, slow_speed, elapsed / GrowBigTime)
		player.FRICTION = lerp(fast_friction, slow_friction, elapsed / GrowBigTime)
		setScale(sprite, coll, lerp(small_scale, big_scale, elapsed / GrowBigTime))
		elapsed += yield()

func setScale(sprite, coll, scale):
	sprite.scale = scale;
	coll.scale = scale;
	
func StartEffect(player):
	var rout = DwarfRoutine(player, 0)
	return rout
	
