programextensions/scene/demos/voxels-dig.xtl
Voxels, 10: digging and building in the endless world. A crosshair marks where you look; the block under it, within 5 blocks, is found by marching 100 points along the view ray (en:p_ick). Click it to dig it out; right-click to place a block of the kind chosen on the hotbar against it. Each change is an edit the world remembers (x y z and the block), and every column is made with its edits -- the edited one made again at once (and its neighbor, when the block is on their border), so walk away and come back and the hole is still there. Run: just demo scene voxels-dig click (or X) dig, right-click (or E) place, 1 to 7 choose the block (stone dirt grass sand wood leaves water), W A S D walk, Space jump, Shift run, F fly (Space up, Shift down), drag or the arrows to look, H back to the start, q quit
Edits, checked
b : Int
Each column is made with the edits that fall in it or its border of one (en:e_dited): here column (0, 0) and its neighbor (1, 0) to the east, with the cell x 15 -- the column's east edge -- edited twice.
b ← ᵛˣc̲olumnBlocks 0 0
ed : Int
ed ← 3 4 r̲eshape 15 20 5 7 15 20 5 0 3 10 3 6
ᵘc̲ell : Int -> a -> a
q u:c_ell m: the block at q (x y z, the column's own cells 1 to 16) of the 18 by 32 by 18 blocks m
ᵘc̲ell ← { q m → (1 + (3 s̲elect q) + 18 × (2 s̲elect q) + 32 × 1 s̲elect q) s̲elect r̲avel m }
Playing
hud : Int
The hotbar, digging, placing and a frame of the game are the library Play.xtl, shared with voxels-water; the state is (the world and its player, the chosen block).
hud ← w ᵖˡh̲ud 1
s : ((Float, Float, Float, Float, Float, Float), (Int, Int, Box Int, Box Int, Int, Int, Int, Int), (Int, Int, Int, Int), (Int, Int, Float, Int, Int))
s ← ᵉⁿn̲ew w
s : ((Float, Float, Float, Float, Float, Float), (Int, Int, Box Int, Box Int, Int, Int, Int, Int), (Int, Int, Int, Int), (Int, Int, Float, Int, Int))
s ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s