Snake/Scripts/Tile.gd

32 lines
581 B
GDScript3
Raw Normal View History

2023-02-06 12:47:18 +00:00
extends Sprite2D
class_name Tile
enum States {
EMPTY,
SNAKE,
APPLE
}
@export var state : States
# 0 means no snake at all, 1 means head and the biger, the further it is from the head
@export var snake_pos := 0
@export var tile_color : TileColors
2023-02-06 12:47:18 +00:00
func _init():
state = States.EMPTY
func update_color():
match state:
States.EMPTY:
self.modulate = tile_color.empty
States.SNAKE:
self.modulate = tile_color.snake_body if snake_pos > 1 else tile_color.snake_head
States.APPLE:
self.modulate = tile_color.apple
pass
func _process(delta):
update_color()
pass