class_name CameraGuide
extends KinematicBody2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var game_size := Vector2(320,180)
onready var window_scale :float = (OS.window_size / game_size).x

var _is_tracking :bool = true

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func enable_tracking() -> void:
	##TODO: add extra collission checks here to make sure we aren't stuck maybe?
	_is_tracking = true

func disable_tracking() -> void:
	_is_tracking = false

var flip_tracker = 0.0
var stuck_check: bool
func _physics_process(delta):
	var pos = global_position
	#pos = pos.move_toward(PlayerInfo.player_position, delta)
	#pos = lerp(pos, PlayerInfo.player_position, delta )
	var dir_to = Vector2(0,0)

	# Calculate how far the player is from object
	var diff_to = (PlayerInfo.player_position - pos)
	var dist_to = (PlayerInfo.player_position - pos).length()
	
	# Determine the chase direction of player is past the threshold
	# Try to prevent bounce
	if (is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.x) > 10:
		dir_to = pos.direction_to(PlayerInfo.player_position)
	elif !(is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.y) > 10:
		dir_to = pos.direction_to(PlayerInfo.player_position)

	
#	UiManager.debug_text = ( UiManager.debug_text + 
#		# str(PlayerInfo.player_position.snapped(Vector2(0.01,0.01))) + 
#		"\n" + str(is_on_ceiling()) + str(is_on_floor()) + str(is_on_wall()) +
#		"\nPP: {0}, {1}".format({"0":"%7.2f" % PlayerInfo.player_position.x, "1":"%7.2f" % PlayerInfo.player_position.y}) +  
#		#"\nKB: " + str(global_position.snapped(Vector2(0.01,0.01))) + 
#		"\nKB: {0}, {1}".format({"0":"%7.2f" % global_position.x, "1":"%7.2f" % global_position.y}) +  
#		"\nDir to: {0}, {1}".format({"0":"%7.2f" % dir_to.x, "1":"%7.2f" % dir_to.y}) +  
#		"\nPoint to: {0}, {1}".format({"0":"%7.2f" % diff_to.x, "1":"%7.2f" % diff_to.y})  
#		#"\nDT: %7.2f" % dist_to 
#	) 

# "Hi, {0} v{version}".format({0:"Godette", "version":"%0.2f" % 3.114})
#"Hi, {0} v{1}".format(["Godette", "3.0"], "{_}")

	move_and_slide(dir_to * 180.0 )
	
#	flip_tracker += delta
#	if flip_tracker < 10:
#		move_and_slide(Vector2(60.2,0))
#	elif flip_tracker < 20:
#		move_and_slide(Vector2(-60.2,0))
#	else:
#		flip_tracker = 0.0
