2023-03-31 17:01:28 +00:00
|
|
|
extends ColorRect
|
2023-02-06 12:47:18 +00:00
|
|
|
|
|
|
|
class_name Tile
|
|
|
|
|
|
|
|
enum States {
|
|
|
|
EMPTY,
|
|
|
|
SNAKE,
|
|
|
|
APPLE
|
|
|
|
}
|
|
|
|
|
|
|
|
@export var state : States
|
2023-02-15 17:11:37 +00:00
|
|
|
# 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
|
|
|
|
2023-03-05 17:54:40 +00:00
|
|
|
@export var x : int
|
|
|
|
@export var y : int
|
|
|
|
|
2023-03-31 17:01:28 +00:00
|
|
|
func _init(_x : int, _y : int, _tile_colors : TileColors):
|
2023-02-06 12:47:18 +00:00
|
|
|
state = States.EMPTY
|
2023-03-05 17:54:40 +00:00
|
|
|
self.x = _x
|
|
|
|
self.y = _y
|
2023-03-31 17:01:28 +00:00
|
|
|
self.size_flags_horizontal += Control.SIZE_EXPAND
|
|
|
|
self.size_flags_vertical += Control.SIZE_EXPAND
|
2023-03-05 17:54:40 +00:00
|
|
|
self.tile_color = _tile_colors
|
2023-02-06 12:47:18 +00:00
|
|
|
|
2023-02-15 17:11:37 +00:00
|
|
|
func update_color():
|
|
|
|
match state:
|
|
|
|
States.EMPTY:
|
2023-03-31 17:01:28 +00:00
|
|
|
self.color = tile_color.empty
|
2023-02-15 17:11:37 +00:00
|
|
|
States.SNAKE:
|
2023-03-31 17:01:28 +00:00
|
|
|
self.color = tile_color.snake_body if snake_pos > 1 else tile_color.snake_head
|
2023-02-15 17:11:37 +00:00
|
|
|
States.APPLE:
|
2023-03-31 17:01:28 +00:00
|
|
|
self.color = tile_color.apple
|
2023-03-05 17:54:40 +00:00
|
|
|
pass
|
2023-02-15 17:11:37 +00:00
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
update_color()
|
|
|
|
pass
|
2023-03-05 17:54:40 +00:00
|
|
|
|