Snake/Scripts/Tile.gd

41 lines
819 B
GDScript3
Raw Normal View History

extends ColorRect
2023-02-06 12:47:18 +00:00
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
@export var x : int
@export var y : int
func _init(_x : int, _y : int, _tile_colors : TileColors):
2023-02-06 12:47:18 +00:00
state = States.EMPTY
self.x = _x
self.y = _y
self.size_flags_horizontal += Control.SIZE_EXPAND
self.size_flags_vertical += Control.SIZE_EXPAND
self.tile_color = _tile_colors
2023-02-06 12:47:18 +00:00
func update_color():
match state:
States.EMPTY:
self.color = tile_color.empty
States.SNAKE:
self.color = tile_color.snake_body if snake_pos > 1 else tile_color.snake_head
States.APPLE:
self.color = tile_color.apple
pass
func _process(delta):
update_color()
pass