2024-04-13 17:07:26 +00:00
|
|
|
extends Node2D
|
2024-04-14 02:07:35 +00:00
|
|
|
class_name Gold
|
2024-04-13 17:07:26 +00:00
|
|
|
|
|
|
|
|
2024-04-24 02:35:35 +00:00
|
|
|
@export var speed_up_factor := 8.0
|
|
|
|
|
|
|
|
|
2024-04-21 21:49:34 +00:00
|
|
|
@onready var game: MainGame = MainGame.get_via_group(self)
|
|
|
|
@onready var move_towards: MoveTowards = %"MoveTowards"
|
|
|
|
@onready var collect_sound_spawner: Spawner = %"CollectSoundSpawner"
|
|
|
|
@onready var collectible: Collectible = %"Collectible"
|
2024-04-14 02:39:45 +00:00
|
|
|
|
|
|
|
|
2024-04-21 21:20:02 +00:00
|
|
|
func magnetize(cursor: Cursor) -> void:
|
|
|
|
move_towards.target = cursor
|
2024-04-14 02:39:45 +00:00
|
|
|
|
2024-04-21 21:20:02 +00:00
|
|
|
func demagnetize() -> void:
|
|
|
|
move_towards.target = null
|
|
|
|
|
|
|
|
func collect() -> void:
|
2024-04-21 21:49:34 +00:00
|
|
|
collectible.apply()
|
2024-04-21 21:20:02 +00:00
|
|
|
collect_sound_spawner.spawn()
|
2024-04-14 02:39:45 +00:00
|
|
|
queue_free()
|
2024-04-21 21:20:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_move(movement: Vector2) -> void:
|
|
|
|
position += movement
|
2024-04-24 02:35:35 +00:00
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if move_towards.target != null:
|
|
|
|
move_towards.speed *= pow(speed_up_factor, delta)
|
2024-05-03 00:45:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_delete_if_not_on_screen_screen_exited() -> void:
|
|
|
|
if move_towards.target == null:
|
|
|
|
queue_free()
|