feat: reorganized logic + camera
This commit is contained in:
@@ -1,75 +1,16 @@
|
||||
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,
|
||||
]
|
||||
@onready var numTiles: int = get_tile_set().get_source(0).get_tiles_count()
|
||||
#@onready var texSize: Vector2 = get_tile_set().get_tile_texture(get_tile_set().get_tile_id(0))
|
||||
@onready var texSize: Vector2 = Vector2(32, 32) # TODO: get from tileSet
|
||||
|
||||
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)
|
||||
return self.tiles.get_or_add(pos, 0)
|
||||
|
||||
# TODO: state sh1ould be an enum probably
|
||||
# TODO: state should 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
|
||||
self.tiles.erase(pos)
|
||||
self.tiles.get_or_add(pos, state % self.numTiles)
|
||||
|
||||
Reference in New Issue
Block a user