code wiki / _hdl_build / nx_wasm_diablo_gate.nx
nx_wasm_diablo_gate.nx source
↩ module page · 69 lines · 3893 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_wasm_diablo_gate.nx -- NATIVE gate for the playable isometric ARPG (nx_wasm_diablo). Drives click()/tick()
4// the way the browser shim will, and verifies the game + the Diablo-generation render BEFORE lowering to wasm.
5// T1 MOVE: a click sets a destination; the hero walks toward it.
6// T2 COMBAT: chasing a foe and striking it kills it and pays gold.
7// T3 LOOT: walking onto the gold collects it.
8// T4 RENDER + LIGHTING: the torch follows the hero (hero lit, far corner in gloom). PNG.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_wasm_diablo.nx"
11import "nx_png.nx"
12import "nx_syscalls.nx"
13
14func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
15" as *u8); return ok }
16func lum(c: i64) -> i64 { return (c & 255) + ((c>>8)&255) + ((c>>16)&255) }
17
18func main() -> i64 {
19 gw("=== nx_wasm_diablo_gate: playable isometric ARPG (Diablo generation), verified NATIVE ===\n" as *u8)
20 var pass: i64 = 0; var total: i64 = 0
21 let base: i64 = sys_mmap(4*1024*1024) as i64
22 let mx: *i64 = (base + O_MX) as *i64
23 let my: *i64 = (base + O_MY) as *i64
24 let ma: *i64 = (base + O_MA) as *i64
25 let st: *i64 = (base + O_ST) as *i64
26
27 // ---- T1: move ----
28 init_impl(base)
29 let hx0: i64 = st[0]
30 click_impl(base, st[0] + 50, st[1])
31 var t: i64=0; while t < 30 { tick_impl(base, 0); t=t+1 }
32 var t1ok: i64=1; if st[0] <= hx0 + 8 {t1ok=0}
33 total=total+1; if t1ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
34 gw("T1 click-to-move: hero walked toward the destination (x " as *u8); gn(hx0); gw("->" as *u8); gn(st[0]); gw(")\n" as *u8)
35
36 // ---- T2: combat ----
37 init_impl(base)
38 let g0: i64 = st[4]
39 t=0; while t < 500 { if ma[0] == 0 { t = 500 } else { click_impl(base, mx[0], my[0]); tick_impl(base, 0); t=t+1 } }
40 var t2ok: i64=1; if ma[0] != 0 {t2ok=0} if st[4] < g0 + 5 {t2ok=0}
41 total=total+1; if t2ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
42 gw("T2 combat: chased + slew a foe (alive=" as *u8); gn(ma[0]); gw(", gold+=" as *u8); gn(st[4]-g0); gw(")\n" as *u8)
43
44 // ---- T3: loot ----
45 init_impl(base)
46 t=0; while t < 500 { if st[10] == 1 { t = 500 } else { click_impl(base, st[8], st[9]); tick_impl(base, 0); t=t+1 } }
47 var t3ok: i64=1; if st[10] != 1 {t3ok=0}
48 total=total+1; if t3ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
49 gw("T3 loot: walked onto the gold and grabbed it (taken=" as *u8); gn(st[10]); gw(", gold=" as *u8); gn(st[4]); gw(")\n" as *u8)
50
51 // ---- render + lighting (capture a combat frame right after a strike: walk pose + attack FX visible) ----
52 init_impl(base)
53 t=0; while t < 300 { click_impl(base, mx[2], my[2]); tick_impl(base, 0); if st[11] > 3 { t = 300 } else { t = t + 1 } }
54 render_impl(base)
55 let fb: *i64 = (base + O_FB) as *i64
56 write_png(fb, W, H, "knowledge/nx_wasm_diablo_native.png" as *u8)
57 gw(" (live evidence: PNG knowledge/nx_wasm_diablo_native.png -- iso dungeon, hero, foes, torch-follow lighting)\n" as *u8)
58
59 // ---- T4: render + lighting ----
60 let hero: i64 = lum(fb[(st[1]-28)*W + st[0]])
61 let corner: i64 = lum(fb[(H-10)*W + 8])
62 var t4ok: i64=1; if hero <= corner + 100 {t4ok=0}
63 total=total+1; if t4ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
64 gw("T4 render+lighting: hero lit by the torch (lum=" as *u8); gn(hero); gw(") vs far gloom (lum=" as *u8); gn(corner); gw(")\n" as *u8)
65
66 gw("\n=== nx_wasm_diablo_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
67 if pass == total { gw(" GREEN (a playable isometric ARPG with click-move + combat + loot + torch-follow lighting)\n" as *u8); sys_exit(0); return 0 }
68 gw(" RED\n" as *u8); sys_exit(1); return 1
69}