29 lines
748 B
GDScript
29 lines
748 B
GDScript
extends Node2D
|
|
|
|
var key
|
|
|
|
@onready var data = Data.data.creatures[key]
|
|
@onready var image = Data.data.images[key]
|
|
|
|
@onready var sprite_2d: Sprite2D = $Sprite2D
|
|
|
|
const COIN = preload("res://src/Coin.tscn")
|
|
|
|
var held = false
|
|
|
|
func _ready() -> void:
|
|
sprite_2d.texture = image
|
|
Triggerer.listen("hour", _on_hour)
|
|
|
|
|
|
func _on_hour(_data):
|
|
if not held and randf() < (Persister.get_value("creature_resource_spawn_rate") / 100.0):
|
|
var new_coin = COIN.instantiate()
|
|
new_coin.global_position = global_position
|
|
get_window().add_child(new_coin)
|
|
|
|
|
|
func _on_mouse_handler_clicked() -> void:
|
|
Triggerer.trigger("grab_creature", {"creature": key, "old_window": get_window(), "old_position": position})
|
|
Persister.persist_data("grabbing", true)
|
|
queue_free()
|