extends Node2D
@export var speech_bubble: Sprite2D
const OUTLINE_MATERIAL = preload("res://scenes/outline_material.tres")
@export var scene_to_open : PackedScene
@export var timer = 2

var mouse_over = false
var is_positive = false
var encounter : Encounter

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	var positive_or_negative = randi_range(0,1)
	is_positive = !encounter.is_nazi
	if is_positive:
		speech_bubble.modulate = Color.GREEN
	else:
		speech_bubble.modulate = Color.RED

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	timer -= delta
	if timer <= 0:
		if is_positive:
			SignalBus.add_score.emit(10)
		else:
			SignalBus.add_score.emit(-10)	
		queue_free()

	position.y -= 200 * delta
		
	if mouse_over and Input.is_action_just_pressed("mouse_click"):
		if is_positive:
			SignalBus.add_score.emit(-100)
			encounter.reduce_bubbles()
		else:
			encounter.reduce_bubbles()

		queue_free()

	
func _on_area_2d_mouse_entered() -> void:
	#speech_bubble.material = OUTLINE_MATERIAL
	mouse_over = true

func _on_area_2d_mouse_exited() -> void:
	#speech_bubble.material = null
	mouse_over = false
