W
Will
Guest
My level generator code looks like this:
The result looks like:
It calls scr_tilemap(x,y,block) to populate the positions within the level_grid with the appropriate pre-determined blocks. This is a very early and basic version, and this technically works as intended. I'm having some trouble though, and it's probably my own oversight, but I'm trying to separate the blocks by 128 on every side.
I tried the following code (adding the x_offset and y_offset vars):
But this was my result:
Where do the x&y offsets need to be to keep them aligned? I don't want to put them in scr_tilemap, because these positions start at (0,0) and then are adjusted by the code to determine where to draw them.
If anyone can help, that would be greatly appreciated, and if you need more clarification let me know. This really should be a quick fix, but I've been staring for a while and can't figure it out.
Code:
randomize();
grid_size = irandom_range(3,4);
level_grid = ds_grid_create(grid_size,grid_size);
ds_grid_set_region(level_grid,0,0,grid_size - 1,grid_size - 1,-1);
for (var row = 0;row < ds_grid_width(level_grid);row ++)
{
for (var col = 0;col < ds_grid_height(level_grid);col ++)
{
if level_grid[# row,col] = -1
{
var block = irandom_range(1,3)
scr_tilemap((128) + (512*row),(128) + (320*col),block);
level_grid[# row,col] = block;
}
}
}
It calls scr_tilemap(x,y,block) to populate the positions within the level_grid with the appropriate pre-determined blocks. This is a very early and basic version, and this technically works as intended. I'm having some trouble though, and it's probably my own oversight, but I'm trying to separate the blocks by 128 on every side.
I tried the following code (adding the x_offset and y_offset vars):
Code:
randomize();
grid_size = irandom_range(3,4);
level_grid = ds_grid_create(grid_size,grid_size);
ds_grid_set_region(level_grid,0,0,grid_size - 1,grid_size - 1,-1);
var offset_x = 0;
var offset_y = 0;
for (var row = 0;row < ds_grid_width(level_grid);row ++)
{
for (var col = 0;col < ds_grid_height(level_grid);col ++)
{
if level_grid[# row,col] = -1
{
var block = irandom_range(1,3)
scr_tilemap((128*offset_x) + (512*row),(128 * offset_y) + (320*col),block);
level_grid[# row,col] = block;
offset_x ++;
offset_y ++;
}
}
}
Where do the x&y offsets need to be to keep them aligned? I don't want to put them in scr_tilemap, because these positions start at (0,0) and then are adjusted by the code to determine where to draw them.
If anyone can help, that would be greatly appreciated, and if you need more clarification let me know. This really should be a quick fix, but I've been staring for a while and can't figure it out.