(wip) advanced langtons ant
(wip) advanced langtons ant
This commit is contained in:
61
langtons-ant/tile_map_layer.gd
Normal file
61
langtons-ant/tile_map_layer.gd
Normal file
@@ -0,0 +1,61 @@
|
||||
extends TileMapLayer
|
||||
|
||||
var tiles: Dictionary = {}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user