1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 08:04:23 +00:00
hella-farm/entities/barn.gd
2024-05-01 06:26:30 +02:00

40 lines
No EOL
1.1 KiB
GDScript

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)
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
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:
Log.p(self, "%s" % entity)
entity.get_node("MovementBarn/BarnPriority").priority_alternative()
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()