sourceextensions/scene/demos/voxels-fly.xtl
1⍝# Voxels, 7: flying. The endless world of voxels-endless, now from the
2⍝# air: F switches between walking and flying. Flying moves level
3⍝# whatever you look at -- W forward, S back, A and D sideways -- Space
4⍝# rises and Shift sinks, with no gravity, the blocks still stopping you;
5⍝# so you can look down at the land as you cross it. F again drops you
6⍝# back to walking wherever you are. The columns are made ahead, one a
7⍝# frame, and dropped behind, under fog and a curved horizon.
8⍝# Run: just demo scene voxels-fly
9⍝# F fly or walk; flying: W A S D level, Space up, Shift down; walking:
10⍝# Space jump or swim up, Shift run; drag the mouse or the arrows to
11⍝# look, H: back to the start, q quit
12
13ᵉⁿ⁼u̲se< "Endless"
14ˢᶜ⁼u̲se< "Scene"
15
16w ← "Voxels 7: flying -- X_eTaL" ˢᶜo̲pen! 640 400
17g ← w ˢᶜf̲og! 22.0 44.0
18k ← w ˢᶜs̲ky! 0.55 0.72 0.92
19k ← w ˢᶜc̲urve! 160.0
20
21"keys: F fly or walk; flying: W A S D level, Space up, Shift down; walking: Space jump/swim, Shift run; drag or arrows look; H home; q quit"
22
23⍝# the world around the start made before the first frame: each column
24⍝# takes three steps
25s ← ᵉⁿn̲ew w
26s ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s
27"columns made at the start:"
28t̲ally ᵉⁿk̲eys s
29
30⍝# one frame: an event, then a third of a column's work, then the
31⍝# player
32ᵘf̲rame ← { s →
33 ᵉⁿs̲topped s ? s
34 v ← ˢᶜn̲ext! w
35 ((v m̲atch "close") + (v m̲atch "key q") + v m̲atch "key Escape") > 0 ? ᵉⁿs̲top s
36 s ← (v m̲atch "key h") ᵘi̲f s
37 s ← ᵉⁿs̲tream s
38 s ← (v m̲atch "key f") ᵘf̲ly s
39 s ᵉⁿm̲ove ˢᶜc̲ontrols w
40}
41ᵘi̲f ← { yes s →
42 yes ? ᵉⁿh̲omeAgain s
43 s
44}
45ᵘf̲ly ← { yes s →
46 yes ? ᵉⁿt̲oggleFly s
47 s
48}
49last ← 100000 'ᵘf̲rame p̲ower s
50z ← ˢᶜc̲lose! w
51"where it ended (x y z, blocks), the columns kept:"
52(f̲loat f̲loor 0.5 + 3 t̲ake ᵉⁿp̲layer last) c̲at f̲loat t̲ally ᵉⁿk̲eys last
53"bye"