tool
extends Node2D


export var Color1 = Color(1, 1, 0, 1);
export var Color2 = Color(1, 0, 0, 1);
export var FollowYPosition = 1000.0;
export var width = 2000.0;
export var step = 50.0;
# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
	randomize()
	$RedrawTimer.connect("timeout", self, "update")
	var rect = RectangleShape2D.new();
	rect.extents = Vector2( width/2.0, step/2.0 );
	$KillArea/CollideShape.shape = rect;
	$KillArea.connect("body_entered", self, "entered");
	pass # Replace with function body.

func entered(obj):
	if (obj.has_method("kill")):
		obj.kill();

func build_vectorpool_array():
	var line = PoolVector2Array();
	var startx = width*-0.5;
	var endx = width*0.5;
	var jitter = 15;
	var i = startx;
	var y1 = step*-0.5;
	var y2 = step*0.5;
	
	while i <= endx:
		line.append(Vector2(i + rand_range(jitter*-1, jitter), y1 + rand_range(jitter*-1, jitter) ));
		i+=step;
	while i > startx:
		i-=step;
		line.append(Vector2(i + rand_range(jitter*-1, jitter), y2 + rand_range(jitter*-1, jitter)));
	line.append(line[0]);
	return line;

func _draw():
	draw_polyline(build_vectorpool_array(), Color1, 3);
	draw_polyline(build_vectorpool_array(), Color2, 3);
	
	

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