Snake/Scripts/Tile.gd
Snoweuph 3037c1fce0 - Switching from sprites to UI Elements
- Binding Main Menu and Game Scene Together
TODO: Settings, Score, Highscore, Controller Support, Color Pallet Rework
2023-03-31 19:01:28 +02:00

40 lines
819 B
GDScript

extends ColorRect
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
@export var x : int
@export var y : int
func _init(_x : int, _y : int, _tile_colors : TileColors):
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
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