Make a meadow
Add a layer of cells with a style of grass and foliagePack to your rules, draw the layer with foliage, and paint the layer.
ts
// in src/rules.ts
import { createGame, defineCellLayer, foliagePack, presetFoliageStyles } from '@v12-engine/engine'
export const game = createGame({
id: 'my-game',
name: 'My game',
// the layer of grass: value 1 is a meadow, which burns and grows back
cellLayers: [defineCellLayer({ id: 'grass', name: 'Grass', values: [{ value: 1, name: 'Meadow', foliage: presetFoliageStyles.meadow }] })],
packs: [foliagePack({ layer: 'grass' })]
})
game.onStart((world) => {
world.setCells('grass', { kind: 'circle', x: 16, z: 16, radius: 12 }, 1)
})ts
// in src/view.ts
import { foliage, type GameView, presetFoliage } from '@v12-engine/client'
export const view: GameView = {
units: { looks: {} },
ground: { cellLayers: { grass: foliage(presetFoliage.meadow) } }
}Done: a round meadow of short blades and a few flowers fills the middle of the field. It sways in the wind and parts around units that walk through it.
A meadow with a look of your own
You can describe the look yourself, and give a second style its own look on top of the layer's:
ts
import { defineCellLayer, presetFoliageStyles } from '@v12-engine/engine'
import { foliage } from '@v12-engine/client'
export const grass = defineCellLayer({
id: 'grass',
name: 'Grass',
values: [
{ value: 1, name: 'Meadow', foliage: presetFoliageStyles.meadow },
{ value: 2, name: 'Clover', foliage: presetFoliageStyles.meadow }
]
})
export const look = foliage({
height: 0.9,
density: 5,
shape: { kind: 'blade', blades: 5, curve: 0.3 },
colors: { foot: [0.2, 0.4, 0.12], tip: [0.55, 0.75, 0.3], vary: 0.15, patches: { amount: 0.3, to: [0.65, 0.7, 0.3] } },
placing: { clump: { amount: 0.4 } },
scatter: [{ density: 0.1, height: 0.5, colors: [[0.95, 0.9, 0.4]] }],
// clover: shorter, darker, white flowers
styles: { 2: { height: 0.5, colors: { tip: [0.35, 0.6, 0.25] }, scatter: [{ density: 0.3, height: 0.3, colors: [[0.95, 0.95, 0.95]] }] } }
})Paint it in the map file
A map stores its grass as one value per cell, row by row:
ts
import { createMap } from '@v12-engine/engine'
const map = createMap({ name: 'Field', width: 32, depth: 32, players: 1, game: 'my-game', tileset: ['grass'] })
const cells = new Uint8Array(map.width * map.depth)
for (let z = 4; z < 28; z++) for (let x = 4; x < 28; x++) cells[z * map.width + x] = 1
map.cells = { grass: cells }In the editor
- Open the Terrain panel and click Meadow under your layer's name, Grass.
- Paint on the map.
- Open Grass and bushes and pick Preset › Meadow, or set the look group by group.
Reference
| Piece | What it is |
|---|---|
defineCellLayer({ id, name, values }) | The layer. Each value is a style, with its rules in foliage |
foliagePack({ layer }) | Hiding, trampling, fire and regrowth, following each style's rules |
foliage(look) | How the layer is drawn, in GameView.ground.cellLayers |
presetFoliage, presetFoliageStyles | Ready-made looks and rules, with matching names |
See Grass and bushes.