extends Node2D

var opened = false
var fullyMoved = false

var moveSpeed = 25

var amountMoved = 0
var amountToMove = 250

var dootsLeft = 20
var readyToCount = false

func _ready():
	GameVariables.globalMessage.connect(global_message_recieved)

func _process(delta):
	if opened and !fullyMoved:
		var amountToMoved = moveSpeed*delta
		position.x += amountToMoved
		amountMoved += abs(amountToMoved)
		
		if amountMoved >= amountToMove:
			fullyMoved = true

func global_message_recieved(message:String):
	if readyToCount and message.substr(0,4) == "doot":
		dootsLeft -= 1
		if dootsLeft <= 0:
			open()

func open():
	opened = true

func _on_cave_wall_waiting_opened_signal():
	readyToCount = true
