extends Node2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var open = false
var animacion

# Called when the node enters the scene tree for the first time.
func _ready():
	$switch.connect("activate",self,"activate_door")
	animacion = $AnimatedSprite
	animacion.connect("animation_finished",self,"change_state")
	if open:
		animacion.frame = 2
		$static_door/Collision_static_door.disabled = true
		$switch.set_collision_layer_bit(2,false)


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass

func change_state():
	if open:
		$static_door/Collision_static_door.disabled = true
		$switch.set_collision_layer_bit(2,false)
	else:
		$static_door/Collision_static_door.disabled = false
		$switch.set_collision_layer_bit(2,true)
	animacion.stop()
	pass
		
func activate_door():
	print("animation_played")
	if not animacion.is_playing():
		
		open = not open
		if open:
			animacion.play("opening")
#			$static_door/Collision_static_door.disabled = true
		else:
			animacion.play("closing")
#			$static_door/Collision_static_door.disabled = false
