feat: made antProgramming dynamic
This commit is contained in:
parent
fa6e5d9582
commit
408ed71722
|
|
@ -1,5 +1,4 @@
|
||||||
UI -> toggleButton so camera follows ant
|
UI -> toggleButton so camera follows ant
|
||||||
-> reset camera button
|
-> reset camera button
|
||||||
-> pause button
|
-> pause button
|
||||||
customizable tile->dir->color logic (im thinking we do a dict: {tileState, (newDir, newTileCol)})
|
|
||||||
dynamically generate tile colours (using a big palette for indexing maybe?) this probably needs to be a shader.
|
dynamically generate tile colours (using a big palette for indexing maybe?) this probably needs to be a shader.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ var pos: Vector2i = Vector2i(0,0)
|
||||||
var dir: TileSet.CellNeighbor = TileSet.CELL_NEIGHBOR_RIGHT_SIDE
|
var dir: TileSet.CellNeighbor = TileSet.CELL_NEIGHBOR_RIGHT_SIDE
|
||||||
@onready var tiles: TileMapLayer = get_node("../TileMapLayer")
|
@onready var tiles: TileMapLayer = get_node("../TileMapLayer")
|
||||||
|
|
||||||
var next_dir: Dictionary = {
|
var cur_dir: Dictionary = {
|
||||||
0: TileSet.CELL_NEIGHBOR_RIGHT_SIDE,
|
0: TileSet.CELL_NEIGHBOR_RIGHT_SIDE,
|
||||||
1: TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
|
1: TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
|
||||||
2: TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
|
2: TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
|
||||||
|
|
@ -22,43 +22,41 @@ var cur_int: Dictionary = {
|
||||||
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE: 5,
|
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:
|
func _ready() -> void:
|
||||||
self.set_z_index(1)
|
self.set_z_index(1)
|
||||||
self.set_frame(cur_int[dir])
|
self.set_frame(cur_int[dir])
|
||||||
tiles.set_tile(pos, (tiles.get_tile_colour(pos))) # TODO: should probably use another dictionary
|
tiles.set_tile(pos, tiles.get_tile_colour(pos))
|
||||||
move()
|
move(dir)
|
||||||
|
|
||||||
|
# update loop:
|
||||||
|
# move in dir
|
||||||
|
# get tile col, change dir based on col
|
||||||
|
# paint tile col
|
||||||
func update() -> void:
|
func update() -> void:
|
||||||
var tile: int = tiles.get_tile_colour(pos)
|
move(dir)
|
||||||
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)
|
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
|
var delta: Vector2
|
||||||
match dir:
|
match to:
|
||||||
TileSet.CELL_NEIGHBOR_RIGHT_SIDE:
|
TileSet.CELL_NEIGHBOR_RIGHT_SIDE:
|
||||||
delta = Vector2(tiles.texSize.x, 0)
|
delta = Vector2(tiles.texSize.x, 0)
|
||||||
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE:
|
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
@export var stepSize: float = 2
|
|
||||||
@export var ant: Sprite2D
|
|
||||||
@export var tiles: TileMapLayer
|
|
||||||
var t: float = -1
|
var t: float = -1
|
||||||
var paused: bool = false
|
var paused: bool = false
|
||||||
|
@export var stepSize: float = 20
|
||||||
|
@export var ant: Sprite2D
|
||||||
|
@export var tiles: TileMapLayer
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
@ -19,6 +18,6 @@ func _process(delta: float) -> void:
|
||||||
if paused: return
|
if paused: return
|
||||||
|
|
||||||
t += delta
|
t += delta
|
||||||
if (t > stepSize/100):
|
if (t > stepSize/1000):
|
||||||
t = 0
|
t = 0
|
||||||
ant.update()
|
ant.update()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue