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

source · imports en: extensions/scene/demos/Endless.xtl; vx: extensions/scene/demos/Voxels.xtl; pl: extensions/scene/demos/Play.xtl; sc: extensions/scene/lib/Scene.xtl

w : Int

value · line 20
w ← "Voxels 10: dig and build -- X_eTaL" ˢᶜo̲pen! 640 400
Used in: g, k, hud, s, z

g : Int

value · line 21
g ← w ˢᶜf̲og! 22.0 44.0

k : Int

value · line 22
k ← w ˢᶜs̲ky! 0.55 0.72 0.92

k : Int

value · line 23
k ← w ˢᶜc̲urve! 160.0

Edits, checked

b : Int

value · line 32

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

value · line 33
ed ← 3 4 r̲eshape 15 20 5 7  15 20 5 0  3 10 3 6

e : Int

value · line 34
e ← (ed, 0 0) ᵉⁿe̲dited b

ᵘc̲ell : Int -> a -> a

function · line 37

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

value · line 50

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))

value · line 51
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))

value · line 52
s ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s

last : (((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)), Int)

value · line 53
last ← 100000 'ᵖˡf̲rame p̲ower (s, 1)
Used in: s

z : Int

value · line 54
z ← ˢᶜc̲lose! w

ᵘw̲orldOf : (Any a, Any b) => (a, b) -> a

function · line 57
ᵘw̲orldOf ← { (s, _) → s }
Used in: s

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))

value · line 58
s ← ᵘw̲orldOf last