sourceextensions/scene/demos/voxels-endless.xtl
1⍝# Voxels, 6: an endless world. Walk in any direction and it never ends:
2⍝# the land comes from value noise hashed from the coordinates
3⍝# (vx:h_eightsAt), so any column of 16 by 16 blocks can be made by
4⍝# itself and fits its neighbors; columns are made around the player as
5⍝# it walks -- the nearest missing one each frame -- and dropped behind
6⍝# it; fog hides the edge of what is made, and a curved horizon (scene
7⍝# lowers the world by d^2 / 2R) makes it look like a small planet.
8⍝# Collision asks the columns themselves. The world and the player are
9⍝# the library Endless.xtl, shared with voxels-fly: each column is made
10⍝# over three frames, so no frame waits long.
11⍝# Run: just demo scene voxels-endless
12⍝# W A S D walk, Shift run, Space jump (in water: swim up; at the
13⍝# surface: climb out onto a bank one block high), drag the mouse or
14⍝# the arrows to look, H: back to the start, q or close: quit
15
16ᵉⁿ⁼u̲se< "Endless"
17ˢᶜ⁼u̲se< "Scene"
18
19w ← "Voxels 6: endless -- X_eTaL" ˢᶜo̲pen! 640 400
20g ← w ˢᶜf̲og! 22.0 44.0
21k ← w ˢᶜs̲ky! 0.55 0.72 0.92
22k ← w ˢᶜc̲urve! 160.0
23
24"keys: W A S D walk, Shift run, Space jump (in water: swim up, climb out), drag or arrows look, H home, q quit"
25
26⍝# the world around the start made before the first frame: each column
27⍝# takes three steps
28s ← ᵉⁿn̲ew w
29s ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s
30"columns made at the start:"
31t̲ally ᵉⁿk̲eys s
32
33⍝# one frame: an event, then a third of a column's work, then the
34⍝# player
35ᵘf̲rame ← { s →
36 ᵉⁿs̲topped s ? s
37 v ← ˢᶜn̲ext! w
38 ((v m̲atch "close") + (v m̲atch "key q") + v m̲atch "key Escape") > 0 ? ᵉⁿs̲top s
39 s ← (v m̲atch "key h") ᵘi̲f s
40 s ← ᵉⁿs̲tream s
41 s ᵉⁿm̲ove ˢᶜc̲ontrols w
42}
43ᵘi̲f ← { yes s →
44 yes ? ᵉⁿh̲omeAgain s
45 s
46}
47last ← 100000 'ᵘf̲rame p̲ower s
48z ← ˢᶜc̲lose! w
49"where the walk ended (x y z, blocks), the columns kept:"
50(f̲loat f̲loor 0.5 + 3 t̲ake ᵉⁿp̲layer last) c̲at f̲loat t̲ally ᵉⁿk̲eys last
51"bye"