1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 08:04:23 +00:00
hella-farm/entities/gold.gd

37 lines
834 B
GDScript3
Raw Normal View History

2024-04-13 17:07:26 +00:00
extends Node2D
class_name Gold
2024-04-13 17:07:26 +00:00
@export var speed_up_factor := 8.0
@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:
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
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()