'use strict'; if(!window.THREE){window.__no3d=true;__bootMsg('The 3D engine did not load. Check the internet connection and reload.');} /* ================= AUDIO (iPhone-safe, scheduled ahead, voice-limited) ================= */ let AC=null,silentEl=null,master=null,musicGain=null,sfxGain=null,muted=false,voices=0; function iosUnlock(){ try{if(navigator.audioSession&&navigator.audioSession.type!=='playback')navigator.audioSession.type='playback';}catch(e){} if(!('audioSession' in navigator)){try{if(!silentEl){silentEl=new Audio('audio/silence.mp3');silentEl.loop=true;silentEl.setAttribute('playsinline','');}const p=silentEl.play();if(p&&p.catch)p.catch(()=>{});}catch(e){}} } function wake(){iosUnlock();if(AC&&AC.state!=='running'){try{const p=AC.resume();if(p&&p.catch)p.catch(()=>{});}catch(e){}}} ['pointerdown','touchend','click','keydown'].forEach(ev=>document.addEventListener(ev,wake,{passive:true,capture:true})); document.addEventListener('visibilitychange',()=>{if(!document.hidden)wake();}); // Home Screen app (iOS standalone): wake sound when the app comes back, block pinch and double-tap zoom. addEventListener('pageshow',wake);addEventListener('focus',wake); ['gesturestart','gesturechange','gestureend','dblclick'].forEach(ev=>document.addEventListener(ev,e=>e.preventDefault(),{passive:false})); document.addEventListener('touchmove',e=>{if(e.touches.length>1)e.preventDefault();},{passive:false}); function initAudio(){ iosUnlock(); if(AC){wake();return;} try{AC=new(window.AudioContext||window.webkitAudioContext)();try{AC.resume();}catch(e){}}catch(e){AC=null;return;} master=AC.createGain();master.gain.value=muted?0:0.9; const comp=AC.createDynamicsCompressor();master.connect(comp);comp.connect(AC.destination); musicGain=AC.createGain();musicGain.gain.value=0.22;musicGain.connect(master); sfxGain=AC.createGain();sfxGain.gain.value=0.8;sfxGain.connect(master); startMusic(); } window.__audio=()=>AC; function tone(f,t0,dur,type,vol,dest,f2){ if(!AC||voices>14)return;voices++; const o=AC.createOscillator(),g=AC.createGain();o.type=type||'sine';o.frequency.setValueAtTime(f,t0); if(f2)o.frequency.exponentialRampToValueAtTime(f2,t0+dur); g.gain.setValueAtTime(0.0001,t0);g.gain.exponentialRampToValueAtTime(vol||0.3,t0+0.015);g.gain.exponentialRampToValueAtTime(0.0001,t0+dur); o.connect(g);g.connect(dest||sfxGain);o.start(t0);o.stop(t0+dur+0.05);o.onended=()=>{voices--;}; } let noiseBuf=null; function noise(t0,dur,vol,freq,q){ if(!AC||voices>14)return;voices++; if(!noiseBuf){noiseBuf=AC.createBuffer(1,AC.sampleRate,AC.sampleRate);const d=noiseBuf.getChannelData(0);for(let i=0;i{voices--;}; } const SFX={ bark(){if(!AC)return;const t=AC.currentTime;tone(540,t,0.09,'square',0.16,null,300);noise(t,0.08,0.18,900,1);tone(580,t+0.17,0.09,'square',0.14,null,320);noise(t+0.17,0.08,0.16,900,1);}, pew(){if(!AC)return;const t=AC.currentTime;tone(900,t,0.09,'square',0.06,null,300);}, peek(){if(!AC)return;const t=AC.currentTime;[880,1100,880].forEach((f,i)=>tone(f,t+i*0.09,0.08,'triangle',0.08));}, step(){if(!AC)return;const t=AC.currentTime;tone(90,t,0.12,'sine',0.25,null,50);}, jump(){if(!AC)return;const t=AC.currentTime;tone(260,t,0.25,'square',0.12,null,620);}, land(){if(!AC)return;const t=AC.currentTime;tone(120,t,0.15,'sine',0.35,null,45);noise(t,0.12,0.15,300);}, egg(){if(!AC)return;const t=AC.currentTime;[784,988,1175,1568].forEach((f,i)=>tone(f,t+i*0.07,0.25,'triangle',0.2));}, hatch(){if(!AC)return;const t=AC.currentTime;noise(t,0.08,0.4,2500,2);tone(600,t+0.08,0.18,'square',0.1,null,1200);tone(1200,t+0.22,0.15,'square',0.08,null,900);}, roar(){if(!AC)return;const t=AC.currentTime;tone(160,t,0.9,'sawtooth',0.25,null,70);tone(240,t,0.8,'sawtooth',0.12,null,110);noise(t,0.9,0.35,500,0.7);}, win(){if(!AC)return;const t=AC.currentTime;[523,659,784,1047,784,1047,1319].forEach((f,i)=>tone(f,t+i*0.13,0.35,'triangle',0.25));}, candy(n){if(!AC)return;const t=AC.currentTime;const f=660*Math.pow(2,((n%8))/12);tone(f,t,0.12,'triangle',0.18);tone(f*1.5,t+0.06,0.14,'triangle',0.12);}, boing(){if(!AC)return;const t=AC.currentTime;tone(180,t,0.45,'sine',0.35,null,720);tone(360,t,0.3,'triangle',0.1,null,1100);}, ahh(){if(!AC)return;const t=AC.currentTime;tone(300,t,0.5,'triangle',0.15,null,420);tone(320,t+0.6,0.6,'triangle',0.18,null,520);}, choo(){if(!AC)return;const t=AC.currentTime;noise(t,0.5,0.6,1800,0.8);tone(500,t,0.3,'square',0.12,null,150);}, babyRoar(i){if(!AC)return;const t=AC.currentTime;tone(520+i*45,t,0.28,'square',0.07,null,330);}, fire(){if(!AC)return;const t=AC.currentTime;noise(t,0.25,0.3,1100,0.8);tone(420,t,0.2,'sawtooth',0.1,null,120);}, pop(){if(!AC)return;const t=AC.currentTime;tone(900,t,0.14,'square',0.14,null,200);noise(t,0.1,0.3,3000,1);}, ouch(){if(!AC)return;const t=AC.currentTime;tone(700,t,0.25,'triangle',0.25,null,250);tone(520,t+0.12,0.25,'triangle',0.2,null,200);}, bonk(){if(!AC)return;const t=AC.currentTime;tone(240,t,0.15,'square',0.12,null,120);}, lose(){if(!AC)return;const t=AC.currentTime;[392,370,349,311].forEach((f,i)=>tone(f,t+i*0.32,0.4,'triangle',0.22,null,f*0.96));}, rumble(){if(!AC)return;const t=AC.currentTime;noise(t,1.8,0.3,90,0.7);tone(55,t,1.8,'sine',0.3,null,40);}, boom(){if(!AC)return;const t=AC.currentTime;noise(t,0.9,0.6,200,0.6);tone(90,t,0.8,'sine',0.5,null,30);}, grr(){if(!AC)return;const t=AC.currentTime;tone(150,t,0.3,'sawtooth',0.08,null,100);}, heart(){if(!AC)return;const t=AC.currentTime;[660,880,1320].forEach((f,i)=>tone(f,t+i*0.08,0.18,'sine',0.2));}, squeak(){if(!AC)return;const t=AC.currentTime;tone(1200,t,0.12,'sine',0.18,null,1800);tone(1500,t+0.1,0.1,'sine',0.14,null,900);}, honk(){if(!AC)return;const t=AC.currentTime;tone(320,t,0.18,'square',0.1,null,260);tone(300,t+0.2,0.18,'square',0.1,null,240);}, click(){if(!AC)return;const t=AC.currentTime;for(let i=0;i<4;i++)noise(t+i*0.08,0.04,0.3,4000,4);}, gift(){if(!AC)return;const t=AC.currentTime;noise(t,0.15,0.3,2500,1);[659,784,988,1319,1568].forEach((f,i)=>tone(f,t+0.1+i*0.07,0.22,'triangle',0.18));}, power(){if(!AC)return;const t=AC.currentTime;tone(300,t,0.6,'square',0.08,null,1200);tone(450,t+0.05,0.6,'triangle',0.1,null,1600);}, stomp(){if(!AC)return;const t=AC.currentTime;tone(70,t,0.25,'sine',0.4,null,40);noise(t,0.15,0.2,200,1);}, hic(){if(!AC)return;const t=AC.currentTime;tone(700,t,0.08,'square',0.12,null,1100);}, gold(){if(!AC)return;const t=AC.currentTime;[1047,1319,1568,2093,1568,2093,2637].forEach((f,i)=>tone(f,t+i*0.08,0.3,'sine',0.16));}, mama(i){if(!AC)return;const t=AC.currentTime;const f=900+i*30;tone(f,t,0.14,'sine',0.14,null,f*1.3);tone(f*0.8,t+0.16,0.2,'sine',0.14,null,f*0.7);}, giggle(){if(!AC)return;const t=AC.currentTime;[0,1,2,3,4,5].forEach(i=>tone(520+(i%2)*160+i*30,t+i*0.09,0.09,'triangle',0.2,null,700+i*40));}, grumble(){if(!AC)return;const t=AC.currentTime;tone(80,t,0.9,'sawtooth',0.18,null,55);tone(95,t+0.3,0.7,'sawtooth',0.12,null,60);}, snore(){if(!AC)return;const t=AC.currentTime;noise(t,0.5,0.15,500,1);tone(110,t,0.5,'sine',0.12,null,90);}, vroom(){if(!AC)return;const t=AC.currentTime;tone(70,t,0.7,'sawtooth',0.14,null,160);tone(110,t+0.1,0.5,'square',0.06,null,220);}, prop(){if(!AC)return;const t=AC.currentTime;for(let i=0;i<8;i++)noise(t+i*0.07,0.05,0.18,600,2);tone(140,t,0.6,'sawtooth',0.08,null,260);}, splash(){if(!AC)return;const t=AC.currentTime;noise(t,0.45,0.4,1200,0.7);tone(300,t,0.2,'sine',0.12,null,120);}, blub(){if(!AC)return;const t=AC.currentTime;tone(500+Math.random()*300,t,0.08,'sine',0.1,null,900);}, hello(){if(!AC)return;const t=AC.currentTime;[880,1109,1319].forEach((f,i)=>tone(f,t+i*0.09,0.2,'sine',0.18));} }; // music: simple bouncy loop, scheduled 0.6 s ahead let musicNext=0,musicStep=0; const MEL=[67,0,71,74,72,0,69,67,64,0,67,69,67,0,0,0, 67,0,71,74,76,0,74,72,71,0,69,71,67,0,0,0]; const BASS=[43,43,47,47,45,45,38,38]; function midi(n){return 440*Math.pow(2,(n-69)/12);} function startMusic(){musicNext=AC.currentTime+0.1;musicStep=0;setInterval(schedMusic,100);} function schedMusic(){ if(!AC||AC.state!=='running')return; const spb=0.18; if(musicNext{muted=!muted;sndBtn.textContent=muted?'πŸ”‡':'πŸ”Š';if(master)master.gain.value=muted?0:0.9;}); /* ================= WORLD ================= */ const canvas=document.getElementById('c'); const renderer=(()=>{const tries=window.__tv?[{antialias:false,powerPreference:'low-power'},{antialias:false,precision:'mediump'}]:[{antialias:true},{antialias:false,powerPreference:'low-power',precision:'mediump'},{antialias:false,precision:'lowp',depth:true,stencil:false,alpha:false}]; for(const o of tries){try{const r=new THREE.WebGLRenderer(Object.assign({canvas,failIfMajorPerformanceCaveat:false},o));if(r.getContext())return r;}catch(e){}} if(window.THREE){window.__no3d=true;__bootMsg('This browser cannot draw 3D (WebGL is off or missing), so the game cannot run here. Please play on a tablet, phone or computer. Tip: an iPad on AirPlay to the TV works, and a PS5 controller can pair with the iPad by Bluetooth.');} throw new Error(window.THREE?'no WebGL':'3D engine did not load');})(); renderer.setPixelRatio(window.__tv?1:Math.min(devicePixelRatio||1,2)); renderer.shadowMap.enabled=!window.__tv;renderer.shadowMap.type=THREE.PCFSoftShadowMap; const scene=new THREE.Scene();scene.background=new THREE.Color(0x9fe0ff);scene.fog=new THREE.Fog(0x9fe0ff,30,70); const camera=new THREE.PerspectiveCamera(55,1,0.1,200); const hemi=new THREE.HemisphereLight(0xffffff,0x6a8f4a,0.75);scene.add(hemi); const sun=new THREE.DirectionalLight(0xfff2d6,0.85);sun.position.set(15,30,10);sun.castShadow=true; sun.shadow.mapSize.set(1024,1024);Object.assign(sun.shadow.camera,{left:-25,right:25,top:25,bottom:-25,near:1,far:80});scene.add(sun);scene.add(sun.target); let N=44,HALF=N/2; // the island is bigger: buildMap sets N from MP.size function hash(x,z){const s=Math.sin(x*127.1+z*311.7)*43758.5453;return s-Math.floor(s);} /* ================= MAPS ================= */ // Each map is its own level: ground colours, hills, water, scenery and beetle colour. const MAPS={ meadow:{name:'Meadow',icon:'🌼',sky:0x9fe0ff,hemi:0x6a8f4a,top:[0.27,0.62,0.5],jit:0.3,side:[0.08,0.45,0.38],water:0x4fc3f7,waterY:0.6,amp:1,max:3,bug:0x7b4fd0,decor:'meadow'}, beach:{name:'Beach',icon:'πŸ–οΈ',sky:0x8fdcff,hemi:0xc9b37a,top:[0.12,0.6,0.74],jit:0.04,side:[0.11,0.5,0.62],water:0x29b6f6,waterY:1.35,amp:0.7,max:3,sea:true,bug:0xff6e40,decor:'beach'}, desert:{name:'Desert',icon:'🏜️',sky:0xffe2a8,hemi:0xc9a05a,top:[0.1,0.65,0.64],jit:0.03,side:[0.08,0.55,0.52],water:0,waterY:-5,amp:1.1,max:4,dune:true,bug:0x8d6e63,decor:'desert'}, snow:{name:'Snow',icon:'❄️',sky:0xdcefff,hemi:0x9fb8d0,top:[0.58,0.35,0.93],jit:0.02,side:[0.6,0.18,0.72],water:0xa8dcff,waterY:0.6,amp:1,max:3,bug:0x1e88e5,decor:'snow',snowfall:true}, jungle:{name:'Jungle',icon:'🌴',sky:0xa6e8c8,hemi:0x3e6b3a,top:[0.33,0.58,0.32],jit:0.05,side:[0.07,0.4,0.28],water:0x26a69a,waterY:0.6,amp:1.1,max:3,bug:0xd81b60,decor:'jungle',fogNear:22,fogFar:60}, forest:{name:'Forest',icon:'πŸ‚',sky:0xffdcb8,hemi:0x7a6a3a,top:[0.22,0.42,0.4],jit:0.05,side:[0.07,0.42,0.33],water:0x4fc3f7,waterY:0.6,amp:1,max:3,bug:0x5d4037,decor:'forest'}, toys:{name:'Toy Land',icon:'🧸',sky:0xbfe6ff,hemi:0x9a8fb0,top:[0.6,0.55,0.64],jit:2.2,side:[0.62,0.3,0.6],water:0x7fd3ff,waterY:0.6,amp:0.7,max:2,bug:0x7b4fd0,decor:'toys'}, hub:{name:"Rexy's Island",icon:'🏝️',sky:0x9fe0ff,hemi:0x6a8f4a,top:[0.3,0.55,0.55],jit:0.2,side:[0.08,0.45,0.38],water:0x4fc3f7,waterY:0.6,amp:0.6,max:2,bug:0,decor:'hub',hub:true,size:66,fogNear:42,fogFar:100}, house:{name:'Blue House',icon:'🏑',sky:0xa9e4ff,hemi:0x6a8f4a,top:[0.3,0.6,0.52],jit:0.25,side:[0.08,0.45,0.38],water:0x4fc3f7,waterY:0.6,amp:0.8,max:3,bug:0x7b4fd0,decor:'house'}, inside:{name:'Inside the Blue House',icon:'πŸ›οΈ',sky:0xd8efff,hemi:0x9a8fb0,top:[0.1,0.45,0.62],jit:0.02,side:[0.1,0.3,0.85],water:0x7fd3ff,waterY:-5,amp:0,max:4,bug:0,decor:'inside',inside:true,noSmooth:true,fogNear:45,fogFar:100, vehs:[['car',-6,4],['car',-15.5,-4,0x2f80ed],['plane',6,1],['blaster',-15.5,4]],pond:[15.5,15.5,3.4],mush:[[-15.5,8.5],[15.5,-5],[-5,15.5],[5,-15.5],[15.5,8]],gates:[[-5,-5.5],[0,-6.2],[5,-5.5]]}, rain:{name:'Rain Land',icon:'🌧️',sky:0x9fb4c8,hemi:0x55705f,top:[0.36,0.5,0.42],jit:0.05,side:[0.08,0.38,0.32],water:0x5c8fd6,waterY:0.6,amp:1.1,max:3,bug:0,decor:'rain',rain:true,fogNear:26,fogFar:72}, race:{name:'Race Track',icon:'🏁',sky:0xa8e0ff,hemi:0x6a8f4a,top:[0.28,0.6,0.5],jit:0.2,side:[0.08,0.45,0.38],water:0x4fc3f7,waterY:0.6,amp:0.6,max:2,bug:0,decor:'race',race:true, vehs:[['car',-3,-12.2,0xff3d3d,Math.PI/2],['car',-3,-14.4,0x2f80ed,Math.PI/2],['car',-6.5,-12.2,0xffd24d,Math.PI/2],['car',-6.5,-14.4,0x5ccf6b,Math.PI/2],['plane',-5,-0.5],['blaster',10,6],['jet',8.5,-1.5]], pond:[-9,3.5,3],mush:[[-3,6],[-11,-5],[10,-6],[12,2.5]],gates:[[-5,-5.5],[0,-6.2],[5,-5.5]]}, mountain:{name:'Mountain',icon:'⛰️',sky:0xb5d8ff,hemi:0x667788,top:[0.27,0.25,0.48],jit:0.04,side:[0.6,0.06,0.48],water:0x4fc3f7,waterY:0.6,amp:2.7,max:7,lift:1,snowcap:4,bug:0x455a64,decor:'mountain'} }; const MAP_ORDER=['toys','house','inside','race','meadow','forest','jungle','beach','desert','mountain','snow','rain']; // the order of the gates round the island: each land sits next to a land like it let GATES=[],gateCd=0,traveling=false; function gatesFor(id){const NL=MAP_ORDER.length;if(MAPS[id].hub)return MAP_ORDER.map((to,k)=>{const a=k/NL*Math.PI*2,R=25;const x=Math.sin(a)*R,z=Math.cos(a)*R;return {to,x,z,ry:Math.atan2(-x,-z)};}); const k=MAP_ORDER.indexOf(id),n=MAP_ORDER.length,P=MAPS[id].gates||[[-11.5,-9.5],[-6.5,-11],[-1.5,-10.5]]; const out=[{to:MAP_ORDER[(k+n-1)%n],x:P[0][0],z:P[0][1],ry:0},{to:'hub',x:P[1][0],z:P[1][1],ry:0},{to:MAP_ORDER[(k+1)%n],x:P[2][0],z:P[2][1],ry:0}]; // the Blue House door is a portal: walk in to go inside the house if(id==='house'){const d=Math.hypot(YARD.x-HOUSE.x,YARD.z-HOUSE.z),ux=(YARD.x-HOUSE.x)/d,uz=(YARD.z-HOUSE.z)/d;out.unshift({to:'inside',x:HOUSE.x+ux*3.5,z:HOUSE.z+uz*3.5,ry:Math.atan2(ux,uz),door:true});out.splice(out.findIndex((G,i)=>i>0&&G.to==='inside'),1);} return out;} function sectorOf(x,z){const n=MAP_ORDER.length,a=(Math.atan2(x,z)+Math.PI*2)%(Math.PI*2);return Math.round(a/(Math.PI*2/n))%n;} let mapId='hub'; let MP=MAPS[mapId],builtMap=null,world=null,water=null,volcano=new THREE.Group(); const NEST={x:3.5,z:6.5};let VSPOTS=[[-16,-16],[16.5,-15.5],[-15.5,16.5]]; let H=[]; function heightCell(ix,iz){ const x=ix-HALF+0.5,z=iz-HALF+0.5,d=Math.hypot(x,z); let n=Math.sin(ix*0.25)*0.9+Math.cos(iz*0.21)*0.9+Math.sin((ix+iz)*0.13)*0.7; if(MP.dune)n+=Math.sin(ix*0.45+iz*0.12)*0.8; let h=Math.floor(1.2+n*MP.amp+(MP.lift||0)); if(MP.sea)h=Math.min(h,Math.floor((12-x)/2.5)); // beach: the sand slopes into the sea on one side if(MP.inside){let w=insideWall(x,z)?4:1;if(d<3||Math.hypot(x-NEST.x,z-NEST.z)<2.6||GATES.some(g=>Math.hypot(x-g.x,z-g.z)<2.4))w=1;return w;} if(MP.race){const e=trackE(x,z);if(e>0.8&&e<1.2)h=1;} if(d<5||Math.hypot(x-NEST.x,z-NEST.z)<4.5)h=1; // flat start and flat nest if(Math.hypot(x-POND.x,z-POND.z)Math.hypot(x-g.x,z-g.z)<3))h=1; // flat ground at each gate // flat garden round the blue house // flat ground round the pond return Math.max(0,Math.min(MP.max,h)); } const POND={x:8.5,z:-10.5,r:4.2,floor:-2,surf:0.85}; // Inside the Blue House: 9 rooms in a 3 x 3 grid with doors between them, one room for each cousin function insideWall(x,z){const ax=Math.abs(x),az=Math.abs(z);if(ax>20.2||az>20.2)return true;const door=c=>[-15.5,0,15.5].some(d=>Math.abs(c-d)<1.6); if(Math.abs(ax-10.5)<0.6&&!door(z))return true;if(Math.abs(az-10.5)<0.6&&!door(x))return true;return false;} function nearWall(x,z,m){if(!MP.inside)return false;m=m||1.3;for(const a of[-m,0,m])for(const b of[-m,0,m])if(insideWall(x+a,z+b))return true;return false;} function roomOf(x,z){const c=v=>v<-10.5?0:v>10.5?2:1;return c(z)*3+c(x);} const ROOMC=[-15.5,0,15.5]; // Race Track: an oval road round the middle of the land const TRA=17,TRB=13;function trackE(x,z){return Math.hypot(x/TRA,z/TRB);} const HOUSE={x:-9,z:9},YARD={x:-5,z:5}; function inPondCell(i,j){return Math.hypot(i-HALF+0.5-POND.x,j-HALF+0.5-POND.z)=N||j>=N||!H[i])return 1;if(inPondCell(i,j))return POND.floor;return H[i][j]+1;} const trees=[],mush=[],VOLC=[],flakes=[]; const GEO={},MATS={};const WHITE=new THREE.Color(0xffffff); function geo(w,h,d){const k=w+','+h+','+d;return GEO[k]||(GEO[k]=new THREE.BoxGeometry(w,h,d));} function mat(c,em){const k=c+'/'+(em||0);return MATS[k]||(MATS[k]=new THREE.MeshLambertMaterial({color:c,emissive:em||0}));} function bx(g,w,h,d,c,x,y,z,ry,rx,rz,em){const m=new THREE.Mesh(geo(w,h,d),mat(c,em));m.position.set(x,y,z);if(ry)m.rotation.y=ry;if(rx)m.rotation.x=rx;if(rz)m.rotation.z=rz;m.castShadow=true;g.add(m);return m;} function addObs(g,x,z,r){g.position.set(x,groundAt(x,z),z);world.add(g);trees.push({x,z,r,g,shake:0});} function addDeco(g,x,z){g.position.set(x,groundAt(x,z),z);world.add(g);} function spots(n,minD,maxD,seed,clear){const out=[];for(let t=0;tMath.hypot(g.x-x,g.z-z)<3.6))continue;if(MP.decor==='house'&&(Math.hypot(x-HOUSE.x,z-HOUSE.z)<6.5||Math.hypot(x-YARD.x,z-YARD.z)<3.5))continue;if((MP.vehs||VEHS).some(v=>Math.hypot(v[1]-x,v[2]-z)<(v[0]==='jet'?5:3)))continue;if(nearWall(x,z))continue;if(MP.race&&Math.abs(trackE(x,z)-1)<0.26)continue; if(Math.abs(x)>HALF-2||Math.abs(z)>HALF-2)continue;if(Math.hypot(x-NEST.x,z-NEST.z)<5.5||Math.hypot(x,z)<5)continue; if(VSPOTS.some(([vx,vz])=>Math.hypot(vx-x,vz-z)<5.5))continue;if(trees.some(o=>Math.hypot(o.x-x,o.z-z)60)break;const m=new THREE.Mesh(bubGeo,bubMat);m.position.set(x+(Math.random()-0.5)*0.4,y+(Math.random()-0.5)*0.3,z+(Math.random()-0.5)*0.4);const s=0.6+Math.random()*0.9;m.scale.setScalar(s);scene.add(m);bubbles.push({m,ph:Math.random()*6,sp:1.2+Math.random()*1.2});}} const bubGeo=new THREE.SphereGeometry(0.12,8,6),bubMat=new THREE.MeshBasicMaterial({color:0xffffff,transparent:true,opacity:0.7}); /* ---- vehicles: walk up, tap GET IN, tap GET OUT ---- */ const VEHS=[['car',-4,-3.5],['car',-1,-6.5,0x2f80ed],['plane',4.5,-4],['blaster',-9.5,1.5],['jet',11,2]];let vehicles=[],ride=null,rideHint=false; function carModel(c){c=c||0xff3d3d;const g=new THREE.Group();bx(g,1.9,0.6,3.0,c,0,0.75,0);bx(g,1.9,0.5,0.9,c,0,1.25,-1.0);bx(g,1.7,0.5,0.08,0x9be7ff,0,1.3,0.6,0,-0.4); for(const[a,b]of[[-1,1],[1,1],[-1,-1],[1,-1]])bx(g,0.35,0.7,0.7,0x222222,a*0.98,0.35,b*0.95);bx(g,0.35,0.2,0.08,0xfff59d,-0.6,0.8,1.52);bx(g,0.35,0.2,0.08,0xfff59d,0.6,0.8,1.52);bx(g,0.5,0.1,0.5,0x333333,0,1.1,0.25);return g;} function planeModel(){const g=new THREE.Group(),Y=0xffc61a;bx(g,1.1,1.0,3.6,Y,0,1.3,0);bx(g,0.8,0.8,0.5,Y,0,1.3,2.0);bx(g,6.2,0.14,1.1,0x40a4ff,0,1.35,0.3);bx(g,2.4,0.12,0.7,0x40a4ff,0,1.5,-1.6);bx(g,0.12,0.9,0.8,0x40a4ff,0,2.0,-1.6); for(const a of[-1,1]){bx(g,0.12,0.6,0.12,0x555555,a*0.6,0.5,0.6);bx(g,0.25,0.4,0.4,0x222222,a*0.6,0.2,0.6);}bx(g,0.12,0.3,0.12,0x555555,0,0.6,-1.5); const pr=new THREE.Group();pr.position.set(0,1.3,2.3);g.add(pr);bx(pr,0.2,2.0,0.08,0x5d4037,0,0,0);bx(pr,0.25,0.25,0.25,0xff3d3d,0,0,0.05);g.userData.prop=pr;return g;} // the big jet: an original block airliner. The pilot sits on top, a friend can hop on, and the babies ride in a row behind. function jetModel(){const g=new THREE.Group(),W=0xffffff,B=0x2f80ed,R=0xff5c8a,GL=0x9be7ff; bx(g,1.6,1.4,7,W,0,1.75,0);bx(g,1.64,0.3,7.04,B,0,1.3,0);bx(g,1.3,1.1,0.9,W,0,1.7,3.9);bx(g,0.9,0.7,0.4,B,0,1.6,4.4);bx(g,1.1,0.5,0.5,GL,0,2.2,3.3); for(let k=0;k<6;k++)for(const sd of[-1,1])bx(g,0.06,0.32,0.36,GL,sd*0.82,1.95,2.1-k*0.9); bx(g,9.6,0.18,1.7,B,0,1.5,0.3);for(const sd of[-1,1]){bx(g,0.22,0.5,1.0,R,sd*4.75,1.75,0.1);bx(g,0.7,0.7,1.5,0xcfd8dc,sd*2.5,1.1,0.7);bx(g,0.45,0.45,0.1,0x37474f,sd*2.5,1.1,1.46);} bx(g,3.4,0.15,1.1,B,0,2.1,-3.1);bx(g,0.16,1.7,1.3,R,0,3.1,-3.0);bx(g,0.18,0.3,0.3,0xffffff,0,3.3,-2.9); for(const[a,b]of[[-0.7,1.8],[0.7,1.8],[0,-2.6]]){bx(g,0.12,0.6,0.12,0x555555,a,0.65,b);bx(g,0.3,0.4,0.4,0x222222,a,0.2,b);} const props=[];for(const sd of[-1,1]){const pr=new THREE.Group();pr.position.set(sd*2.5,1.1,1.55);g.add(pr);bx(pr,0.16,1.5,0.06,0x5d4037,0,0,0);bx(pr,0.2,0.2,0.2,R,0,0,0.05);props.push(pr);}g.userData.props=props;return g;} function buildVehicles(){vehicles=(MP.hub?[['car',-6.5,1.5],['car',-6.5,-2,0x2f80ed],['car',-4,-5,0xffd24d],['plane',7.5,0.5],['blaster',0,-7.5],['jet',9,-9]]:MP.vehs||VEHS).map(([kind,x,z,col,f0])=>{const g=kind==='car'?carModel(col):kind==='blaster'?blasterModel():kind==='jet'?jetModel():planeModel();world.add(g);const v={kind,g,hx:x,hz:z,x,z,y:groundAt(x,z),face:f0||0,hface:f0||0,vy:0};g.position.set(x,v.y,z);g.rotation.y=v.face;return v;});ride=null;} function resetVehicles(){ride=null;vehicles.forEach(v=>{v.driver=null;v.passenger=null;v.x=v.hx;v.z=v.hz;v.y=groundAt(v.x,v.z);v.face=v.hface||0;v.vy=0;v.g.position.set(v.x,v.y,v.z);v.g.rotation.set(0,0,0);});rideBtn.hidden=true;} function nearVeh(){let best=null,bd=3.0;for(const v of vehicles){if(v.driver&&v.driver!==player&&!(v.kind==='jet'&&!v.passenger))continue;const d=Math.hypot(v.x-player.x,v.z-player.z)-(v.kind==='jet'?1.4:0);if(dgroundAt(nx,nz)+2){chute=true;say('Wheee! πŸͺ‚',1500);}SFX.jump();return;} const v=nearVeh();if(!v)return; if(v.driver&&v.driver!==player){v.passenger=player;player.pass=true;ride=v;chute=false;SFX.prop();say('πŸ›« You hopped on the jet! FIRE works up here too.',2800);return;} v.driver=player;ride=v;player.x=v.x;player.z=v.z;player.y=Math.max(player.y,v.y);player.face=v.face;chute=false; if(v.kind==='car'){SFX.vroom();say('πŸš— Vroom! Drive with the joystick. JUMP = hop.',2500);}else if(v.kind==='blaster'){SFX.power();haptic(60,0.8);say('πŸ’₯ Blaster! Turn with the joystick. Hold FIRE to blast the land!',3000);} else if(v.kind==='jet'){SFX.prop();SFX.vroom();say('πŸ›« The big jet! Hold JUMP to fly up high. The babies ride with you!'+(twoP?' Player 2 can hop on too.':''),3500);}else{SFX.prop();say('✈️ Hold JUMP to fly up. Let go to glide down.',3000);}} /* ---- blaster station: a toy blaster on a turntable. Rexy sits in it, turns with the joystick and holds FIRE: bouncy paint balls knock holes in the land and pop trees and scenery ---- */ function blasterModel(){const g=new THREE.Group();const base=new THREE.Mesh(new THREE.CylinderGeometry(1.5,1.7,0.5,16),mat(0x7e57c2));base.position.y=0.25;base.castShadow=true;g.add(base); const ring=new THREE.Mesh(new THREE.TorusGeometry(1.5,0.12,6,20),mat(0xffd24d));ring.rotation.x=Math.PI/2;ring.position.y=0.5;g.add(ring); bx(g,1.2,0.5,1.0,0xff5c8a,0,0.75,-0.4);bx(g,0.25,0.9,0.25,0x555555,0,0.9,0.4); const C=[0x40c4ff,0xffd24d,0x5ccf6b];for(let k=0;k<3;k++){const t=new THREE.Mesh(new THREE.CylinderGeometry(0.22,0.28,1.8,10),mat(C[k]));t.rotation.x=Math.PI/2;t.position.set((k-1)*0.45,1.45,1.1);t.castShadow=true;g.add(t); const tip=new THREE.Mesh(new THREE.TorusGeometry(0.24,0.07,6,12),mat(0xffffff));tip.position.set((k-1)*0.45,1.45,2.0);g.add(tip);} bx(g,1.6,0.6,0.7,0xff9800,0,1.45,0.4);bx(g,0.3,0.3,0.3,0xff3d3d,0,1.85,0.5);return g;} let blasts=[],blastN=0;const blastGeo=new THREE.SphereGeometry(0.28,10,8); const BLC=[0xff5c8a,0x40c4ff,0xffd24d,0x5ccf6b,0xb57bff,0xff9a3d].map(c=>new THREE.MeshBasicMaterial({color:c})); function blast(){if(!ride||ride.kind!=='blaster')return;fireCd=0.11;blastN++;const k=(blastN%3)-1,f=player.face,cx=Math.cos(f),cz=-Math.sin(f); const x=player.x+Math.sin(f)*2.2+cx*k*0.45,z=player.z+Math.cos(f)*2.2+cz*k*0.45,y=player.y+1.45;const m=new THREE.Mesh(blastGeo,BLC[blastN%BLC.length]);m.position.set(x,y,z);scene.add(m); blasts.push({m,x,y,z,vx:Math.sin(f)*24,vz:Math.cos(f)*24,vy:4.5,life:2.5});SFX.pew();haptic(15,0.25);} function crater(x,z){const R=1.7;let hit=false;for(let i=Math.floor(x+HALF-R);i<=Math.ceil(x+HALF+R);i++)for(let j=Math.floor(z+HALF-R);j<=Math.ceil(z+HALF+R);j++){if(i<1||j<1||i>=N-1||j>=N-1||inPondCell(i,j))continue; const cx=i-HALF+0.5,cz=j-HALF+0.5,d=Math.hypot(cx-x,cz-z);if(d>R)continue;if(Math.hypot(cx-NEST.x,cz-NEST.z)<4.2||GATES.some(G=>Math.hypot(cx-G.x,cz-G.z)<2.6)||Math.hypot(cx-player.x,cz-player.z)<1.6)continue; const dn=d<0.9?2:1;if(H[i][j]>0){H[i][j]=Math.max(0,H[i][j]-dn);hit=true;}} if(hit){mapDamaged=true;for(const m of mush){if(m.g.visible&&Math.hypot(m.x-x,m.z-z)<2){m.g.visible=false;m.x=9999;}}}} function popThing(t){const i=trees.indexOf(t);if(i<0||t.keep)return;trees.splice(i,1);const p=t.g.position;burst(p.x,p.y+1.5,p.z,0x5ccf6b,14,6);burst(p.x,p.y+1,p.z,0xffe14d,10,5);t.g.visible=false;mapDamaged=true;SFX.pop();} function updateBlasts(dt){blkT-=dt;if(mapDamaged&&blocksMesh&&blkT<=0&&blocksDirty){blocksDirty=false;blkT=0.3;buildBlocks();} for(let n=blasts.length-1;n>=0;n--){const b=blasts[n];b.life-=dt;b.vy-=16*dt;b.x+=b.vx*dt;b.z+=b.vz*dt;b.y+=b.vy*dt;b.m.position.set(b.x,b.y,b.z);let hit=b.life<=0||Math.abs(b.x)>HALF||Math.abs(b.z)>HALF; if(!hit)for(const t of trees){if(Math.hypot(t.x-b.x,t.z-b.z)0)&&!a.fly&&!a.swim&&Math.hypot(a.x-b.x,a.z-b.z)<1.3&&b.y