extends Area2D

var gap_size = 5

var speed = 24
var y = 0
var new_y = 0
var safe_zone = null

var pos_x
var limits
var dir_x

func _process(delta):
	new_y += speed * delta
	if ceil(y) != ceil(new_y):
		y = new_y
		position.y += 1
		
func on_area_entered(area):
	if area.position.x > safe_zone.x and area.position.x < safe_zone.y:
		pass
	else:
		area.destroy()

func _ready():
	var gap_pos = randi() % (16 - gap_size)
	$left/pol.scale.x = gap_pos
	var s = 15 - (gap_pos + gap_size)
	$right/pol.scale.x = s
#	if gap_pos > 0:
#		$left/pol.scale.x = gap_pos
#		$coll_left.scale.x = gap_pos
#	else:
#		$left/pol.free()
#		$coll_left.free()
#	var s = 15 - (gap_pos + gap_size)
#	if s > 0:
#		$right/pol.scale.x = s
#		$coll_right.scale.x = -s
#	else:
#		$right/pol.free()
#		$coll_right.free()
	safe_zone = Vector2(7 + gap_pos, 6 + gap_pos + gap_size)
	$vis.connect("screen_exited", self, "queue_free")
	self.connect("area_entered", self, "on_area_entered")
	$life_time.connect("timeout", self, "queue_free")
	$life_time.start()
