O
ookki
Guest
Hello.
I've been playing around with a ds_grid based tilemap, random generation and autotiling.
My basic idea is to have destructible terrain with some other stored variables like perhaps friction in a ds_map stored within the grid cell corresponding the tile. Now, I have watched some tutorials concerning the topics and have blatantly copied and modified some of the code. Here's the most basic part of the modified code:
The last part of the code is what makes this messy for me. (I left it here as it's in the original code. FLOOR, WALL and VOID are just constants.) The questions are:
1) Should I actually even take this approach or is there another way I should pursue and what way is that?
2) If this is a suitable approach, is there a way to do the last code block more tidy than something like:
3) I would think it would be better to have the empty tiles just have a simple number (VOID at the moment) than just fill them with ds_maps as well, but that would mean checking an empty tile with an accessor would give an error. The solution, which comes to my mind is doing something like:
And do that every single time I want to check the ds_map. But it just feels really ugly. Perhaps it's the right way but I'd like to have some thoughts on this.
Here's the link to the original code I stole:
https://www.dropbox.com/s/d15t23zqr2kehnp/Level Generation and Autotiling.txt?dl=0
I think it was by HeartBeast.
I've been playing around with a ds_grid based tilemap, random generation and autotiling.
My basic idea is to have destructible terrain with some other stored variables like perhaps friction in a ds_map stored within the grid cell corresponding the tile. Now, I have watched some tutorials concerning the topics and have blatantly copied and modified some of the code. Here's the most basic part of the modified code:
Code:
// initialize ds_grid as a tilemap
var width = room_width div CELL_WIDTH; // cell_width is the width of a tile
var height = room_height div CELL_HEIGHT; // convert room height into DS_GRID size
tileMap = ds_grid_create(width, height);
ds_grid_set_region(tileMap, 0, 0, width-1, height-1, VOID); // initially set every cell as VOID
/* fill 2/3 of the map with soil. We do that by adding a ds_map for the tile.
the parameters are:
-Type =
-TileId = the index of the tile
-HP = the hitpoints of the tile
-Friction_s and _k = respective friction coefficients
-CenterTile = is this a center tile or not?
*/
// set the center tiles
for (var _xx = 0; _xx < width - 1; _xx++) {
for (var _yy = height div 3; _yy < height - 1 ; _yy++) { // fill 2/3 of the map with tiles
tileMap[# _xx, _yy] = ds_map_create();
var dsMap = tileMap[# _xx, _yy];
dsMap[? "CenterTile"] = true;
dsMap[? "TileBg"] = bg_soil;
}
}
// add border tiles
for (var xx = 0; _xx < width - 1; xx++) {
for (var yy = 0; _yy < height - 1 ; yy++) {
if (grid[# xx, yy] == FLOOR) {
if (grid[# xx+1, yy] != FLOOR) grid[# xx+1,yy] = WALL;
if (grid[# xx-1, yy] != FLOOR) grid[# xx-1,yy] = WALL;
if (grid[# xx, yy+1] != FLOOR) grid[# xx,yy+1] = WALL;
if (grid[# xx, yy-1] != FLOOR) grid[# xx,yy-1] = WALL;
}
}
}
1) Should I actually even take this approach or is there another way I should pursue and what way is that?
2) If this is a suitable approach, is there a way to do the last code block more tidy than something like:
Code:
var dsMap = tileMap[# xx, yy];
if dsMap[? "CenterTile"] {
dsMap = tileMap[# xx+1,yy];
if (!dsMap[? "CenterTile"] {
dsMap[? "CenterTile"] = false;
}
dsMap = tileMap[# xx-1,yy];
if (!dsMap[? "CenterTile"] {
dsMap[? "CenterTile"] = false;
}
... and so on.
Code:
if tileMap[# x, y] != VOID {
dsMap = tileMap[# x, y];
}
Here's the link to the original code I stole:
https://www.dropbox.com/s/d15t23zqr2kehnp/Level Generation and Autotiling.txt?dl=0
I think it was by HeartBeast.