#help with the bitmasking and procedural generation

14 messages · Page 1 of 1 (latest)

unkempt lily
#

here my whole creation code

#

help with the bitmasking and procedural generation

#

create

#
//always random the sizes when activeted
randomize();

//enums for room types and information about it
enum map_type{
    small,
    medium,
    large
    
}

enum map_info{
    
    void,
    ground
    
}

//type of room
rm_type = map_type.large;

//defines aspect about each size of rooms
if (rm_type == map_type.small){
    rm_size = 16;
    steps = 480;
}
else if  (rm_type == map_type.medium){
    rm_size = 32;
    steps = 480;
}
else if  (rm_type == map_type.large){
    rm_size = 64;
    steps = irandom_range(480, 960);
}

//contruction of the grid to generate the rooms
rm_width = rm_size * CELL_SIZE;
rm_heigth = rm_width div 2;
global.grid_width = rm_width div CELL_SIZE;
global.grid_heigth = rm_heigth div CELL_SIZE;
global.grid_map = ds_grid_create(global.grid_width, global.grid_heigth);
ds_grid_clear(global.grid_map, map_info.void);

if (!layer_exists("top_wall")){
    
    var _lay = layer_create(-2, "top_wall")
    wall_top_map_layer = layer_tilemap_create(_lay, 0, 0, Ts_top_wall, global.grid_width, global.grid_heigth);
    
}

//create objects layer
if (!layer_exists("entities")){
    
    var _lay = layer_create(-1, "entities")
    
}

//create floor layer
if (!layer_exists("floor_tiles")){
    
    var _lay = layer_create(2, "floor_tiles")
    floor_map_layer = layer_tilemap_create(_lay, 0, 0, Ts_ground, global.grid_width, global.grid_heigth);
    
}
#
//clean up

//delete the grid
if (ds_exists(global.grid_map, ds_type_grid)) {
    ds_grid_destroy(global.grid_map);
}
#
//room start 

//the procedural generation code
room_width = rm_width;
room_height = rm_heigth;

var _x1 = global.grid_width div 2;
var _y1 = global.grid_heigth div 2;
var _dir = irandom(3);
var _odds = 1;

var _p_x = _x1 * CELL_SIZE + CELL_SIZE / 2;
var _p_y = _y1 * CELL_SIZE + CELL_SIZE / 2;

instance_create_layer(_p_x, _p_y, "entities", choose(Obj_Cindy, Obj_Otto));

for (var _i = 0; _i < steps; _i++){
    
    global.grid_map[# _x1, _y1] = map_info.ground;
    
    if (irandom(_odds) == _odds){_dir = irandom(3);}
    
    var _x_dir = lengthdir_x(1, _dir * 90);
    var _y_dir = lengthdir_y(1, _dir * 90);
    
    _x1 += _x_dir;
    _y1 += _y_dir;
    
    if (_x1 < 2 or _x1 > global.grid_width - 2){_x1 += -_x_dir * 2;}
    
    if (_y1 < 2 or _y1 > global.grid_heigth - 2){_y1 += -_y_dir * 2;}
    
}
#

as well in room start

#
//the bit masking code

for (var _xx = 0; _xx < global.grid_width; _xx++){
    
    for (var _yy = 0; _yy < global.grid_heigth; _yy++){
        if (global.grid_map[# _xx, _yy] != map_info.ground){
            var _n_tile = global.grid_map[# _xx, _yy - 1] == map_info.void;
            var _w_tile = global.grid_map[# _xx - 1, _yy] == map_info.void;
            var _e_tile = global.grid_map[# _xx + 1, _yy] == map_info.void;
            var _s_tile = global.grid_map[# _xx, _yy + 1] == map_info.void;
        
            if (global.grid_map[# _xx, _yy + 1] == map_info.ground){instance_create_layer(_xx * CELL_SIZE, _yy * CELL_SIZE, "entities", Obj_wall);}
            else if (global.grid_map[# _xx, _yy - 1] == map_info.ground){instance_create_layer(_xx * CELL_SIZE, _yy * CELL_SIZE, "entities", Obj_wall);}
            else if (global.grid_map[# _xx + 1, _yy] == map_info.ground){instance_create_layer(_xx * CELL_SIZE, _yy * CELL_SIZE, "entities", Obj_wall);}
            else if (global.grid_map[# _xx - 1, _yy] == map_info.ground){instance_create_layer(_xx * CELL_SIZE, _yy * CELL_SIZE, "entities", Obj_wall);} 
            
            var _tile_index = NORTH * _n_tile + WEST * _w_tile + EAST * _e_tile + SOUTH * _s_tile + 1;
        
            tilemap_set(wall_top_map_layer, _tile_index, _xx, _yy - 1);
        }
            else if (global.grid_map[# _xx, _yy] == map_info.ground){
                
                var _tile_index = 1;
        
                tilemap_set(floor_map_layer, _tile_index, _xx, _yy);
                
            }
        
    }
}
#

yes, i tried ```gml
tilemap_set(wall_top_map_layer, _tile_index, _xx, _yy - 1);

#

but this is the result

#

it's creates some void tiles in the ground tiles

#

if someone could help me, i would be glad