1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00
hella-farm/entities/barn.gd

42 lines
1.2 KiB
GDScript3
Raw Normal View History

extends StaticBody2D
class_name Barn
signal coin_inserted
@onready var sheep_spawner: Spawner = %"SheepSpawner"
@onready var blocked_tracker: Tracker = %"BlockedTracker"
@onready var animator: AnimationPlayer = %"Animator"
@onready var game := MainGame.get_via_group(self)
@onready var viewport := get_viewport()
func _on_roof_input(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
var gold_counter = game.inventory.get_counter(&"Gold")
if gold_counter.value < 5:
return
if blocked_tracker.tracking:
return
if not event is InputEventMouseButton:
return
if not event.pressed:
return
2024-05-01 04:26:30 +00:00
if animator.is_playing():
return
gold_counter.decrease(5)
animator.play(&"coin")
func _on_animation_finished(anim_name:StringName) -> void:
if anim_name == &"coin":
coin_inserted.emit()
func _on_sheep_spawned(entity: Node2D) -> void:
entity.get_node("MovementBarn/BarnPriority").priority_alternative()
2024-05-02 03:42:45 +00:00
entity.get_node("MovementBarn").speed *= animator.speed_scale
2024-05-01 04:26:30 +00:00
animator.speed_scale += 0.04
if Random.rng.randi_range(0, 20) == 0:
entity.get_node("Sprite/TopHatter").plus_one()
if Random.rng.randi_range(0, 20) == 0:
entity.get_node("Sprite/Monocler").plus_one()