extends Node2D const PICKUP_RADIUS := 48.0 const ATTRACTION_RADIUS := 150.0 var mineral := "iron" var texture: Texture2D var points := PackedVector2Array() var uv := PackedVector2Array() var drift := Vector2.ZERO var spin := 0.0 var _age := 0.0 var _collected := false var _player: CharacterBody2D func _ready() -> void: add_to_group("loot") add_to_group("mineral_pickups") _player = get_tree().current_scene.get_node_or_null("PlayerShip") as CharacterBody2D z_index = 18 light_mask = 4 func _physics_process(delta: float) -> void: _age += delta position += drift * delta drift *= exp(-1.8 * delta) rotation += spin * delta spin *= exp(-0.7 * delta) queue_redraw() if _collected or _age < 0.8 or not is_instance_valid(_player) or bool(_player.get("_is_destroyed")): return var distance := global_position.distance_to(_player.global_position) if distance <= PICKUP_RADIUS: _collected = true GameState.captain.minerals[mineral] = int(GameState.captain.minerals.get(mineral, 0)) + 1 _player.call("recycle_asteroid_fragment") GameState.captain.emit_changed() var popup := preload("res://scenes/game/damage_popup.tscn").instantiate() as Label popup.text = "+1 %s" % {"iron": "żelaza", "aluminium": "aluminium", "titanium": "tytanu", "uranium": "uranu", "sulfur": "siarki"}.get(mineral, mineral) popup.set("text_color", Color("c9e8ff")) popup.position = _player.position + Vector2(-40, -50) get_tree().current_scene.add_child.call_deferred(popup) queue_free() elif distance <= ATTRACTION_RADIUS: global_position = global_position.move_toward(_player.global_position, 180.0 * delta) func _draw() -> void: if texture == null or points.size() < 3: return draw_polygon(points, PackedColorArray([Color.WHITE]), uv, texture)