Tough_Crowd/godot/scenes/faces/face.gd

37 lines
1.2 KiB
GDScript3
Raw Normal View History

2024-01-26 19:53:36 +00:00
extends Node2D
2024-01-27 11:02:06 +00:00
@export_enum("angry", "neutral", "happy", "laugh") var expression
2024-01-26 19:53:36 +00:00
2024-01-27 11:02:06 +00:00
var person_controller : AudienceMember
2024-01-27 11:40:54 +00:00
var expression_map = {}
2024-01-27 11:02:06 +00:00
const expression_change_speed : float = 1.5
2024-01-26 19:53:36 +00:00
const color_transparent : Color = Color(1, 1, 1, 0)
const color_visible : Color = Color(1, 1, 1, 1)
# Called when the node enters the scene tree for the first time.
func _ready():
2024-01-27 11:40:54 +00:00
expression_map = {
"angry" : $Unhappy,
"neutral" : $Neutral,
"happy" : $Happy,
"laugh" : $Laugh,
}
person_controller = get_node("../../../Person")
2024-01-27 11:02:06 +00:00
expression = person_controller.expression
reset_face()
2024-01-26 19:53:36 +00:00
func _process(_delta):
2024-01-27 11:02:06 +00:00
if expression != person_controller.expression:
update_face(person_controller.expression)
2024-01-27 11:40:54 +00:00
expression = person_controller.expression
2024-01-27 11:02:06 +00:00
func reset_face():
for expr in expression_map:
2024-01-27 11:40:54 +00:00
expression_map[expr].modulate = color_transparent.lerp(color_visible, expr == expression)
2024-01-27 11:02:06 +00:00
func update_face(new_expression: String):
var tween = get_tree().create_tween().bind_node(self).set_parallel().set_trans(Tween.TRANS_LINEAR)
tween.tween_property(expression_map[expression], "modulate", color_transparent, expression_change_speed)
tween.tween_property(expression_map[new_expression], "modulate", color_visible, expression_change_speed)