Files
ploxion-doomion/app.blade.php

87 lines
7.6 KiB
PHP

{{-- PL0XION doomion 😈 — DOOM NATIF : cœur de jeu WASM (Rust) + rendu 3D sur le MOTEUR jOSEngine
(au-dessus de jOS3D/Three.js). (rs-4). La simulation (joueur/ennemis/collision/IA/tir) est dans
public/bions/doom_core.wasm (5 Ko, Rust no_std) ; TOUT le reste (input, murs, sprites, caméra FPS,
boucle, HUD) vient de jOSEngine = le moteur réutilisable du xerboxion. Zéro émulateur. --}}
<style>
.dio{display:flex;flex-direction:column;height:100%;background:#000;color:#cdd0e0;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
.dio__stage{flex:1;min-height:0;position:relative}
.dio__stage canvas{width:100%;height:100%;display:block;cursor:crosshair}
.dio__cross{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);color:rgba(255,255,255,.6);font:1rem ui-monospace;pointer-events:none}
.dio__flash{position:absolute;left:50%;bottom:6%;transform:translateX(-50%);width:70px;height:34px;background:radial-gradient(circle,rgba(255,220,120,.9),transparent 70%);opacity:0;pointer-events:none}
.dio__over{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;background:rgba(0,0,0,.72);cursor:pointer;text-align:center;padding:18px;z-index:3}
.dio__over h3{color:#e33;font:900 1.5rem ui-sans-serif;margin:0} .dio__over p{color:#9aa;font-size:.76rem;max-width:340px}
.dio__over .go{background:#e33;color:#fff;border:0;border-radius:9px;padding:9px 18px;font:800 .85rem ui-sans-serif;cursor:pointer}
</style>
<script>
(function () {
'use strict';
var WASM = '/bions/doom_core.wasm';
var MAP = ['1111111111111111', '1000000000000001', '1011110011110101', '1010000000010101', '1010111110010001', '1010100010011101', '1000100010000101', '1110111011110101', '1000001000000001', '1011101011111101', '1010001010000001', '1010111010111011', '1010000000100001', '1011111110101101', '1000000000000001', '1111111111111111'];
var LIVE = null; // posé au mount : { wasm, playing }
function describe() {
var wasm = LIVE ? LIVE.wasm() : null, playing = LIVE ? LIVE.playing() : false;
if (!wasm || !playing) return { v: 1, id: 'doomion', title: 'Doomion', icon: '😈', items: [{ p: 1, kind: 'text', label: 'doomion', value: 'DOOM natif WASM + jOSEngine' }] };
return { v: 1, id: 'doomion', title: 'Doomion', icon: '😈', items: [
{ p: 1, kind: 'stat', label: '❤ vie', value: wasm.hp() | 0 },
{ p: 2, kind: 'stat', label: '☠ kills', value: wasm.kills() }
] };
}
function mount(container) {
container.innerHTML = '<div class="dio"><div class="dio__stage"><canvas></canvas>'
+ '<div class="dio__cross">+</div><div class="dio__flash" data-flash></div>'
+ '<div class="dio__over" data-over><h3>😈 DOOMION</h3><p>Cœur <b>WASM natif</b> (Rust) + moteur <b>jOSEngine</b> (jOS3D/WebGL). WASD = bouger/strafe · flèches/souris = tourner · Espace/clic = tirer.</p><button class="go">▶ entrer</button></div></div></div>';
var cv = container.querySelector('canvas'), over = container.querySelector('[data-over]'), flashEl = container.querySelector('[data-flash]');
if (!window.jOSEngine) { over.querySelector('p').textContent = 'jOSEngine absent.'; return { unmount: function () { container.innerHTML = ''; } }; }
var wasm = null, sprites = [], playing = false, flash = 0, dead = false;
LIVE = { wasm: function () { return wasm; }, playing: function () { return playing; } };
var eng = jOSEngine.create(cv, { ground: false, grid: false, fog: true, bg: 0x000000, dist: 6, onReady: build });
eng.loadWasm(WASM).then(function (ex) { if (dead) return; wasm = ex; wasm.init(); }).catch(function () { over.querySelector('p').textContent = 'doom_core.wasm non chargé.'; });
function build(e) {
e.gridWalls(MAP, { wall: 0x6a5050, floorColor: 0x161009, ceilColor: 0x0a0d16, height: 1 });
var tex = e.canvasTexture(function (g, s) {
g.fillStyle = '#8a1010'; g.beginPath(); g.arc(32, 34, 26, 0, 6.28); g.fill();
g.fillStyle = '#ffcf3a'; g.beginPath(); g.arc(24, 28, 6, 0, 6.28); g.arc(40, 28, 6, 0, 6.28); g.fill();
g.fillStyle = '#200'; g.beginPath(); g.arc(24, 29, 2.5, 0, 6.28); g.arc(40, 29, 2.5, 0, 6.28); g.fill();
g.strokeStyle = '#200'; g.lineWidth = 3; g.beginPath(); g.moveTo(20, 46); g.lineTo(28, 42); g.lineTo(36, 46); g.lineTo(44, 42); g.stroke();
g.fillStyle = '#6a0'; g.beginPath(); g.moveTo(10, 14); g.lineTo(18, 6); g.lineTo(20, 18); g.fill(); g.beginPath(); g.moveTo(54, 14); g.lineTo(46, 6); g.lineTo(44, 18); g.fill();
}, 64);
for (var i = 0; i < 5; i++) sprites.push(e.billboard(tex, { scale: 0.9 }));
}
// caméra FPS pilotée par l'état WASM
eng.fps(function () { return wasm ? { x: wasm.px(), y: wasm.py(), dx: wasm.dx(), dy: wasm.dy(), eye: 0.55 } : null; });
// boucle de jeu : input → WASM → sprites + HUD
eng.onUpdate(function (dt, e) {
if (!wasm || !playing) return; var k = e.input.keys;
var turn = ((k.arrowright ? 1 : 0) - (k.arrowleft ? 1 : 0)) * 2.4 * dt + e.input.mdx * 0.0032;
var gp = e.input.gamepad(); if (gp) { turn += (gp.axes[2] || 0) * 2.4 * dt; }
var kb = (k.w || k.arrowup ? 1 : 0) | (k.s || k.arrowdown ? 2 : 0) | (k.a ? 4 : 0) | (k.d ? 8 : 0) | (k.shift ? 16 : 0);
if (gp) { if ((gp.axes[1] || 0) < -.3) kb |= 1; if ((gp.axes[1] || 0) > .3) kb |= 2; if ((gp.axes[0] || 0) < -.3) kb |= 4; if ((gp.axes[0] || 0) > .3) kb |= 8; }
wasm.step(dt, kb, Math.cos(-turn), Math.sin(-turn));
for (var i = 0; i < sprites.length; i++) { var al = wasm.ea(i); sprites[i].visible = !!al; if (al) sprites[i].position.set(wasm.ex(i), 0.5, wasm.ey(i)); }
if (flash > 0) { flashEl.style.opacity = flash; flash -= dt * 5; } else flashEl.style.opacity = 0;
e.hud('❤ ' + (wasm.hp() | 0) + '&nbsp;&nbsp; ▮ ' + wasm.ammo() + '&nbsp;&nbsp; ☠ ' + wasm.kills());
});
function shoot() { if (!wasm || !playing) return; var r = wasm.shoot(); flash = 1;
try { beep(r > 0 ? 320 : 180, .06); if (r === 1) beep(90, .18); } catch (e) {}
try { window.jOSPorts && jOSPorts.emit('doomion', 'shoot', { hit: r }); } catch (e) {} }
function beep(f, d) { try { var ac = beep._ac || (beep._ac = new (window.AudioContext || window.webkitAudioContext)()); var o = ac.createOscillator(), gn = ac.createGain(); o.type = 'square'; o.frequency.value = f; gn.gain.setValueAtTime(.12, ac.currentTime); gn.gain.exponentialRampToValueAtTime(.001, ac.currentTime + d); o.connect(gn).connect(ac.destination); o.start(); o.stop(ac.currentTime + d); } catch (e) {} }
cv.addEventListener('click', function () { if (playing) { shoot(); if (!eng.input.locked) eng.input.lock(); } });
document.addEventListener('keydown', function (e) { if (playing && (e.key === ' ')) { e.preventDefault(); shoot(); } }, true);
over.addEventListener('click', function () { if (!wasm) { over.querySelector('p').textContent = 'WASM pas encore prêt…'; return; } playing = true; over.style.display = 'none'; eng.input.lock();
try { (window.__tsoinMark || (window.jOSTsoin && window.jOSTsoin.mark))('doomion', 'doom natif wasm + jOSEngine'); } catch (e) {} });
return { unmount: function () { LIVE = null; dead = true; try { eng.dispose(); } catch (e) {} container.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['doomion'] = { manifest: { id: 'doomion', name: 'Doomion', icon: '😈' }, mount: mount, describe: describe };
})();
</script>