code wiki / _hdl_build / nx_creature_demo.nx

nx_creature_demo.nx source

↩ module page · 101 lines · 4856 B

1// nx_creature_demo.nx -- EMITS a real companion-game screen: a party of UNIQUE creatures (each rolled 2// from nx_game_companion traits, rendered by nx_creature_render) on a rich background, each on a card with 3// its name/type/level + an HP bar (mechanics VISIBLE). Writes a PNG and SCORES it with the hardened critic 4// so the emission's richness is MEASURED against the palette gap (my old games 220 vs real games 766-3336). 5// This is the horse: get rich graphics + mechanics emitting first. license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_game_companion.nx" 8import "nx_creature_render.nx" 9import "nx_game_art.nx" 10import "nx_game_critic.nx" 11import "nx_gamehud.nx" 12import "nx_png_write.nx" 13const K_MAGIC_20260721: i64 = 20260721 14 15const FW: i64 = 480 16const FH: i64 = 300 17 18func ww(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func wn(v: i64) -> i64 { 20 if v==0 { sys_write(1,"0" as *u8,1); return 0 } 21 var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } 22 let t: *u8=sys_mmap(32); var k: i64=0 23 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 24 let o: *u8=sys_mmap(32); var q: i64=k-1; var i: i64=0 25 while q>=0 { o[i]=t[q]; i=i+1; q=q-1 } 26 sys_write(1,o,i); return 0 27} 28func spec_name(s: i64) -> *u8 { 29 if s==0 { return "Ember" as *u8 } 30 if s==1 { return "Tide" as *u8 } 31 if s==2 { return "Bramble" as *u8 } 32 if s==3 { return "Volt" as *u8 } 33 if s==4 { return "Mystic" as *u8 } 34 return "Crag" as *u8 35} 36func png_emit(fb: *i64, path: *u8) -> i64 { 37 let rgb: *u8 = sys_mmap(FW*FH*3) 38 var p: i64=0 39 let n: i64=FW*FH 40 while p<n { let v: i64=fb[p]; rgb[p*3]=(v & 0xff) as u8; rgb[p*3+1]=((v>>8) & 0xff) as u8; rgb[p*3+2]=((v>>16) & 0xff) as u8; p=p+1 } 41 return nx_png_write_rgb(path, rgb, FW, FH) 42} 43 44func main() -> i64 { 45 let SEED: i64 = K_MAGIC_20260721 46 let font: *u8 = font8x8_table() 47 let fb: *i64 = sys_mmap(FW*FH*8) as *i64 48 // rich background 49 art_nebula(fb, FW, FH, 10, 8, 26, 40, 20, 62) 50 art_stardust(fb, FW, FH, 180) 51 // title bar 52 gr_rect(fb, FW, FH, 0, 0, FW-1, 22, gr_pack(16,14,34)) 53 gh_text(fb, FW, FH, font, 10, 7, "NISHI FRONTIER -- your companions" as *u8) 54 55 // a party of 6 UNIQUE creatures, each invested differently (levels vary = the rpgstats mechanic) 56 let ros: *i64 = sys_mmap(en_words(16, COMP_NC)*8) as *i64 57 comp_new_roster(ros, 16, 6, SEED, 1) 58 var i: i64 = 0 59 while i < 6 { 60 let hnd: i64 = en_nth(ros, i) 61 comp_invest(ros, hnd, i*i*40) // 0,40,160,360,640,1000 xp -> varied levels 62 let col: i64 = i % 3 63 let row: i64 = i / 3 64 let cardx: i64 = 12 + col*156 65 let cardy: i64 = 32 + row*132 66 // card 67 gr_rect(fb, FW, FH, cardx, cardy, cardx+146, cardy+122, gr_pack(20,18,40)) 68 gr_rect(fb, FW, FH, cardx, cardy, cardx+146, cardy+2, gr_pack(60,54,100)) 69 // creature 70 let sp: i64 = en_get(ros, hnd, C_SPEC) 71 cr_creature(fb, FW, FH, cardx+73, cardy+58, 40, 72 sp, en_get(ros,hnd,C_IV0), en_get(ros,hnd,C_IV1), en_get(ros,hnd,C_IV2), en_get(ros,hnd,C_IV3)) 73 // nameplate on a SOLID strip so 8px text reads over the busy art (fixes the garble) 74 gr_rect(fb, FW, FH, cardx+4, cardy+99, cardx+142, cardy+111, gr_pack(9,8,20)) 75 var tx: i64 = gh_text(fb, FW, FH, font, cardx+8, cardy+102, spec_name(sp)) 76 tx = gh_text(fb, FW, FH, font, tx+5, cardy+102, "Lv" as *u8) 77 gh_numdraw(fb, FW, FH, font, tx+2, cardy+102, en_get(ros,hnd,C_LVL)) 78 // HP bar (power from IVs+level) 79 let pw: i64 = comp_power(ros, hnd) 80 var bar: i64 = pw*130/120 81 if bar>130 { bar=130 } 82 gr_rect(fb, FW, FH, cardx+8, cardy+114, cardx+138, cardy+119, gr_pack(26,24,44)) 83 gr_rect(fb, FW, FH, cardx+8, cardy+114, cardx+8+bar, cardy+119, gr_pack(90,220,140)) 84 i = i + 1 85 } 86 87 png_emit(fb, "knowledge/nx_creature_party.png" as *u8) 88 89 // MEASURE the emission richness with the hardened critic 90 let m: *i64 = sys_mmap(GC_N*8) as *i64 91 gc_score(fb, FW, FH, m) 92 let q: i64 = gc_quality(m) 93 ww("=== nx_creature_demo: EMITTED a 6-companion party screen ===\n") 94 ww(" frame knowledge/nx_creature_party.png ("); wn(FW); ww("x"); wn(FH); ww(")\n") 95 ww(" critic pal/det1/det4/grad/coh/cov = "); wn(m[0]); ww("/"); wn(m[1]); ww("/"); wn(m[2]); ww("/"); wn(m[3]); ww("/"); wn(m[5]); ww("/"); wn(m[4]) 96 ww(" -> quality "); wn(q); ww(" = "); ww(gc_verdict(q)); ww("\n") 97 ww(" (palette was the #1 gap: old games ~220, real games 766-3336. This screen's palette = "); wn(m[0]); ww(")\n") 98 if q >= GC_RICH { ww("=== EMISSION RICH+ (beats my old games; re-run groundtruth vs Veloren) ===\n"); return 0 } 99 ww("=== EMISSION "); ww(gc_verdict(q)); ww(" -- keep enriching\n") 100 return 0 101}