extends KinematicBody2D

var input_vector = Vector2.ZERO

export var MAX_SPEED = 300
var movement = Vector2.ZERO

onready var sprite = $sprite
var movable = false

func _ready():
	print("ping")

func _on_player_entered(body):
	if (body.name == "Player"):
		movable = true

func _on_player_exited(body):
	if (body.name == "Player"):
		#yield(get_tree().create_timer(.1), "timeout")
		sprite.modulate = Color(1,1,1)
		movable = false
		
func _physics_process(_delta):
	if (Input.get_action_strength("Action")>0 and movable):
		sprite.modulate = Color(.3,.7,.1)
		input_vector.x = Input.get_action_strength("Right") - Input.get_action_strength("Left")
		input_vector.y = Input.get_action_strength("Down") - Input.get_action_strength("Up")
		input_vector = input_vector.normalized()
		movement.x = input_vector.x * MAX_SPEED #* delta
		movement.y = input_vector.y * MAX_SPEED #* delta
		movement = move_and_slide(movement)
	print(movable)

	if (Input.get_action_strength("Action")==0 and movable):
		sprite.modulate = Color(.6,1,.7)
