notSpore/langtons-ant/tile_map_layer.gd

76 lines
1.8 KiB
GDScript

extends TileMapLayer
var tiles: Dictionary = {}
var idx: int = 0
var dirs: Array[int] = [
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE,
TileSet.CELL_NEIGHBOR_RIGHT_SIDE,
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
TileSet.CELL_NEIGHBOR_LEFT_SIDE,
TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE,
]
func render_next() -> void:
print("rendering {i}")
set_cell(get_neighbor_cell(Vector2i(0, 0), dirs[idx]), 0, Vector2i(0, 1))
idx = (idx + 1) % 6
func get_tile_colour(pos: Vector2i) -> int:
return tiles.get_or_add(pos, 0)
# TODO: state sh1ould be an enum probably
func set_tile(pos: Vector2i, state: int) -> void:
print("setting cell (%s) at %d %d\n" % [state, pos.x, pos.y])
set_cell(pos, 0, Vector2i(0, state))
tiles.erase(pos)
tiles.get_or_add(pos, state)
#var direction = 0
#var antPos = Vector2i(0,0)
#var grid = {}
#var tileSize = 16
#
## Called when the node enters the scene tree for the first time.
#func _ready() -> void:
#set_process(true)
#grid[antPos] = 0
#updateTile(antPos, 0)
#
#func updateTile(pos: Vector2i, col: int):
#var tileCol = Color.WHITE if col == 0 else Color.BLACK
#var tileRect = ColorRect.new()
#tileRect.color = tileCol
#tileRect.size = Vector2(tileSize, tileSize)
#tileRect.position = Vector2(pos.x * tileSize, pos.y * tileSize)
#add_child(tileRect)
#
#
## Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
#moveAnt()
#
#func moveAnt():
#var curCol = grid.get(antPos, 0)
#
#if curCol == 0:
#direction = (direction + 1) % 4
#else:
#direction = (direction + 3) % 4
#
#grid[antPos] = 1 - curCol
#updateTile(antPos, grid[antPos])
#
#match direction:
#0:
#antPos.y -= 1
#1:
#antPos.x += 1
#2:
#antPos.y += 1
#3:
#antPos.x -= 1
#
#if not grid.has(antPos):
#grid[antPos] = 0