79 lines
1.6 KiB
GDScript
79 lines
1.6 KiB
GDScript
@tool
|
|
extends Node2D
|
|
|
|
@export var animal_type : String:
|
|
set(value):
|
|
animal_type = value
|
|
if is_node_ready():
|
|
_update_sprite()
|
|
|
|
@export var flip_horizontal : bool = false:
|
|
set(value):
|
|
flip_horizontal = value
|
|
if is_node_ready():
|
|
_update_sprite()
|
|
|
|
@export var show_shavings : bool = false:
|
|
set(value):
|
|
show_shavings = value
|
|
if is_node_ready():
|
|
_update_shavings()
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
_update_sprite()
|
|
_update_shavings()
|
|
|
|
|
|
func _update_sprite() -> void:
|
|
|
|
# Hide all animal sprites first
|
|
%Fox.visible = false
|
|
%Porcupine.visible = false
|
|
%Wolf.visible = false
|
|
%Cat.visible = false
|
|
%Goose.visible = false
|
|
%Frog.visible = false
|
|
%Chick.visible = false
|
|
%Dog.visible = false
|
|
|
|
# Show the appropriate animal based on animal_type
|
|
var active_sprite: AnimatedSprite2D
|
|
match animal_type:
|
|
"Fox":
|
|
%Fox.visible = true
|
|
active_sprite = %Fox
|
|
"Porcupine":
|
|
%Porcupine.visible = true
|
|
active_sprite = %Porcupine
|
|
"Wolf":
|
|
%Wolf.visible = true
|
|
active_sprite = %Wolf
|
|
"Cat":
|
|
%Cat.visible = true
|
|
active_sprite = %Cat
|
|
"Goose":
|
|
%Goose.visible = true
|
|
active_sprite = %Goose
|
|
"Frog":
|
|
%Frog.visible = true
|
|
active_sprite = %Frog
|
|
"Chick":
|
|
%Chick.visible = true
|
|
active_sprite = %Chick
|
|
"Dog":
|
|
%Dog.visible = true
|
|
active_sprite = %Dog
|
|
|
|
# Apply horizontal flip if enabled
|
|
if active_sprite:
|
|
active_sprite.flip_h = flip_horizontal
|
|
|
|
|
|
func _update_shavings() -> void:
|
|
%Shavings.visible = show_shavings
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|