extends Area2D

export (int) var SPEED = 100
onready var animationPlayer = $Animation
var moving = false
var goingLeft = false

func _process(delta):
	moving = false
	
	if Input.is_action_pressed("ui_right"):
		goingLeft = false
		move(SPEED, 0, delta)

	if Input.is_action_pressed("ui_left"):
		goingLeft = true
		move(-SPEED, 0, delta)

	if Input.is_action_pressed("ui_up"):
		move(0, -SPEED, delta)

	if Input.is_action_pressed("ui_down"):
		move(0, SPEED, delta)

	if moving:
		animationPlayer.play("Run")
	else:
		animationPlayer.play("Idle")

	$Sprite.flip_h = goingLeft
		
	# var areas = get_overlapping_areas()
	# for area in areas:
	# 	area.queue_free()

func move(xspeed, yspeed, delta):
	moving = true
	position.x += xspeed * delta
	position.y += yspeed * delta


func _on_Pig_area_entered(apple):
	apple.queue_free()
	scale *= 1.1
	SPEED *= 0.9
