extends Area2D

var velocity: Vector2 = Vector2.ZERO
var source: Node = null

func _ready() -> void:
	body_entered.connect(_on_body_entered)

func _process(delta: float) -> void:
	global_position += velocity * delta
	var screen = get_viewport_rect().size
	if (global_position.x < 0 or global_position.x > screen.x or
			global_position.y < 0 or global_position.y > screen.y):
		queue_free()

func _on_body_entered(body: Node) -> void:
	if body == source:
		return
	if body.has_method("take_damage"):
		body.take_damage(GameConfig.bullet_damage)
	queue_free()
