diff options
Diffstat (limited to 'src/ui/hud/snake/scripts/snake_head.gd')
-rw-r--r-- | src/ui/hud/snake/scripts/snake_head.gd | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ui/hud/snake/scripts/snake_head.gd b/src/ui/hud/snake/scripts/snake_head.gd new file mode 100644 index 0000000..a414e23 --- /dev/null +++ b/src/ui/hud/snake/scripts/snake_head.gd @@ -0,0 +1,29 @@ +extends TextureRect + +enum { + IDLE, + EAT, + DEAD +} + +var frames = { + IDLE: preload("res://ui/hud/snake/sprites/head1.png"), + EAT: preload("res://ui/hud/snake/sprites/head2.png"), + DEAD: preload("res://ui/hud/snake/sprites/head3.png") +} + + +func _ready(): + texture = frames[IDLE] + Event.connect("food_eaten", self, "_on_food_eaten") + Event.connect("game_over", self, "_on_game_over") + + +func _on_food_eaten(properties: Dictionary) -> void: + texture = frames[EAT] + yield(get_tree().create_timer(0.25), "timeout") + texture = frames[IDLE] + + +func _on_game_over() -> void: + texture = frames[DEAD]
\ No newline at end of file |