ld-56/src/creature.gd

30 lines
748 B
GDScript3
Raw Normal View History

2024-10-07 05:05:27 +00:00
extends Node2D
var key
@onready var data = Data.data.creatures[key]
@onready var image = Data.data.images[key]
@onready var sprite_2d: Sprite2D = $Sprite2D
2024-10-07 18:53:09 +00:00
const COIN = preload("res://src/Coin.tscn")
var held = false
2024-10-07 05:05:27 +00:00
func _ready() -> void:
sprite_2d.texture = image
2024-10-07 18:53:09 +00:00
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)
2024-10-07 05:05:27 +00:00
func _on_mouse_handler_clicked() -> void:
2024-10-07 17:07:46 +00:00
Triggerer.trigger("grab_creature", {"creature": key, "old_window": get_window(), "old_position": position})
Persister.persist_data("grabbing", true)
queue_free()