File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ export function draw(rootNode: Node<Room>) {
37
37
tiles = carveRooms ( tiles , rootNode ) ;
38
38
tiles = carveCorridors ( tiles , rootNode ) ;
39
39
40
+ // Add some padding to the tilemap for a more visually appealing result (optional)
41
+ // tiles = padTilemap(tiles, 3, TilesTypes.WALL);
42
+
40
43
// Draw tiles
41
44
drawTilesMask ( context , tileSize , tiles ) ;
42
45
drawTiles ( context , tileSize , tiles ) ;
@@ -237,8 +240,8 @@ function drawTilesMask(
237
240
// Compute the bitmask tilesmap
238
241
const mask = computeTilesMask ( normalized ) ;
239
242
240
- for ( let y = 0 ; y < tiles . length ; y ++ ) {
241
- for ( let x = 0 ; x < tiles [ y ] . length ; x ++ ) {
243
+ for ( let y = 0 ; y < mask . length ; y ++ ) {
244
+ for ( let x = 0 ; x < mask [ y ] . length ; x ++ ) {
242
245
const tileId = mask [ y ] [ x ] ;
243
246
const texture = tilesTextures [ tileId ] ;
244
247
Original file line number Diff line number Diff line change @@ -30,6 +30,32 @@ export function duplicateTilemap(tiles: Tiles): Tiles {
30
30
} ) ;
31
31
}
32
32
33
+ /**
34
+ * Pad a tilemap on all sides.
35
+ */
36
+ export function padTilemap (
37
+ tiles : Tiles ,
38
+ paddingWidth : number ,
39
+ fill : number
40
+ ) : Tiles {
41
+ const copy = duplicateTilemap ( tiles ) ;
42
+
43
+ const newLine = new Array ( tiles [ 0 ] . length ) . fill ( fill ) ;
44
+
45
+ for ( let i = 0 ; i < paddingWidth ; i ++ ) {
46
+ copy . unshift ( newLine ) ;
47
+ copy . push ( newLine ) ;
48
+ }
49
+
50
+ return copy . map ( ( row ) => {
51
+ return [
52
+ ...new Array ( paddingWidth ) . fill ( fill ) ,
53
+ ...row ,
54
+ ...new Array ( paddingWidth ) . fill ( fill ) ,
55
+ ] ;
56
+ } ) ;
57
+ }
58
+
33
59
/**
34
60
* Get the dungeon width and height in tiles unit.
35
61
*/
You can’t perform that action at this time.
0 commit comments