extends Node2D


var step = 150


func _ready():
	$character/animation.play("normal")
	pass

# warning-ignore:unused_argument
func _process(delta):
	character_move()

	if position.x > 1785:
		position.x = 135
	if position.x < 135:
		position.x = 1785

	if position.y < 220:
		position.y = 970
	if position.y > 970:
		position.y = 220
	
	if Input.is_action_just_pressed("ui_select"):
		if Global.color == "red":
			Global.color = "blue"
		elif Global.color == "blue":
			Global.color = "yellow"
		elif Global.color == "yellow":
			Global.color = "red"
	
	if Global.color == "red":
			$color.play("red")
	elif Global.color == "blue":
			$color.play("blue")
	elif Global.color == "yellow":
			$color.play("yellow")
	
	if Global.death == true:
		$character/death.play("death")
		Global.death = false
	
	if Global.game_over == true:
		queue_free()
	pass


func character_move():
	if Input.is_action_just_pressed("ui_up"):
		position -= Vector2(0, step)
	elif Input.is_action_just_pressed("ui_down"):
		position += Vector2(0, step)
	elif Input.is_action_just_pressed("ui_left"):
		position -= Vector2(step, 0)
		$flip.play("left")
	elif Input.is_action_just_pressed("ui_right"):
		position += Vector2(step, 0)
		$flip.play("right")
	elif Input.is_action_just_pressed("ui_end"):
		get_tree().quit()
	pass
