extends Node2D var key @onready var data = Data.data.creatures[key] @onready var image = Data.data.images[key] @onready var sprite_2d: Sprite2D = $Sprite2D @onready var audio_stream_player: AudioStreamPlayer = $AudioStreamPlayer @onready var audio_stream_player_2: AudioStreamPlayer = $AudioStreamPlayer2 const COIN = preload("res://src/Coin.tscn") var held = false var target var start_pos var lifetime_timer = randi_range(10, 15) var end_pos var tween var tiled = false var tiles = [] func _ready() -> void: sprite_2d.texture = image Triggerer.listen("hour", _on_hour) func _process(delta: float) -> void: if target: position = position.lerp(target, delta * 2) if get_window().name == "CreatureWindow": if Persister.get_value("paused"): return lifetime_timer -= delta if lifetime_timer <= 0 and not end_pos: end_pos = true match randi_range(0, 3): 0: target = Vector2(-25, randi_range(-25, 100)) 1: target = Vector2(100, randi_range(-25, 100)) 2: target = Vector2(randi_range(-25, 100), -25) 3: target = Vector2(randi_range(-25, 100), 100) if lifetime_timer <= -2: queue_free() 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) #audio_stream_player.play() Triggerer.trigger("coin_sound") func _on_mouse_handler_clicked() -> void: Triggerer.trigger("grab_creature", {"creature": key, "old_window": get_window(), "old_position": position, "tiled": tiled, "tiles": tiles}) Persister.persist_data("grabbing", true) queue_free() func _on_mouse_handler_hovered() -> void: if held: return if tween: tween.kill() tween = create_tween() tween.tween_property(sprite_2d, "position:y", -1, 0.075) tween.tween_property(sprite_2d, "position:y", 0, 0.075) #audio_stream_player_2.play() Triggerer.trigger("creature_sound")