extends Node2D

## Distance-Based Collision Demo: Manual hit-testing with point distance

var circles: Array[Dictionary] = []
var hit_threshold: float = 30.0

func _ready():
	$Label.text = "Click near the circles to 'pop' them (distance < 30px)"
	
	# Create some random circles
	for i in range(5):
		var pos = Vector2(randf_range(50, 350), randf_range(150, 450))
		circles.append({
			"position": pos,
			"color": Color(randf(), randf(), randf()),
			"radius": 25
		})

func _input(event: InputEvent):
	if event is InputEventMouseButton and event.pressed:
		check_hits(event.position)

func check_hits(click_pos: Vector2):
	for i in range(circles.size() - 1, -1, -1):
		var circle = circles[i]
		var distance = click_pos.distance_to(circle["position"])
		if distance < hit_threshold:
			circles.pop_at(i)  # Remove the circle
			$PopLabel.text = "Popped! %d remaining" % circles.size()
	queue_redraw()

func _draw():
	for circle in circles:
		draw_circle(circle["position"], circle["radius"], circle["color"])
