<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Boomerang Fu - 3D Local Arena</title>
<style>
*{box-sizing:border-box}
html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#9bcfc8;font-family:Arial,sans-serif}
#game{position:fixed;inset:0}
canvas{display:block}
#hud{position:fixed;inset:0;pointer-events:none;color:white;text-shadow:0 2px 5px #203b32}
#title{position:absolute;top:17px;left:20px;font-size:23px;font-weight:1000;letter-spacing:3px}
#title small{display:block;font-size:9px;letter-spacing:2px;margin-top:4px}
#message{position:absolute;top:17px;left:50%;transform:translateX(-50%);background:#173d34df;border:1px solid #ffffff55;border-radius:10px;padding:10px 18px;font-size:12px;font-weight:bold;white-space:nowrap}
#scoreboard{position:absolute;bottom:14px;left:50%;transform:translateX(-50%);display:flex;gap:8px;justify-content:center;flex-wrap:wrap;width:96%}
.score{background:#173d34dd;border:1px solid #ffffff55;border-radius:8px;padding:8px 12px;font-size:11px;min-width:115px}
.score b{display:block;font-size:12px;margin-bottom:4px}
#menu{position:fixed;inset:0;z-index:5;background:#173c35eF;display:flex;align-items:center;justify-content:center;padding:12px;color:#26382f}
.panel{width:min(900px,96vw);max-height:95vh;overflow:auto;background:#f5eedc;border:5px solid #d6b978;border-radius:20px;padding:22px;box-shadow:0 18px 55px #14251e99}
h1{text-align:center;margin:0;font-size:34px;letter-spacing:3px}
.panel>p{text-align:center;margin:8px 0 18px}
#playerPicks{display:flex;justify-content:center;gap:8px;flex-wrap:wrap;margin:15px 0}
.playerPick{border:2px solid #cbbd9d;border-radius:9px;padding:9px 15px;background:#fffaf0;color:#293b31;font-weight:bold;cursor:pointer}
.playerPick.active{border:3px solid #e8ad45;background:#fff0c7}
#roster{display:grid;grid-template-columns:repeat(4,1fr);gap:9px}
.food{border:2px solid #d1c5a9;border-radius:12px;background:#fffaf0;padding:10px 4px;min-height:65px;cursor:pointer;color:#293b31;font-weight:bold}
.food.active{border:4px solid #e8ad45;background:#fff0c7}
.food .swatch{width:24px;height:24px;border-radius:50%;margin:0 auto 6px;border:2px solid #0002}
.food small{display:block;font-weight:normal;font-size:10px;margin-top:4px}
.food:disabled{opacity:.4;cursor:default}
#start{display:block;margin:18px auto 0;border:0;border-radius:12px;padding:14px 42px;background:#e5a83f;color:#26382f;font-size:18px;font-weight:900;cursor:pointer}
#start:hover{background:#f4c86d}
#help{text-align:center;font-size:11px;line-height:1.7;margin-top:13px}
#menuButton{position:fixed;right:14px;top:14px;z-index:4;pointer-events:auto;border:0;border-radius:8px;background:#173d34;color:white;padding:10px 14px;font-weight:bold;cursor:pointer}
@media(max-width:600px){#roster{grid-template-columns:repeat(3,1fr)}h1{font-size:25px}.panel{padding:13px}#message{top:65px;font-size:10px}#title{font-size:18px}}
</style>
</head>
<body>
<div id="game"></div>
<div id="hud">
<div id="title">BOOMERANG FU<small>LOCAL FOOD FIGHT</small></div>
<div id="message">CHOOSE YOUR FIGHTERS</div>
<div id="scoreboard"></div>
</div>
<button id="menuButton">MENU</button>
<div id="menu">
<div class="panel">
<h1>BOOMERANG FU</h1>
<p>Choose a character for each player.</p>
<div id="playerPicks"></div>
<div id="roster"></div>
<div id="help">
PLAYER 1: W A S D + SPACE<br>
PLAYER 2: ARROW KEYS + ENTER<br>
PLAYER 3: I J K L + U<br>
PLAYER 4: T F G H + R<br>
Move to aim. Throw your boomerang to knock out opponents.
</div>
<button id="start">START GAME</button>
</div>
</div>
<script type="module">
import * as THREE from 'https://esm.sh/three@0.160.0';
const $=id=>document.getElementById(id);
const scene=new THREE.Scene();
scene.background=new THREE.Color(0x9bcfc8);
scene.fog=new THREE.Fog(0x9bcfc8,27,49);
const camera=new THREE.PerspectiveCamera(40,innerWidth/innerHeight,.1,100);
camera.position.set(0,23,24);
camera.lookAt(0,0,0);
const renderer=new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.setSize(innerWidth,innerHeight);
renderer.shadowMap.enabled=true;
renderer.shadowMap.type=THREE.PCFSoftShadowMap;
renderer.outputColorSpace=THREE.SRGBColorSpace;
renderer.toneMapping=THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure=1.12;
$('game').appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xf4ffff,0x48644d,2.1));
const sun=new THREE.DirectionalLight(0xfff4d9,3.1);
sun.position.set(-8,16,10);
sun.castShadow=true;
sun.shadow.mapSize.set(2048,2048);
sun.shadow.camera.left=-17;
sun.shadow.camera.right=17;
sun.shadow.camera.top=17;
sun.shadow.camera.bottom=-17;
scene.add(sun);
const mat=(c,r=.43,m=0)=>new THREE.MeshStandardMaterial({color:c,roughness:r,metalness:m});
const M={
outline:mat(0x55453e),white:mat(0xfff6e7),black:mat(0x282326,.25),
pink:mat(0xf29a9e),leaf:mat(0x39964d),green:mat(0x62a94f),
cream:mat(0xf5e5c7),brown:mat(0x96603c),gold:mat(0xe8b944)
};
function mesh(parent,geo,material,x=0,y=0,z=0){
const o=new THREE.Mesh(geo,material);
o.position.set(x,y,z);o.castShadow=true;o.receiveShadow=true;
parent.add(o);return o;
}
function sphere(parent,x,y,z,sx,sy,sz,material){
const o=mesh(parent,new THREE.SphereGeometry(1,32,24),material,x,y,z);
o.scale.set(sx,sy,sz);return o;
}
function box(parent,w,h,d,material,x,y,z,r=.08){
const geo=new THREE.BoxGeometry(w,h,d,4,4,2);
const o=mesh(parent,geo,material,x,y,z);
return o;
}
function cylinder(parent,rt,rb,h,material,x,y,z,segments=32){
return mesh(parent,new THREE.CylinderGeometry(rt,rb,h,segments),material,x,y,z);
}
function group(parent,x=0,y=0,z=0){
const g=new THREE.Group();g.position.set(x,y,z);parent.add(g);return g;
}
function extruded(parent,points,depth,material,x=0,y=0,z=0,bevel=.08){
const s=new THREE.Shape();
s.moveTo(points[0][0],points[0][1]);
for(let i=1;i<points.length;i++)s.lineTo(points[i][0],points[i][1]);
s.closePath();
const geo=new THREE.ExtrudeGeometry(s,{
depth,bevelEnabled:true,bevelSegments:4,steps:1,
bevelSize:bevel,bevelThickness:bevel,curveSegments:12
});
geo.translate(0,0,-depth/2);
return mesh(parent,geo,material,x,y,z);
}
function tube(parent,pts,r,material){
const curve=new THREE.CatmullRomCurve3(pts.map(p=>new THREE.Vector3(...p)));
return mesh(parent,new THREE.TubeGeometry(curve,32,r,10,false),material);
}
function torus(parent,r,t,material,x,y,z){
return mesh(parent,new THREE.TorusGeometry(r,t,12,48),material,x,y,z);
}
// Arena
const arena=group(scene);
cylinder(arena,12.7,13,.7,mat(0x328d60),0,-.45,0,64);
cylinder(arena,10.8,10.8,.12,mat(0xd8c38e),0,-.035,0,64);
const rim=torus(arena,12.55,.2,mat(0x205c45),0,-.02,0);
rim.rotation.x=Math.PI/2;
for(let i=0;i<20;i++){
const a=i/20*Math.PI*2,x=Math.cos(a)*11.9,z=Math.sin(a)*11.9;
const tree=group(arena,x,0,z);
cylinder(tree,.13,.2,1.8,mat(0x91613b),0,.9,0,12);
for(let j=0;j<5;j++){
const leaf=sphere(tree,Math.cos(j*1.25)*.45,1.85,
Math.sin(j*1.25)*.45,.16,.09,.7,M.leaf);
leaf.rotation.y=j*1.25;
}
}
for(const [x,z,r] of [[-7,-2,.2],[7,2,-.3],[-2,7,.5],[3,-7,.2]]){
const c=box(arena,.9,.7,.9,mat(0x96613b),x,.36,z);c.rotation.y=r;
box(arena,.7,.12,.95,mat(0xb17a4c),x,.41,z);
}
for(let i=0;i<18;i++){
const a=i*2.4;
sphere(arena,Math.sin(a)*9,.08,Math.cos(a)*9,.22,.12,.18,
mat(i%2?0x4a9d5c:0x6eaa58));
}
// Character roster
const foods=[
{name:'Milk',color:0xf5f0df,type:'milk'},
{name:'Coffee',color:0x9a5937,type:'coffee'},
{name:'Carrot',color:0xef8424,type:'carrot'},
{name:'Bacon',color:0xc45b55,type:'bacon'},
{name:'Avocado',color:0x75a84b,type:'avocado'},
{name:'Eggplant',color:0x69427d,type:'eggplant'},
{name:'Ice Cream',color:0xf1aebc,type:'ice'},
{name:'Sushi',color:0xf2e6d4,type:'sushi'},
{name:'Watermelon',color:0x319b5b,type:'watermelon'},
{name:'Donut',color:0xc88b57,type:'donut'},
{name:'Bread',color:0xc88d50,type:'bread'},
{name:'Banana',color:0xf3d13d,type:'banana'}
];
const playerColors=[0xf5a623,0x55c7e8,0xec668b,0x8cda79];
function face(g,z=.42,y=1.02,spacing=.19){
// Facial features are separate rounded 3D objects, not painted pixels.
for(const x of [-spacing,spacing]){
sphere(g,x,y,z,.047,.065,.035,M.black);
sphere(g,x-.012,y+.025,z+.027,.013,.018,.009,M.white);
}
tube(g,[[-.075,y-.13,z+.012],[0,y-.16,z+.025],[.075,y-.13,z+.012]],.018,M.outline);
sphere(g,-.31,y-.05,z,.065,.035,.025,M.pink);
sphere(g,.31,y-.05,z,.065,.035,.025,M.pink);
}
function limbs(g){
const armMat=mat(0x493a32);
for(const side of [-1,1]){
const arm=mesh(g,new THREE.CapsuleGeometry(.055,.23,5,10),armMat,side*.48,.77,0);
arm.rotation.z=side*.65;
sphere(g,side*.59,.64,.02,.09,.075,.08,mat(0xf0c9a4));
sphere(g,side*.25,.12,.04,.14,.09,.19,M.black);
}
}
function makeBody(g,type){
const outline=M.outline;
let front=.34,fy=1.02,spacing=.19;
switch(type){
case'milk':{
const body=group(g,0,1.02,0);
const shell=mesh(body,new THREE.BoxGeometry(.91,1.15,.58,3,4,2),
mat(0x62b9e9),0,0,0);
shell.material.color.set(0x6bbde9);
// Rounded shoulders and carton roof.
const roof=mesh(body,new THREE.CylinderGeometry(.02,.5,.27,4,1),mat(0xeaf8ff),0,.69,0);
roof.rotation.y=Math.PI/4;
box(body,.35,.17,.37,mat(0xeaf8ff),0,.83,0);
box(body,.7,.07,.59,mat(0xeaf8ff),0,.48,.01);
box(body,.57,.16,.04,mat(0xf6ffff),0,.02,.3);
body.position.y=1.03;front=.32;fy=1.04;break;
}
case'coffee':{
const cup=cylinder(g,.48,.36,1.05,mat(0xb77950),0,1.03,0,48);
cylinder(g,.49,.49,.11,mat(0xf3e8d4),0,1.59,0,48);
cylinder(g,.42,.42,.035,mat(0x49372e),0,1.66,0,48);
const sleeve=cylinder(g,.46,.42,.31,mat(0xd8c4a4),0,1.05,0,48);
tube(g,[[.18,1.35,.29],[.25,1.62,.31],[.25,1.85,.31]],.035,mat(0xf5f0df));
front=.44;fy=1.08;break;
}
case'carrot':{
const body=mesh(g,new THREE.ConeGeometry(.55,1.55,40,5),mat(0xf18a2c),0,1.03,0);
body.rotation.z=Math.PI;
sphere(g,0,1.75,0,.48,.12,.42,mat(0xe8a044));
for(let i=0;i<4;i++){
tube(g,[[-.27+i*.16,1.25,.36],[-.18+i*.16,1.19,.4],[-.1+i*.16,1.18,.37]],.018,mat(0xd7651e));
}
const leaves=group(g,0,1.85,0);
for(let i=0;i<5;i++){
const l=mesh(leaves,new THREE.ConeGeometry(.13,.55,12),M.leaf,
(i-2)*.13,.2,0);
l.rotation.z=(i-2)*-.45;
}
front=.4;fy=1.08;break;
}
case'bacon':{
const pts=[[-.48,.45],[-.52,.68],[-.32,.86],[-.48,1.1],
[-.3,1.32],[-.38,1.52],[-.12,1.62],[.08,1.47],
[.3,1.65],[.5,1.43],[.38,1.2],[.52,1.0],
[.34,.8],[.48,.57],[.22,.43],[0,.55],[-.22,.4]];
extruded(g,pts,.43,mat(0xe97870),0,0,0,.1);
tube(g,[[-.34,.62,.24],[-.2,.82,.25],[-.34,1.02,.25],
[-.16,1.2,.25],[-.23,1.42,.25],[0,1.5,.25],
[.18,1.37,.25],[.32,1.48,.25]],.055,mat(0xffc69e));
front=.29;fy=1.04;break;
}
case'avocado':{
const b=sphere(g,0,1.02,0,.65,.88,.42,mat(0x5b9c43));
sphere(g,0,1.04,.13,.54,.76,.34,mat(0x9acb68));
sphere(g,0,.72,.43,.25,.28,.13,mat(0x9a6038));
front=.48;fy=1.28;spacing=.2;break;
}
case'eggplant':{
const b=sphere(g,0,1.02,0,.57,.84,.43,mat(0x68417e));
b.rotation.z=-.18;
sphere(g,-.05,1.69,0,.25,.18,.25,mat(0x4b8d48));
for(let i=0;i<5;i++){
const leaf=mesh(g,new THREE.ConeGeometry(.13,.48,12),mat(0x3d9449),
(i-2)*.12,1.8,0);
leaf.rotation.z=(i-2)*-.35;
}
front=.43;fy=1.08;break;
}
case'ice':{
const cone=cylinder(g,.05,.36,.72,mat(0xc38a50),0,.43,0,32);
cone.rotation.z=Math.PI;
for(let i=0;i<4;i++){
tube(g,[[-.24+i*.13,.2,.23],[.24-i*.1,.58,.23]],.012,mat(0x8d603b));
}
sphere(g,0,1.12,0,.65,.62,.49,mat(0x6bd9c9));
sphere(g,-.32,1.08,.03,.3,.36,.35,mat(0x8ce8d7));
sphere(g,.32,1.08,.03,.3,.36,.35,mat(0x5bcaba));
front=.49;fy=1.15;break;
}
case'sushi':{
cylinder(g,.56,.56,.74,mat(0xf4ead7),0,.83,0,48);
cylinder(g,.58,.58,.13,mat(0x263d34),0,.48,0,48);
const salmon=sphere(g,0,1.3,.02,.57,.27,.47,mat(0xf18d77));
salmon.rotation.z=-.08;
sphere(g,-.18,1.36,.38,.09,.035,.035,mat(0xffd4ac));
sphere(g,.18,1.36,.38,.09,.035,.035,mat(0xffd4ac));
front=.43;fy=.96;break;
}
case'watermelon':{
const pts=[[-.7,-.45],[0,1.0],[.7,-.45]];
extruded(g,pts,.48,mat(0x319b5b),0,1.0,0,.08);
extruded(g,[[-.62,-.4],[0,.88],[.62,-.4]],.5,mat(0xf5e69a),0,1.0,.015,.035);
extruded(g,[[-.56,-.36],[0,.78],[.56,-.36]],.51,mat(0xf06c70),0,1.0,.03,.025);
for(const [x,y] of [[-.22,.22],[.13,.42],[.24,.04],[-.05,-.12]]){
sphere(g,x,1+y,.31,.025,.065,.018,M.black);
}
front=.32;fy=1.0;break;
}
case'donut':{
const d=torus(g,.47,.22,mat(0xc68a54),0,1.04,0);
d.rotation.x=0;
const icing=torus(g,.48,.15,mat(0xf18bb6),0,1.08,.04);
for(let i=0;i<10;i++){
const a=i*Math.PI/5;
sphere(g,Math.cos(a)*.51,1.08+Math.sin(a)*.51,.2,
.035,.06,.025,[mat(0x6fc7eb),mat(0xffe57d),mat(0x9a7bd0)][i%3]);
}
front=.45;fy=1.12;break;
}
case'bread':{
const pts=[[-.55,-.55],[-.55,.2],[-.5,.48],[-.3,.62],
[-.08,.56],[.12,.65],[.35,.57],[.53,.4],[.55,-.55]];
extruded(g,pts,.48,mat(0xa76d3d),0,1.03,0,.13);
const inner=extruded(g,[[-.43,-.47],[-.43,.2],[-.36,.42],
[-.2,.5],[-.04,.43],[.15,.51],[.34,.4],[.43,.23],[.43,-.47]],
.49,mat(0xf1d09a),0,1.03,.02,.09);
front=.34;fy=1.05;break;
}
case'banana':{
const curve=new THREE.CatmullRomCurve3([
new THREE.Vector3(-.62,.35,0),
new THREE.Vector3(-.55,.9,0),
new THREE.Vector3(-.05,1.53,0),
new THREE.Vector3(.55,1.45,0),
new THREE.Vector3(.65,1.02,0)
]);
mesh(g,new THREE.TubeGeometry(curve,48,.19,24,false),mat(0xf4d23c));
sphere(g,-.62,.35,0,.12,.15,.14,mat(0x79502d));
sphere(g,.65,1.02,0,.12,.15,.14,mat(0x79502d));
front=.2;fy=1.05;break;
}
}
face(g,front,fy,spacing);
limbs(g);
}
function makeCharacterModel(food){
const root=group(scene);
const body=group(root);
makeBody(body,food.type);
const shadow=mesh(root,new THREE.CircleGeometry(.63,40),
new THREE.MeshBasicMaterial({color:0x315747,transparent:true,opacity:.18}),0,.025,0);
shadow.rotation.x=-Math.PI/2;
const ring=mesh(root,new THREE.TorusGeometry(.66,.045,8,32),
mat(0xffffff),0,.055,0);
ring.rotation.x=Math.PI/2;
return {root,body,ring,shadow};
}
// Character selection UI
const roster=$('roster'),playerPicks=$('playerPicks');
const selected=[0,1,2,3];
let activePlayer=0;
function renderRoster(){
playerPicks.innerHTML='';
for(let p=0;p<4;p++){
const b=document.createElement('button');
b.className='playerPick'+(p===activePlayer?' active':'');
b.textContent='PLAYER '+(p+1)+': '+foods[selected[p]].name;
b.onclick=()=>{activePlayer=p;renderRoster()};
playerPicks.appendChild(b);
}
roster.innerHTML='';
foods.forEach((food,i)=>{
const b=document.createElement('button');
const owner=selected.indexOf(i),isCurrent=selected[activePlayer]===i;
b.className='food'+(isCurrent?' active':'');
b.disabled=owner>=0&&!isCurrent;
b.innerHTML=`<div class="swatch" style="background:#${food.color.toString(16).padStart(6,'0')}"></div>${food.name}<small>${isCurrent?'Selected for Player '+(activePlayer+1):owner>=0?'Player '+(owner+1):'Choose character'}</small>`;
b.onclick=()=>{
if(selected.some((v,p)=>p!==activePlayer&&v===i))return;
selected[activePlayer]=i;renderRoster();
};
roster.appendChild(b);
});
}
renderRoster();
// Gameplay
const controls=[
{up:'w',down:'s',left:'a',right:'d',throw:' '},
{up:'ArrowUp',down:'ArrowDown',left:'ArrowLeft',right:'ArrowRight',throw:'Enter'},
{up:'i',down:'k',left:'j',right:'l',throw:'u'},
{up:'t',down:'g',left:'f',right:'h',throw:'r'}
];
const spawn=[[-4.5,-4.5],[4.5,-4.5],[-4.5,4.5],[4.5,4.5]];
let players=[],boomerangs=[],keys={};
let playing=false,round=1,scores=[0,0,0,0],last=0;
function clearRound(){
for(const p of players)scene.remove(p.model.root);
for(const b of boomerangs)scene.remove(b.mesh);
players=[];boomerangs=[];
}
function makePlayer(i){
const model=makeCharacterModel(foods[selected[i]]);
model.ring.material=mat(playerColors[i]);
model.root.position.set(spawn[i][0],0,spawn[i][1]);
return {id:i,model,x:spawn[i][0],z:spawn[i][1],
angle:0,alive:true,speed:5.4,cooldown:0,boomerang:null,
controls:controls[i],color:playerColors[i]};
}
function updateScore(){
$('scoreboard').innerHTML=players.map(p=>
`<div class="score"><b style="color:#${p.color.toString(16).padStart(6,'0')}">PLAYER ${p.id+1}</b>${p.alive?'FIGHTING':'KNOCKED OUT'}<br>WINS: ${scores[p.id]}</div>`
).join('');
}
function startRound(){
clearRound();players=[0,1,2,3].map(makePlayer);
playing=true;$('message').textContent='ROUND '+round+' — FIGHT!';
updateScore();
}
function startGame(){
scores=[0,0,0,0];round=1;
startRound();$('menu').style.display='none';
}
function showMenu(){
playing=false;clearRound();$('menu').style.display='flex';
$('message').textContent='CHOOSE YOUR FIGHTERS';
}
$('start').onclick=startGame;
$('menuButton').onclick=showMenu;
function throwBoomerang(p){
if(!playing||!p.alive||p.cooldown>0||p.boomerang)return;
p.cooldown=.55;
const mesh=meshBoomerang(p);
const b={mesh,owner:p,angle:p.angle,distance:0,returning:false,hit:new Set()};
p.boomerang=b;boomerangs.push(b);
}
function meshBoomerang(p){
const g=new THREE.Group();
const blade=mesh(g,new THREE.TorusGeometry(.29,.085,10,28),
mat(p.color,.25),0,0,0);
blade.rotation.x=Math.PI/2;
const center=mesh(g,new THREE.SphereGeometry(.11,16,12),mat(0xfff0c5));
g.position.set(p.x,1,p.z);scene.add(g);return g;
}
function eliminate(p,killer){
if(!p.alive)return;
p.alive=false;scene.remove(p.model.root);
if(killer)scores[killer.id]++;
$('message').textContent=killer?
`PLAYER ${killer.id+1} KNOCKED OUT PLAYER ${p.id+1}!`:'PLAYER ELIMINATED';
updateScore();
const living=players.filter(x=>x.alive);
if(living.length<=1){
if(living.length===1)scores[living[0].id]++;
updateScore();playing=false;
$('message').textContent=living.length?
`PLAYER ${living[0].id+1} WINS ROUND ${round}!`:'DRAW!';
setTimeout(()=>{
if($('menu').style.display!=='none')return;
if(round>=5){
$('message').textContent='MATCH COMPLETE!';
setTimeout(showMenu,1400);
}else{round++;startRound()}
},1500);
}
}
function updatePlayers(dt,t){
for(const p of players){
if(!p.alive)continue;
const c=p.controls;let dx=0,dz=0;
if(keys[c.left])dx--;
if(keys[c.right])dx++;
if(keys[c.up])dz--;
if(keys[c.down])dz++;
const len=Math.hypot(dx,dz);
if(len){dx/=len;dz/=len;p.angle=Math.atan2(dx,dz)}
p.x+=dx*p.speed*dt;p.z+=dz*p.speed*dt;
const dist=Math.hypot(p.x,p.z);
if(dist>10.25){p.x=p.x/dist*10.25;p.z=p.z/dist*10.25}
p.model.root.position.set(p.x,Math.abs(Math.sin(t*.008+p.id*1.7))*.045,p.z);
p.model.body.rotation.y=Math.atan2(dx,dz)*.12;
p.model.body.position.y= Math.sin(t*.008+p.id*1.7)*.035;
p.cooldown=Math.max(0,p.cooldown-dt);
}
}
function updateBoomerangs(dt){
for(let i=boomerangs.length-1;i>=0;i--){
const b=boomerangs[i],p=b.owner;
if(!p.alive){
scene.remove(b.mesh);boomerangs.splice(i,1);p.boomerang=null;continue;
}
b.mesh.rotation.y+=dt*13;
if(!b.returning){
b.mesh.position.x+=Math.sin(b.angle)*12*dt;
b.mesh.position.z+=Math.cos(b.angle)*12*dt;
b.distance+=12*dt;
if(b.distance>7.8)b.returning=true;
for(const target of players){
if(!target.alive||target===p||b.hit.has(target))continue;
const d=Math.hypot(target.x-b.mesh.position.x,target.z-b.mesh.position.z);
if(d<.85){b.hit.add(target);eliminate(target,p)}
}
}else{
const dx=p.x-b.mesh.position.x,dz=p.z-b.mesh.position.z,d=Math.hypot(dx,dz);
if(d<.7){
scene.remove(b.mesh);boomerangs.splice(i,1);p.boomerang=null;continue;
}
b.mesh.position.x+=dx/d*12*dt;
b.mesh.position.z+=dz/d*12*dt;
}
}
}
window.addEventListener('keydown',e=>{
keys[e.key]=true;keys[e.key.toLowerCase()]=true;
if([' ','ArrowUp','ArrowDown','ArrowLeft','ArrowRight'].includes(e.key))e.preventDefault();
if(!playing)return;
players.forEach(p=>{if(e.key===p.controls.throw)throwBoomerang(p)});
});
window.addEventListener('keyup',e=>{
keys[e.key]=false;keys[e.key.toLowerCase()]=false;
});
function animate(t){
requestAnimationFrame(animate);
const dt=Math.min((t-last)/1000||0,.035);last=t;
if(playing){updatePlayers(dt,t);updateBoomerangs(dt)}
renderer.render(scene,camera);
}
animate(0);
window.addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight;
camera.updateProjectionMatrix();renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>