Godot Version
4.5.1
Question
I am very new to Godot but have an idea for something I want to work on so found some template code I wanted to make use of.
Below is some code from Godot 3 and this works just fine. It was a demo project I found and i wanted to move it up to 4 so that i can build upon it.
const N = 1
const E = 2
const S = 4
const W = 8
var cell_walls = { Vector2i(0, -1): N, Vector2i(1, 0): E, Vector2i(0, 1): S, Vector2i(-1, 0): W }
func make_maze():
print("making maze")
var unvisited = [] # array of unvisited tiles
var stack = []
# fill the map with solid tiles
Map.clear()
for x in range(width):
for y in range(height):
unvisited.append(Vector2(x, y))
Map.set_cellv(Vector2(x, y), N|E|S|W)
var current = Vector2(0, 0)
unvisited.erase(current)
# execute recursive backtracker algorithm
while unvisited:
print("unvisited")
var neighbors = check_neighbors(current, unvisited)
if neighbors.size() > 0:
var next = neighbors[randi() % neighbors.size()]
stack.append(current)
# remove walls from *both* cells
var dir = next - current
# This is getting the TileSet tile by ID, e.g. 15 == all grass tile
var current_walls = Map.get_cellv(current) - cell_walls[dir]
var cell_walls_a = cell_walls[dir]
var current_a = Map.get_cellv(current)
var next_walls = Map.get_cellv(next) - cell_walls[-dir]
print("Current walls: " + str(current_walls))
print("Next walls: " + str(next_walls))
Map.set_cellv(current, current_walls)
Map.set_cellv(next, next_walls)
current = next
unvisited.erase(current)
elif stack:
print("pop_back")
current = stack.pop_back()
yield(get_tree(), 'idle_frame')
Godot 4 deprecated TileMaps and this does not work like for like. I have made some changes to it and it runs, but it does not generate anything. The issue is the current_walls is returning negative values as opposed to positive in 3. This is due to the way it retrieves or cannot retrieves the values for N | E | S | W in cell_walls.
I am struggling to understand what needs to change to get this to work the same way in 4. I’ve Googled so much and looked at the docs and the mostly what I come across is people complaining about the rework to TileMaps to TileMapLayers and it being more difficult to do than before.
Can anyone shed some light on what it is I need to amend?