sourceextensions/scene/demos/voxels-dig.xtl
1⍝# Voxels, 10: digging and building in the endless world. A crosshair
2⍝# marks where you look; the block under it, within 5 blocks, is found
3⍝# by marching 100 points along the view ray (en:p_ick). Click it to dig
4⍝# it out; right-click to place a block of the kind chosen on the hotbar
5⍝# against it. Each change is an edit the world remembers (x y z and the
6⍝# block), and every column is made with its edits -- the edited one
7⍝# made again at once (and its neighbor, when the block is on their
8⍝# border), so walk away and come back and the hole is still there.
9⍝# Run: just demo scene voxels-dig
10⍝# click (or X) dig, right-click (or E) place, 1 to 7 choose the block
11⍝# (stone dirt grass sand wood leaves water), W A S D walk, Space jump, Shift
12⍝# run, F fly (Space up, Shift down), drag or the arrows to look, H
13⍝# back to the start, q quit
14
15ᵉⁿ⁼u̲se< "Endless"
16ᵛˣ⁼u̲se< "Voxels"
17ᵖˡ⁼u̲se< "Play"
18ˢᶜ⁼u̲se< "Scene"
19
20w ← "Voxels 10: dig and build -- X_eTaL" ˢᶜo̲pen! 640 400
21g ← w ˢᶜf̲og! 22.0 44.0
22k ← w ˢᶜs̲ky! 0.55 0.72 0.92
23k ← w ˢᶜc̲urve! 160.0
24
25ᵖˡhelp
26
27⍝## Edits, checked
28
29⍝# Each column is made with the edits that fall in it or its border of
30⍝# one (en:e_dited): here column (0, 0) and its neighbor (1, 0) to the
31⍝# east, with the cell x 15 -- the column's east edge -- edited twice.
32b ← ᵛˣc̲olumnBlocks 0 0
33ed ← 3 4 r̲eshape 15 20 5 7 15 20 5 0 3 10 3 6
34e ← (ed, 0 0) ᵉⁿe̲dited b
35⍝# q u:c_ell m: the block at q (x y z, the column's own cells 1 to 16)
36⍝# of the 18 by 32 by 18 blocks m
37ᵘc̲ell ← { q m → (1 + (3 s̲elect q) + 18 × (2 s̲elect q) + 32 × 1 s̲elect q) s̲elect r̲avel m }
38"in the column: the newest edit of x 15 (leaves, 7), the wood (6) at 3 10 3:"
39(16 20 6 ᵘc̲ell e) c̲at 4 10 4 ᵘc̲ell e
40"how many cells changed (the two edited):"
41'+ r̲/ (r̲avel e) ≠ r̲avel b
42"the neighbor (1, 0) sees the edit in its border, x 0:"
430 20 6 ᵘc̲ell (ed, 1 0) ᵉⁿe̲dited ᵛˣc̲olumnBlocks 1 0
44
45⍝## Playing
46
47⍝# The hotbar, digging, placing and a frame of the game are the library
48⍝# Play.xtl, shared with voxels-water; the state is (the world and its
49⍝# player, the chosen block).
50hud ← w ᵖˡh̲ud 1
51s ← ᵉⁿn̲ew w
52s ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s
53last ← 100000 'ᵖˡf̲rame p̲ower (s, 1)
54z ← ˢᶜc̲lose! w
55⍝ (an accessor, not a top-level tuple pattern: xetal doc would list a
56⍝ hidden %N value for one, ask E10)
57ᵘw̲orldOf ← { (s, _) → s }
58s ← ᵘw̲orldOf last
59"the edits (x y z block), the newest first:"
60ᵉⁿe̲dits s
61"bye"