Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JorensM |
So I made a room generator function, and it works fine most of the time, but occasionally it will not generate left or top walls.
This is how it normally looks:
This is how it occasionally looks:
I can’t for the time being figure out what is wrong with my code. I try to follow the logic trail but to me it seems that it should be working just fine! The code by default sets the tile to FLOOR, and when the program detects an edge, it replaces it with a wall, but for some reason sometimes it doesn’t work with the left or top walls
Here is my code for the room generator:
func generateRoom(var size, var pos, var enemies):
var tile
for y in range(0, size.y):
for x in range(0, size.x):
#Set tile to FLOOR by default.
tile = tile_id.FLOOR
#Check if first row
if(y == 0):
if(x == 0):
tile = tile_id.WALL_LEFT
elif(x == size.x - 1):
tile = tile_id.WALL_RIGHT
else:
tile = tile_id.WALL_TOP
#Check if last row
elif(y == size.y - 1):
if(x == 0):
tile = tile_id.WALL_BOTTOM_CORNER_LEFT
elif(x == size.x - 1):
tile = tile_id.WALL_BOTTOM_CORNER_RIGHT
else:
tile = tile_id.WALL_BOTTOM
elif(x == 0):
tile = tile_id.WALL_LEFT
elif(x == size.x - 1):
tile = tile_id.WALL_RIGHT
$TileMap.set_cell(x + pos.x, y + pos.y, tile)
The problem only occurs with left and top walls.