feat: made antProgramming dynamic
This commit is contained in:
@@ -4,7 +4,7 @@ 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 = {
|
||||
var cur_dir: Dictionary = {
|
||||
0: TileSet.CELL_NEIGHBOR_RIGHT_SIDE,
|
||||
1: TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
|
||||
2: TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
|
||||
@@ -22,43 +22,41 @@ var cur_int: Dictionary = {
|
||||
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE: 5,
|
||||
}
|
||||
|
||||
var antProgram: Dictionary = {
|
||||
0: Vector2i(-2, 1),
|
||||
1: Vector2i(0, 2),
|
||||
2: Vector2i(0, 3),
|
||||
3: Vector2i(-1, 4),
|
||||
4: Vector2i(-2, 5),
|
||||
5: Vector2i(-1, 0),
|
||||
}
|
||||
|
||||
func getNextStep(tile: int) -> Vector2i:
|
||||
return antProgram.get(tile, Vector2i(0,0))
|
||||
|
||||
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()
|
||||
tiles.set_tile(pos, tiles.get_tile_colour(pos))
|
||||
move(dir)
|
||||
|
||||
# update loop:
|
||||
# move in dir
|
||||
# get tile col, change dir based on col
|
||||
# paint tile col
|
||||
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()
|
||||
move(dir)
|
||||
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 tile: int = tiles.get_tile_colour(pos)
|
||||
var res = getNextStep(tile)
|
||||
dir = cur_dir[(cur_int[dir] + tiles.numTiles + res.x) % tiles.numTiles]
|
||||
self.set_frame(dir)
|
||||
tiles.set_tile(pos, res.y % tiles.numTiles)
|
||||
|
||||
func move(to: TileSet.CellNeighbor) -> void:
|
||||
var delta: Vector2
|
||||
match dir:
|
||||
match to:
|
||||
TileSet.CELL_NEIGHBOR_RIGHT_SIDE:
|
||||
delta = Vector2(tiles.texSize.x, 0)
|
||||
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE:
|
||||
|
||||
Reference in New Issue
Block a user