summaryrefslogtreecommitdiff
path: root/src/ui/hud/snake/scripts/snake_head.gd
blob: a414e23e682bfb5b4c4e9c4f734cf08e7144eef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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]