77 lines
2.3 KiB
GDScript
77 lines
2.3 KiB
GDScript
extends Sprite2D
|
|
|
|
var pos: Vector2i = Vector2i(0,0)
|
|
var dir: TileSet.CellNeighbor = TileSet.CELL_NEIGHBOR_RIGHT_SIDE
|
|
@onready var tiles: TileMapLayer = get_node("../TileMapLayer")
|
|
|
|
var next_dir: Dictionary = {
|
|
0: TileSet.CELL_NEIGHBOR_RIGHT_SIDE,
|
|
1: TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
|
|
2: TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
|
|
3: TileSet.CELL_NEIGHBOR_LEFT_SIDE,
|
|
4: TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE,
|
|
5: TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE,
|
|
}
|
|
|
|
var cur_int: Dictionary = {
|
|
TileSet.CELL_NEIGHBOR_RIGHT_SIDE: 0,
|
|
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: 1,
|
|
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: 2,
|
|
TileSet.CELL_NEIGHBOR_LEFT_SIDE: 3,
|
|
TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE: 4,
|
|
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE: 5,
|
|
}
|
|
|
|
func _ready() -> void:
|
|
self.set_z_index(1)
|
|
self.set_frame(cur_int[dir])
|
|
tiles.set_tile(pos, (tiles.get_tile_colour(pos))) # TODO: should probably use another dictionary
|
|
move()
|
|
|
|
func update() -> void:
|
|
var tile: int = tiles.get_tile_colour(pos)
|
|
var newFrame: int = cur_int[dir]
|
|
|
|
# TODO: turn into dict{tileCol, (nextDir, paintCol)} customizable
|
|
match tile:
|
|
0:
|
|
newFrame = (newFrame + 5) % tiles.numTiles
|
|
1:
|
|
newFrame = (newFrame + 4) % tiles.numTiles
|
|
2:
|
|
newFrame = (newFrame + 0) % tiles.numTiles
|
|
3:
|
|
newFrame = (newFrame + 0) % tiles.numTiles
|
|
4:
|
|
newFrame = (newFrame + 5) % tiles.numTiles
|
|
5:
|
|
newFrame = (newFrame + 4) % tiles.numTiles
|
|
_:
|
|
pass
|
|
dir = next_dir[newFrame]
|
|
|
|
move()
|
|
pos = tiles.get_neighbor_cell(pos, dir)
|
|
tile = tiles.get_tile_colour(pos)
|
|
tiles.set_tile(pos, (tile + 1) % tiles.numTiles) # TODO: should probably use another dictionary
|
|
self.set_frame(newFrame)
|
|
|
|
func move() -> void:
|
|
var delta: Vector2
|
|
match dir:
|
|
TileSet.CELL_NEIGHBOR_RIGHT_SIDE:
|
|
delta = Vector2(tiles.texSize.x, 0)
|
|
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE:
|
|
delta = Vector2(tiles.texSize.x/2, tiles.texSize.y/4*3)
|
|
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE:
|
|
delta = Vector2(-tiles.texSize.x/2, tiles.texSize.y/4*3)
|
|
TileSet.CELL_NEIGHBOR_LEFT_SIDE:
|
|
delta = Vector2(-tiles.texSize.x, 0)
|
|
TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE:
|
|
delta = Vector2(-tiles.texSize.x/2, -tiles.texSize.y/4*3)
|
|
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE:
|
|
delta = Vector2(tiles.texSize.x/2, -tiles.texSize.y/4*3)
|
|
_:
|
|
delta = Vector2(0,0)
|
|
self.translate(delta)
|