UNPKG

shellquest

Version:

Terminal-based procedurally generated dungeon crawler

195 lines (169 loc) 8.7 kB
import type {Tile} from '../types.ts'; import type {TileMap} from '../../TileMap.ts'; export function setupTileDefinitions(mainTileMap: TileMap): void { mainTileMap.loadFromFile('tilemap_packed.png'); const tiles: Tile[] = [ {name: 'grass-1', x: 0, y: 0, layer: 'bottom', solid: false}, {name: 'grass-2', x: 1, y: 0, layer: 'bottom', solid: false}, {name: 'grass-3', x: 2, y: 0, layer: 'bottom', solid: false}, {name: 'grass-outer-dirt-inner-9slice-top-left', x: 0, y: 1, layer: 'bottom', solid: false}, {name: 'grass-outer-dirt-inner-9slice-top', x: 1, y: 1, layer: 'bottom', solid: false}, {name: 'grass-outer-dirt-inner-9slice-top-right', x: 2, y: 1, layer: 'bottom', solid: false}, { name: 'grass-outer-dirt-inner-9slice-middle-left', x: 0, y: 2, layer: 'bottom', solid: false, }, {name: 'dirt-1', x: 1, y: 2, layer: 'bottom', solid: false}, { name: 'grass-outer-dirt-inner-9slice-middle-right', x: 2, y: 2, layer: 'bottom', solid: false, }, { name: 'grass-outer-dirt-inner-9slice-bottom-left', x: 0, y: 3, layer: 'bottom', solid: false, }, {name: 'grass-outer-dirt-inner-9slice-bottom', x: 1, y: 3, layer: 'bottom', solid: false}, { name: 'grass-outer-dirt-inner-9slice-bottom-right', x: 2, y: 3, layer: 'bottom', solid: false, }, {name: 'dirt-2', x: 3, y: 3, layer: 'bottom', solid: false}, {name: 'dirt-3', x: 4, y: 3, layer: 'bottom', solid: false}, {name: 'dirt-4', x: 5, y: 3, layer: 'bottom', solid: false}, {name: 'dirt-5', x: 6, y: 3, layer: 'bottom', solid: false}, {name: 'grass-walking-path', x: 7, y: 3, layer: 'bottom', solid: false}, {name: 'fence-corner-top-left', x: 8, y: 3, layer: 'sprite', solid: true}, {name: 'fence-corner-top-right', x: 10, y: 3, layer: 'sprite', solid: true}, {name: 'fence-corner-bottom-left', x: 8, y: 5, layer: 'sprite', solid: true}, {name: 'fence-corner-bottom-right', x: 10, y: 5, layer: 'sprite', solid: true}, {name: 'fence-horizontal-withbar', x: 9, y: 3, layer: 'sprite', solid: true}, {name: 'fence-vertical-left-withbar', x: 8, y: 4, layer: 'sprite', solid: true}, {name: 'fence-vertical-right-withbar', x: 10, y: 4, layer: 'sprite', solid: true}, {name: 'fence-vertical-top', x: 11, y: 3, layer: 'sprite', solid: true}, {name: 'fence-vertical-middle-withbar', x: 11, y: 4, layer: 'sprite', solid: true}, {name: 'fence-vertical-bottom', x: 11, y: 5, layer: 'sprite', solid: true}, {name: 'fence-horizontal-left', x: 8, y: 6, layer: 'sprite', solid: true}, {name: 'fence-horizontal-middle-nobar', x: 9, y: 6, layer: 'sprite', solid: true}, {name: 'fence-horizontal-right', x: 10, y: 6, layer: 'sprite', solid: true}, {name: 'tall-tree-1-top', x: 3, y: 0, layer: 'top', solid: false}, {name: 'tall-tree-1-bottom', x: 3, y: 1, layer: 'sprite', solid: true}, {name: 'tall-tree-2-top', x: 4, y: 0, layer: 'top', solid: false}, {name: 'tall-tree-2-bottom', x: 4, y: 1, layer: 'sprite', solid: true}, {name: 'small-tree-1', x: 3, y: 2, layer: 'sprite', solid: true}, {name: 'small-tree-2', x: 4, y: 2, layer: 'sprite', solid: true}, {name: 'bush-1', x: 5, y: 0, layer: 'sprite', solid: true}, {name: 'vine-1', x: 5, y: 1, layer: 'sprite', solid: true}, {name: 'mushroom-1', x: 5, y: 2, layer: 'sprite', solid: true}, // this is for a simple cluster. they can not be tiled beyond these 5 sprites, but they can be place as a group {name: 'tree-cluster-1-top', x: 7, y: 0, layer: 'sprite', solid: true}, {name: 'tree-cluster-1-left', x: 6, y: 1, layer: 'sprite', solid: true}, {name: 'tree-cluster-1-center', x: 7, y: 1, layer: 'sprite', solid: true}, {name: 'tree-cluster-1-right', x: 8, y: 1, layer: 'sprite', solid: true}, {name: 'tree-cluster-1-bottom', x: 7, y: 2, layer: 'sprite', solid: true}, // this is for a simple cluster. they can not be tiled beyond these 5 sprites, but they can be place as a group {name: 'tree-cluster-2-top', x: 7 + 3, y: 0, layer: 'sprite', solid: true}, {name: 'tree-cluster-2-left', x: 6 + 3, y: 1, layer: 'sprite', solid: true}, {name: 'tree-cluster-2-center', x: 7 + 3, y: 1, layer: 'sprite', solid: true}, {name: 'tree-cluster-2-right', x: 8 + 3, y: 1, layer: 'sprite', solid: true}, {name: 'tree-cluster-2-bottom', x: 7 + 3, y: 2, layer: 'sprite', solid: true}, // these can be tiled indefinitely. when placed it must include all 4 tiles as it has partial trees // when you place the 4 tile cluster next to each other horizontally you must place the tiles on top of eachother with one layer on sprite and one on top // so tree-tile-1-top-left and tree-tile-1-top-right will occupy the same tile, and top and bottom will occupy the same tile {name: 'tree-tile-1-top-left', x: 6, y: 0, layer: 'sprite', solid: true}, {name: 'tree-tile-1-top-right', x: 8, y: 0, layer: 'sprite', solid: true}, {name: 'tree-tile-1-bottom-left', x: 6, y: 2, layer: 'sprite', solid: true}, {name: 'tree-tile-1-bottom-right', x: 8, y: 2, layer: 'sprite', solid: true}, // these can be tiled indefinitely. when placed it must include all 4 tiles as it has partial trees // when you place the 4 tile cluster next to each other horizontally you must place the tiles on top of eachother with one layer on sprite and one on top // so tree-tile-2-top-left and tree-tile-2-top-right will occupy the same tile, and top and bottom will occupy the same tile {name: 'tree-tile-2-top-left', x: 6 + 3, y: 0, layer: 'sprite', solid: true}, {name: 'tree-tile-2-top-right', x: 8 + 3, y: 0, layer: 'sprite', solid: true}, {name: 'tree-tile-2-bottom-left', x: 6 + 3, y: 2, layer: 'sprite', solid: true}, {name: 'tree-tile-2-bottom-right', x: 8 + 3, y: 2, layer: 'sprite', solid: true}, {name: 'player', x: 0, y: 18, layer: 'sprite', solid: true}, {name: 'zombie', x: 1, y: 18, layer: 'sprite', solid: true}, {name: 'wand', x: 10, y: 21, layer: 'sprite', solid: true}, {name: 'sword', x: 8, y: 19, layer: 'sprite', solid: true}, ]; for (let house of [ {name: 'house-1', x: 0}, {name: 'house-2', x: 4}, ]) { tiles.push( ...([ { name: `${house.name}-roof-top-top-left`, x: 0 + house.x, y: 4, layer: 'top', solid: true, }, {name: `${house.name}-roof-top-middle`, x: 1 + house.x, y: 4, layer: 'top', solid: true}, { name: `${house.name}-roof-top-top-right`, x: 2 + house.x, y: 4, layer: 'top', solid: true, }, {name: `${house.name}-roof-top-chimney`, x: 3 + house.x, y: 4, layer: 'top', solid: true}, {name: `${house.name}-roof-bottom-left`, x: 0 + house.x, y: 5, layer: 'top', solid: true}, { name: `${house.name}-roof-bottom-middle`, x: 1 + house.x, y: 5, layer: 'top', solid: true, }, { name: `${house.name}-roof-bottom-right`, x: 2 + house.x, y: 5, layer: 'top', solid: true, }, {name: `${house.name}-roof-bottom-arch`, x: 3 + house.x, y: 5, layer: 'top', solid: true}, {name: `${house.name}-wall-left`, x: 0 + house.x, y: 6, layer: 'top', solid: true}, {name: `${house.name}-wall-middle`, x: 1 + house.x, y: 6, layer: 'top', solid: true}, {name: `${house.name}-wall-right`, x: 3 + house.x, y: 6, layer: 'top', solid: true}, {name: `${house.name}-wall-window`, x: 0 + house.x, y: 7, layer: 'top', solid: true}, {name: `${house.name}-wall-door-hole`, x: 2 + house.x, y: 6, layer: 'top', solid: true}, {name: `${house.name}-wall-door-single`, x: 1 + house.x, y: 7, layer: 'top', solid: true}, { name: `${house.name}-wall-door-double-left`, x: 2 + house.x, y: 7, layer: 'top', solid: true, }, { name: `${house.name}-wall-door-double-right`, x: 3 + house.x, y: 7, layer: 'top', solid: true, }, ] as Tile[]), ); } for (const tile of tiles) { mainTileMap.defineTile(tile.name, tile.x, tile.y, { layer: tile.layer, solid: tile.solid, flipX: tile.flipX, flipY: tile.flipY, }); } }