Godot Version
Godot 4.2
Question
Need help with two things: setting up the terrain set for the tileset, and adjusting the code for it. I followed the code shown in Heartbeast’s video. Here is the code, one for the tilemap:
extends Node
class_name Walker
const DIRECTIONS = [Vector2.RIGHT, Vector2.UP, Vector2.LEFT, Vector2.DOWN]
var position = Vector2.ZERO
var direction = Vector2.RIGHT
var borders = Rect2()
var step_history = []
var steps_since_turn = 0
var rooms = []
func _init(starting_position, new_borders):
assert(new_borders.has_point(starting_position))
position = starting_position
step_history.append(position)
borders = new_borders
func walk(steps):
place_room(position)
for step in steps:
if randf() <= 0.5 and steps_since_turn >= 7:
change_direction()
if step():
step_history.append(position)
else:
change_direction()
return step_history
func step():
var target_position = position + direction
if borders.has_point(target_position):
steps_since_turn += 1
position = target_position
return true
else:
return false
func change_direction():
place_room(position)
steps_since_turn = 0
var directions = DIRECTIONS.duplicate()
directions.erase(direction)
directions.shuffle()
direction = directions.pop_front()
while not borders.has_point(position + direction):
direction = directions.pop_front()
func create_room(position, size):
return {position = position, size = size}
func place_room(position):
var size = Vector2(randi() % 4 + 2, randi() % 4 + 2)
var top_left_corner = (position - size/2).ceil()
rooms.append(create_room(position, size))
for y in size.y:
for x in size.x:
var new_step = top_left_corner + Vector2(x, y)
if borders.has_point(new_step):
step_history.append(new_step)
```
And code for the 2D node:
extends Node2D
var borders = Rect2(1, 1, 152, 81)
@onready var tileMap = $TileMap
func _ready():
randomize()
generate_level()
func generate_level():
var walker = Walker.new(Vector2(76, 40.5), borders)
var map = walker.walk(1000)
walker.queue_free()
for location in map:
tileMap.erase_cell(0, location)
var used_tiles = tileMap.get_used_cells(0)
for tile in used_tiles:
tileMap.erase_cell(0, tile)
tileMap.set_cells_terrain_connect(0, used_tiles, 0, 0)
func reload_level():
get_tree().reload_current_scene()
func _input(event):
if event.is_action_pressed(“ui_accept”):
reload_level()```
How can I adjust the code so that I can place custom floors, walls, and filling?
And part of this, how do I set up the terrain set for the tileset?
Picture:
Talking specifically about the tiles without it, as they are tiles with shadows, I don’t know how to do it for the shadows of the tiles.