Randoloot/scripts/items/time_crystal_pickup.gd
2026-10-20 19:53:03 +02:00

37 lines
1.4 KiB
GDScript

extends Node2D
const PICKUP_RADIUS := 48.0
const ATTRACTION_RADIUS := 150.0
const POPUP := preload("res://scenes/game/damage_popup.tscn")
var amount := 0
var _player: CharacterBody2D
var _collected := false
func _ready() -> void:
add_to_group("time_crystal_pickups")
_player = get_parent().get_node_or_null("PlayerShip") as CharacterBody2D
z_index = 18
func _draw() -> void:
for radius in [27.0,22.0,18.0]: draw_circle(Vector2.ZERO,radius,Color(0.42,0.86,1.0,0.07))
var icon := load("res://assets/icons/resources/time_crystals.png") as Texture2D
if icon != null: draw_texture_rect(icon,Rect2(-18,-18,36,36),false)
func _physics_process(delta: float) -> void:
if _collected 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
var gained := maxi(0,amount)
GameState.captain.expedition.time_crystals += gained
GameState.captain.expedition.emit_changed()
GameState.captain.emit_changed()
var popup := POPUP.instantiate() as Label
popup.text = "+%d KRYSZTAŁÓW CZASU" % gained
popup.set("text_color",Color("9be7ff"))
popup.position = _player.position+Vector2(-80,-90)
get_parent().add_child(popup)
set_physics_process(false)
queue_free()
elif distance <= ATTRACTION_RADIUS:
global_position = global_position.move_toward(_player.global_position,180.0*delta)