From e9459da4aa08374a2ed67f8fbe5b22de15527754 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 02:28:18 +0000 Subject: [PATCH 1/6] Ebbwork: first playable slice (work in progress, not linked from the site) A first-person flood-drainage game for the Back Room. This commit has the water simulation, one job (a back yard with a buried drain and a split pipe), the rake, bucket and stop tap, walking and touch controls, and saving. No card, phone row or What's new entry yet, so nothing on the site points at it. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01Cw2rM7oof2mCeBWM93T7t4 --- e63334287a3deaa3/ebbwork/core.js | 314 +++++++++++++++++++ e63334287a3deaa3/ebbwork/game.js | 452 ++++++++++++++++++++++++++++ e63334287a3deaa3/ebbwork/index.html | 280 +++++++++++++++++ 3 files changed, 1046 insertions(+) create mode 100644 e63334287a3deaa3/ebbwork/core.js create mode 100644 e63334287a3deaa3/ebbwork/game.js create mode 100644 e63334287a3deaa3/ebbwork/index.html diff --git a/e63334287a3deaa3/ebbwork/core.js b/e63334287a3deaa3/ebbwork/core.js new file mode 100644 index 00000000..37190c69 --- /dev/null +++ b/e63334287a3deaa3/ebbwork/core.js @@ -0,0 +1,314 @@ +/* Ebbwork: everything that is not drawing. Three parts, in order: EWSim (the water), EW.World (a job site and what + each tool does to it) and EWMaps (the jobs). No DOM and no three.js, so `node` can load this file and play a job + by calling the same functions the page does (see the README section). index.html loads it with one script tag. */ +// The water. A grid of square cells. Each has a ground height g (+ bar, a barrier laid on top), a water depth d, and a +// flow through its right and bottom edge (fx, fy, m3/s, signed). Each step: every edge's flow speeds up by the +// difference in surface height across it (and slows by friction), no cell may give more than it holds, then +// depths change by what flowed. Nothing is added or removed here except through add() and take(), so volume is +// conserved. Blocks of 8 x 8 cells go to sleep when nothing in or next to them is changing. +var EWSim=(function(){ + var BS=8,FILM=0.003,GRAV=9.0,AWAKE=45; + function Sim(W,H,cs){ + this.W=W;this.H=H;this.cs=cs;var n=W*H;this.n=n; + this.g=new Float32Array(n);this.bar=new Float32Array(n);this.solid=new Uint8Array(n); + this.d=new Float64Array(n);this.fx=new Float32Array(n);this.fy=new Float32Array(n); + this.k=new Float32Array(n); + this.BW=Math.ceil(W/BS);this.BH=Math.ceil(H/BS);var nb=this.BW*this.BH; + this.act=new Uint8Array(nb);this.proc=new Uint8Array(nb);this.was=new Uint8Array(nb); + this.nProc=0;this.fric=0.015;this.damp=0.4; + } + var P=Sim.prototype; + P.idx=function(x,z){return z*this.W+x}; + P.wake=function(i){var x=i%this.W,z=(i-x)/this.W;this.act[((z/BS)|0)*this.BW+((x/BS)|0)]=AWAKE}; + P.wakeAll=function(){this.act.fill(AWAKE)}; + P.add=function(i,vol){if(this.solid[i])return 0;this.d[i]+=vol/(this.cs*this.cs);this.wake(i);return vol}; + P.take=function(i,vol){var a=this.cs*this.cs,have=this.d[i]*a,t=vol0&&act[b-1])||(bx0&&act[b-BW])||(bzzj?zi:zj;up=(hi>hj?hi:hj)-sill-FILM; + if(up>0){if(x===xe){fx[i]=0;act[b]=AWAKE}else{f=(fx[i]+cdt*up*(hi-hj))/(dm+fr/(up+0.01));fx[i]=f}}else fx[i]=0; + }else fx[i]=0; + if(zzj?zi:zj;up=(hi>hj?hi:hj)-sill-FILM; + if(up>0){if(z===ze){fy[i]=0;act[b]=AWAKE}else{f=(fy[i]+cdt*up*(hi-hj))/(dm+fr/(up+0.01));fy[i]=f}}else fy[i]=0; + }else fy[i]=0; + } + } + } + // 2. no cell gives more than it holds + for(bz=0;bz0)out+=v;v=fy[i];if(v>0)out+=v; + if(x>0){v=fx[i-1];if(v<0)out-=v} + if(z>0){v=fy[i-W];if(v<0)out-=v} + var can=d[i]*lim;k[i]=out>can?(out>0?can/out:0):1; + } + } + for(bz=0;bz0)fx[i]=a*k[i];else if(a<0)fx[i]=a*(proc[(((z/BS)|0))*BW+(((x+1)/BS)|0)]?k[i+1]:0); + a=fy[i]; + if(a>0)fy[i]=a*k[i];else if(a<0)fy[i]=a*(proc[(((z+1)/BS)|0)*BW+((x/BS)|0)]?k[i+W]:0); + } + } + // 3. depths + var q=dt/area; + for(bz=0;bz0)net+=fx[i-1];if(z>0)net+=fy[i-W]; + net*=q;var nd=d[i]+net;if(nd<0)nd=0;d[i]=nd; + if(net<0)net=-net;if(net>mx)mx=net; + } + if(mx>4e-5)act[b]=AWAKE;else if(act[b]>0)act[b]--; + was[b]=1; + } + for(b=0;b0?this.fx[i-1]:0),b=this.fy[i]+(i>=W?this.fy[i-W]:0),s=0.5/(this.cs*(dd+0.02)); + out[0]=a*s;out[1]=b*s; + }; + Sim.FILM=FILM;Sim.BS=BS; + return Sim; +})(); +// The job site: ground, walls, drains, leaks, valves, debris, pumps, barriers, and what each tool does to them. +// Still no DOM or three.js: index.html draws what is here and calls these functions when the player acts. +var EW=(function(){ + var CS=0.5,AREA=CS*CS,FILM=EWSim.FILM; + var T={GRASS:0,PAVE:1,SOIL:2,TILE:3,ROAD:4,GRAVEL:5,CONC:6}; + function mulberry(a){return function(){a|=0;a=a+0x6D2B79F5|0;var t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}} + function hash2(x,z,s){var h=Math.imul(x*374761393+z*668265263^s*1274126177,1103515245);h^=h>>>13;h=Math.imul(h,1274126177);return((h^h>>>16)>>>0)/4294967296} + function vnoise(x,z,s){var x0=Math.floor(x),z0=Math.floor(z),fx=x-x0,fz=z-z0;fx=fx*fx*(3-2*fx);fz=fz*fz*(3-2*fz); + var a=hash2(x0,z0,s),b=hash2(x0+1,z0,s),c=hash2(x0,z0+1,s),d=hash2(x0+1,z0+1,s);return a+(b-a)*fx+(c-a)*fz+(a-b-c+d)*fx*fz} + + function World(def,opt){ + opt=opt||{}; + var w=this;w.def=def;w.W=Math.round(def.w/CS);w.H=Math.round(def.h/CS);w.cs=CS; + var S=w.S=new EWSim(w.W,w.H,CS),n=S.n; + w.sh=new Float32Array(n); // top of a solid cell (m) + w.type=new Uint8Array(n); // surface type (T) + w.soft=new Uint8Array(n); // 1 = can be dug + w.mask=new Uint8Array(n).fill(1); // 1 = counts as part of the job + w.sink=new Uint8Array(n); // 1 = water here leaves the map (ditch, river outfall) + w.hold=new Float32Array(n).fill(-1e9); // >-1e8: a river cell held at this surface level + w.g0=null;w.boxes=[];w.drains=[];w.leaks=[];w.valves=[];w.debris=[];w.pumps=[];w.barriers=[];w.sockets=[];w.gens=[]; + w.signs=[];w.sinkList=[];w.holdList=[];w.dirty=[];w.spoil=0;w.t=0;w.tick=0;w.removed=0;w.added=0;w.holdIn=0;w._hin=0; + w.spawn={x:def.w/2,z:def.h/2,yaw:0};w.rand=mulberry(def.seed||7); + w.hoseLen=opt.hoseLen||9;w.cableLen=opt.cableLen||8;w.pumpRate=opt.pumpRate||0.085; + def.build(w); + w.g0=new Float32Array(S.g); + for(var i=0;i-1e8){w.holdList.push(i);w.mask[i]=0}if(S.solid[i])w.mask[i]=0} + S.wakeAll(); + w.left=0;w.wet=0;w.peak=0;w.stats();w.start=w.peak=w.left; + } + var P=World.prototype; + // ---- helpers ---- + P.cell=function(x,z){var cx=Math.floor(x/CS),cz=Math.floor(z/CS);if(cx<0||cz<0||cx>=this.W||cz>=this.H)return -1;return cz*this.W+cx}; + P.cx=function(i){return(i%this.W+0.5)*CS}; + P.cz=function(i){return(((i/this.W)|0)+0.5)*CS}; + P.zb=function(i){return this.S.g[i]+this.S.bar[i]}; + P.each=function(x0,z0,x1,z1,fn){var W=this.W,H=this.H,a=Math.max(0,Math.round(x0/CS)),b=Math.min(W,Math.round(x1/CS)),c=Math.max(0,Math.round(z0/CS)),d=Math.min(H,Math.round(z1/CS)); + for(var z=c;zW-1?W-1:x0,xb=x0+1<0?0:x0+1>W-1?W-1:x0+1,za=z0<0?0:z0>H-1?H-1:z0,zb=z0+1<0?0:z0+1>H-1?H-1:z0+1; + var a=g[za*W+xa],b=g[za*W+xb],c=g[zb*W+xa],d=g[zb*W+xb];return a+(b-a)*fx+(c-a)*fz+(a-b-c+d)*fx*fz}; + P.depthAt=function(x,z){var i=this.cell(x,z);return i<0?0:this.S.d[i]}; + // ---- building a map (called from a map's build()) ---- + P.ground=function(fn){var w=this;w.each(0,0,w.def.w,w.def.h,function(i,x,z){w.S.g[i]=fn(x,z)})}; + P.noise=function(amp,scale,x0,z0,x1,z1){var w=this,s=w.def.seed||7;w.each(x0||0,z0||0,x1||w.def.w,z1||w.def.h,function(i,x,z){w.S.g[i]+=(vnoise(x/scale,z/scale,s)-0.5)*2*amp})}; + P.surf=function(x0,z0,x1,z1,type,soft){var w=this;w.each(x0,z0,x1,z1,function(i){w.type[i]=type;w.soft[i]=soft?1:0})}; + P.shape=function(x0,z0,x1,z1,fn){var w=this;w.each(x0,z0,x1,z1,function(i,x,z){w.S.g[i]=fn(x,z,w.S.g[i])})}; + // a solid block: h is its height above the ground under it. kind is only for drawing. + P.wall=function(x0,z0,x1,z1,h,col,kind){var w=this,lo=1e9;w.each(x0,z0,x1,z1,function(i){if(w.S.g[i]1e8)lo=0; + w.each(x0,z0,x1,z1,function(i){w.S.solid[i]=1;w.sh[i]=lo+h}); + var b={x0:x0,z0:z0,x1:x1,z1:z1,y0:lo-0.6,y1:lo+h,col:col,kind:kind||'wall'};w.boxes.push(b);return b}; + // drawn only, no collision (y0,y1 are above the ground at its centre) + P.box=function(x0,z0,x1,z1,y0,y1,col,kind){var gy=this.groundAt((x0+x1)/2,(z0+z1)/2);var b={x0:x0,z0:z0,x1:x1,z1:z1,y0:gy+y0,y1:gy+y1,col:col,kind:kind||'deco'};this.boxes.push(b);return b}; + P.drain=function(x,z,o){o=o||{};var d={x:x,z:z,i:this.cell(x,z),rate:o.rate||0.12,cap:o.cap||10,clear:1,flow:0,n:0,kind:o.kind||'grate'};this.drains.push(d);return d}; + P.sinkArea=function(x0,z0,x1,z1){var w=this;w.each(x0,z0,x1,z1,function(i){w.sink[i]=1})}; + P.noJob=function(x0,z0,x1,z1){var w=this;w.each(x0,z0,x1,z1,function(i){w.mask[i]=0})}; + P.river=function(x0,z0,x1,z1,level){var w=this;w.each(x0,z0,x1,z1,function(i){w.hold[i]=level})}; + // a leak: water comes out at (x,z). valve: id of the valve that feeds it (shut it to stop it). wrench:true = can be + // tightened by hand with the wrench. (nx,nz) is which way the pipe faces, y its height above the ground. + P.leak=function(x,z,o){o=o||{};var l={x:x,z:z,i:this.cell(x,z),rate:o.rate||0.02,valve:o.valve||null,wrench:!!o.wrench,fixed:false,on:true,y:o.y==null?0.7:o.y,nx:o.nx||0,nz:o.nz||0,px:o.px==null?x:o.px,pz:o.pz==null?z:o.pz,label:o.label||''};this.leaks.push(l);return l}; + P.valve=function(x,z,id,o){o=o||{};var v={x:x,z:z,id:id,closed:false,y:o.y==null?0.9:o.y,nx:o.nx||0,nz:o.nz||0,turn:0};this.valves.push(v);return v}; + P.socket=function(x,z,o){o=o||{};var s={x:x,z:z,y:o.y==null?1.0:o.y,nx:o.nx||0,nz:o.nz||0};this.sockets.push(s);return s}; + P.sign=function(x,z,text,o){o=o||{};this.signs.push({x:x,z:z,text:text,y:o.y==null?1.4:o.y,nx:o.nx||0,nz:o.nz||0})}; + P.litter=function(x,z,r,n,kind){var w=this;for(var k=0;kw.S.d[i])w.S.d[i]=d})}; + P.spawnAt=function(x,z,yaw){this.spawn={x:x,z:z,yaw:yaw||0}}; + + // ---- every step ---- + var vv=[0,0]; + P.step=function(dt){ + var w=this,S=w.S,d=S.d,k,i,v; + w.t+=dt;w.tick++; + for(k=0;kv.turn?1:-1)*dt*1.4;if(Math.abs(v.turn-tg)<0.03)v.turn=tg}} + for(k=0;k1e-5||df<-1e-5){if(df>0)w._hin+=df*AREA;d[i]=want;S.wake(i)}} + for(k=0;k=0&&iS.g[dr.i]+0.004)got+=S.take(i,Math.min((q-got),d[i]*AREA*0.5))}} + dr.flow+=((got/dt)-dr.flow)*0.2;w.removed+=got} + for(k=0;k0){w.removed+=d[i]*AREA;d[i]=0}} + S.step(dt); + w.debrisStep(dt); + if(w.tick%8===0)w.stats(); + if(w.tick%30===0){w.holdIn=w._hin;w._hin=0} + }; + P.valveShut=function(id){for(var k=0;k0.002){s+=e;if(e>0.008)c++}} + w.left=s*AREA;w.wet=c;if(w.left>w.peak)w.peak=w.left}; + // is any water still coming in? + P.incoming=function(){for(var k=0;k0.004}; + P.fraction=function(){return this.peak>0?this.left/this.peak:0}; + P.isDone=function(){return this.fraction()<=World.DONE&&!this.incoming()}; + // how blocked each drain is: debris lying on or floating over the grate + P.clog=function(){var w=this,k,j,p;for(k=0;k0.05;p.fl=fl?1:0; + if(fl){S.vel(i,vv);var tx=vv[0]*0.8,tz=vv[1]*0.8; + for(k=0;k0.01){var ds=Math.sqrt(q),pl=Math.min(0.3,dr.flow*2.5)/(0.6+ds);tx+=dx/ds*pl;tz+=dz/ds*pl} + else if(q<=0.01){tx*=0.2;tz*=0.2}} + var kk=Math.min(1,(p.kick>0?1.2:3.5)*dt);p.vx+=(tx-p.vx)*kk;p.vz+=(tz-p.vz)*kk; + }else{var f=Math.max(0,1-(p.kick>0?2.2:9)*dt);p.vx*=f;p.vz*=f} + if(p.kick>0)p.kick-=dt; + var sp=p.vx*p.vx+p.vz*p.vz;if(sp<1e-5)continue; + var here=S.g[i]+S.bar[i]+dd,nx=p.x+p.vx*dt,ni=w.cell(nx,p.z); + if(ni<0||S.solid[ni]||(ni!==i&&S.g[ni]+S.bar[ni]>here+(fl?0.02:0.3))){p.vx*=-0.2}else p.x=nx; + var nz=p.z+p.vz*dt;ni=w.cell(p.x,nz); + if(ni<0||S.solid[ni]||(ni!==i&&S.g[ni]+S.bar[ni]>here+(fl?0.02:0.3))){p.vz*=-0.2}else p.z=nz; + p.a+=p.s*dt*Math.min(2,Math.sqrt(sp)*3); + } + }; + // ---- what the tools do ---- + // rake: push (or pull) debris lying in front of the player + P.rake=function(px,pz,dx,dz,pull){var w=this,n=0;for(var j=0;j2.7)continue;var along=(ex*dx+ez*dz);if(q>0.5&&along/q<0.72)continue;if(along<-0.2)continue; + var s=pull?-1:1,side=(ex*-dz+ez*dx);p.vx=s*dx*5.2+(-dz)*side*0.8+(w.rand()-0.5)*0.6;p.vz=s*dz*5.2+dx*side*0.8+(w.rand()-0.5)*0.6;p.kick=0.6;n++} + return n}; + P.setValve=function(v,closed){v.closed=closed}; + P.fixLeak=function(l){if(l.wrench){l.fixed=true;l.on=false;return true}return false}; + P.scoop=function(x,z,cap){var w=this,S=w.S,cells=[],tot=0;w.each(x-0.75,z-0.75,x+0.75,z+0.75,function(i){if(!S.solid[i]&&S.d[i]>0.001){cells.push(i);tot+=S.d[i]*AREA}}); + if(tot<=0)return 0;var take=Math.min(cap,tot*0.95),got=0;for(var k=0;k=0&&this.soft[i]&&!this.S.solid[i]&&!this.S.bar[i]&&this.S.g[i]>this.g0[i]-World.DIGMAX+0.01}; + P.dig=function(x,z){var w=this,S=w.S,i=w.cell(x,z);if(!w.canDig(x,z))return false; + S.g[i]=Math.max(w.g0[i]-World.DIGMAX,S.g[i]-0.16);w.type[i]=T.SOIL;w.spoil++;w.dirty.push(i);S.wake(i); + var nb=[i-1,i+1,i-w.W,i+w.W];for(var m=0;m<4;m++){var j=nb[m];if(j>=0&&jS.g[i]+0.1){S.g[j]-=0.035;w.dirty.push(j);S.wake(j)}} + return true}; + P.canPile=function(x,z){var i=this.cell(x,z);return i>=0&&this.spoil>0&&this.soft[i]&&!this.S.solid[i]&&!this.S.bar[i]&&this.S.g[i]=0.55;s-=0.5)for(var lat=-0.5;lat<=0.5;lat+=0.5){var cx=px+dx*s-dz*lat,cz=pz+dz*s+dx*lat,c=w.cell(cx,cz),t=w.cell(cx+dx*0.62,cz+dz*0.62); + if(c<0||t<0||c===t||S.solid[c]||S.solid[t])continue;var dc=d[c];if(dc<=0.0005||dc>0.07)continue; + if(S.g[t]+S.bar[t]>S.g[c]+S.bar[c]+dc+0.05)continue;var mv=dc*0.92;d[c]-=mv;d[t]+=mv;moved+=mv*AREA;S.wake(c);S.wake(t)} + return moved}; + // barrier: three cells in a row; rot 0..3 = along x, diagonal, along z, other diagonal + var BD=[[1,0],[1,1],[0,1],[-1,1]]; + P.barrierCells=function(x,z,rot){var w=this,cx=Math.floor(x/CS),cz=Math.floor(z/CS),o=BD[rot&3],out=[]; + for(var k=-1;k<=1;k++){var ax=cx+o[0]*k,az=cz+o[1]*k;if(ax<0||az<0||ax>=w.W||az>=w.H)return null;var i=az*w.W+ax;if(w.S.solid[i]||w.S.bar[i]>0||w.sink[i])return null; + for(var q=0;q0){var nb=[i-1,i+1,i-w.W,i+w.W],best=-1,bh=1e9;for(var m=0;m<4;m++){var j=nb[m];if(j<0||j>=S.n||S.solid[j]||S.bar[j]>0)continue;var h=S.g[j]+S.d[j];if(h=0){S.d[best]+=vol;S.d[i]=0;S.wake(best)}}S.wake(i)} + var b={cells:cells,x:x,z:z,rot:rot&3};w.barriers.push(b);return b}; + P.removeBarrier=function(b){var k=this.barriers.indexOf(b);if(k<0)return;this.barriers.splice(k,1);for(k=0;k<3;k++){this.S.bar[b.cells[k]]=0;this.S.wake(b.cells[k])}}; + // pump: needs power (a socket or generator within cable reach) and a hose end somewhere else + P.placePump=function(x,z){var i=this.cell(x,z);if(i<0||this.S.solid[i])return null;var p={x:this.cx(i),z:this.cz(i),i:i,on:true,src:null,hose:null,flow:0,run:false,why:''};this.pumps.push(p);this.autoPower(p);return p}; + P.removePump=function(p){var k=this.pumps.indexOf(p);if(k>=0)this.pumps.splice(k,1)}; + P.powerList=function(){return this.sockets.concat(this.gens)}; + P.autoPower=function(p){var w=this,best=null,bd=w.cableLen;w.powerList().forEach(function(s){var q=Math.hypot(s.x-p.x,s.z-p.z);if(q<=bd){bd=q;best=s}});p.src=best;return best}; + P.setHose=function(p,x,z){var i=this.cell(x,z);if(i<0||this.S.solid[i])return false;if(Math.hypot(x-p.x,z-p.z)>this.hoseLen)return false;p.hose={x:x,z:z,i:i};return true}; + P.placeGen=function(x,z){var i=this.cell(x,z);if(i<0||this.S.solid[i])return null;var g={x:this.cx(i),z:this.cz(i),i:i,gen:true,dead:false};this.gens.push(g);for(var k=0;k=0)this.gens.splice(k,1);for(k=0;k0.14} + if(!p.on)p.why='off';else if(!p.src)p.why='power';else if(p.src.gen&&p.src.dead)p.why='wetgen';else if(!p.hose)p.why='hose';else{ + var q=w.pumpRate*dt,got=S.take(p.i,q),nb=[p.i-1,p.i+1,p.i-w.W,p.i+w.W]; + for(var m=0;m<4&&got=0&&iS.g[p.i]+0.004)got+=S.take(i,Math.min(q-got,S.d[i]*AREA*0.5))} + if(got>0){if(w.sink[p.hose.i])w.removed+=got;else S.add(p.hose.i,got)} + p.flow+=(got/dt-p.flow)*0.2;p.run=true;p.why=got>q*0.05?'':'dry';return} + p.flow*=0.8}; + World.DONE=0.03;World.DIGMAX=0.64;World.BARH=0.36;World.T=T;World.CS=CS;World.vnoise=vnoise; + return {World:World,T:T,CS:CS}; +})(); +// The jobs. Sizes are in metres; x runs east, z runs south. Each build() lays out one place. +var EWMaps=(function(){ + var T=EW.T; + function dist(x,z,a,b){return Math.sqrt((x-a)*(x-a)+(z-b)*(z-b))} + var MAPS=[]; + // 1. Marlow Row: a back yard. The patio drain is buried in leaves and the garden tap's pipe has split. + MAPS.push({id:'yard',name:'Marlow Row',sub:'Back yard',w:22,h:18,seed:11,pay:60,par:210,sky:'day', + brief:'The back yard has been under water since the storm, and it is not going down.', + build:function(b){ + b.ground(function(x,z){return 0.016*dist(x,z,8,6.5)+Math.max(0,z-9)*0.04}); + b.surf(0,0,22,9,T.PAVE);b.surf(0,9,22,18,T.GRASS,1);b.surf(17,0,22,3,T.GRAVEL); + b.noise(0.006,1.7,0,0,22,9);b.noise(0.02,2.3,0,9,22,18); + b.wall(0,0,17,3,5.2,0xb9aa94,'house'); + b.wall(17,0,22,0.5,1.9,0x6b5a45,'fence');b.wall(21.5,0,22,18,1.9,0x6b5a45,'fence');b.wall(0,17.5,22,18,1.9,0x6b5a45,'fence');b.wall(0,3,0.5,18,1.9,0x6b5a45,'fence'); + b.wall(16.5,12.5,20.5,16,2.3,0x5d7a6a,'shed'); + b.wall(1,10,3.5,11,0.5,0x7a5a3c,'planter');b.wall(12.5,3,14,3.5,0.55,0x4c5b66,'bin');b.wall(14.5,3,15.5,3.5,0.9,0x3f6b4c,'bin'); + b.wall(5,13.5,6.5,14.5,0.72,0x8a8f93,'table'); + b.drain(8,6.5,{rate:0.13,cap:12}); + b.valve(17.02,1.75,'tap',{nx:1,y:0.8}); + b.leak(4.25,3.25,{rate:0.028,valve:'tap',y:0.75,nz:1,pz:3.02,label:'Garden tap pipe'}); + b.sign(17.02,2.4,'STOP TAP',{nx:1,y:1.35}); + b.litter(8,6.5,0.75,15);b.litter(8,6.5,5,8);b.litter(13,12,5,10);b.litter(4,6,3,4); + b.flood(0,0,22,18,0.235); + b.spawnAt(19.3,1.6,Math.PI); + }}); + return MAPS; +})(); +if(typeof module!=='undefined')module.exports={EWSim:EWSim,EW:EW,EWMaps:EWMaps}; diff --git a/e63334287a3deaa3/ebbwork/game.js b/e63334287a3deaa3/ebbwork/game.js new file mode 100644 index 00000000..f1f6baeb --- /dev/null +++ b/e63334287a3deaa3/ebbwork/game.js @@ -0,0 +1,452 @@ +/* Ebbwork: drawing, controls, HUD and menus. The rules of the water and of every tool are in core.js. */ +(function(){ +'use strict'; +var $=function(id){return document.getElementById(id)}; +function T(s,v){if(window.BackRoomLang)return BackRoomLang.t(s,v);return v?s.replace(/\{(\w+)\}/g,function(m,k){return v[k]}):s} +var CS=EW.CS,FILM=EWSim.FILM,TT=EW.T; +var clamp=function(v,a,b){return vb?b:v}; + +// ---------------------------------------------------------------- saved progress +var SAVE_KEY='ebbwork:v1'; +var save={v:1,coins:0,gear:{rake:1,bucket:1,wrench:1},jobs:{},set:{sens:1,vol:0.8,q:'auto',inv:0},seen:{}}; +(function(){try{var o=JSON.parse(localStorage.getItem(SAVE_KEY)||'null');if(o&&o.v===1){for(var k in o)if(k==='set'||k==='gear'||k==='seen'||k==='jobs'){for(var j in o[k])save[k][j]=o[k][j]}else save[k]=o[k]}}catch(e){}})(); +function persist(){try{localStorage.setItem(SAVE_KEY,JSON.stringify(save))}catch(e){}} + +// ---------------------------------------------------------------- renderer +var touchUI=matchMedia('(pointer: coarse)').matches&&!matchMedia('(any-pointer: fine)').matches; +function setTouch(on){touchUI=on;document.body.classList.toggle('touch',on)} +setTouch(touchUI); +var canvas=$('view'); +var renderer=new THREE.WebGLRenderer({canvas:canvas,antialias:!touchUI,powerPreference:'high-performance'}); +var scene=new THREE.Scene(),camera=new THREE.PerspectiveCamera(74,1,0.06,260); +camera.rotation.order='YXZ';scene.add(camera); +var SKY={zen:new THREE.Color(0x7f97a6),hor:new THREE.Color(0xc5d0d0),fog:new THREE.Color(0xbcc8c9),sun:new THREE.Vector3(-0.45,0.72,0.52).normalize(),sunC:new THREE.Color(0xfff0d8),gnd:new THREE.Color(0x56605a)}; +scene.background=SKY.fog;scene.fog=new THREE.Fog(SKY.fog.getHex(),26,150); +var hemi=new THREE.HemisphereLight(0xd3dde2,0x525c50,0.82);scene.add(hemi); +var sun=new THREE.DirectionalLight(0xfff0d8,0.62);sun.position.copy(SKY.sun).multiplyScalar(50);scene.add(sun); +function quality(){var q=save.set.q;return q==='auto'?(touchUI?'low':'high'):q} +function resize(){var w=innerWidth,h=innerHeight,pr=Math.min(devicePixelRatio||1,quality()==='high'?2:touchUI?1.25:1); + renderer.setPixelRatio(pr);renderer.setSize(w,h,false);camera.aspect=w/h;camera.fov=w>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}})(seed); + for(var k=0;kmx)mx=s} + for(var i=0;i0.02){vec2 q=vW.xz/vP;vec2 f=abs(fract(q)-0.5);float j=smoothstep(0.455,0.492,max(f.x,f.y));vec2 id=floor(q);float h=fract(sin(dot(id,vec2(12.9898,78.233)))*43758.5453);c*=(0.93+0.12*h)*(1.0-0.38*j);}'+ + 'float wet=clamp(vWet,0.0,1.0);c*=mix(1.0,0.60,wet);'+ + 'float dl=max(dot(n,uSun),0.0);vec3 col=c*(mix(uGnd,uSky,n.y*0.5+0.5)*1.05+uSunC*dl*0.62);'+ + 'vec3 V=normalize(uCam-vW);float fr=pow(1.0-max(dot(n,V),0.0),4.0);col+=uSky*fr*wet*0.30;'+ + 'gl_FragColor=vec4(col,1.0);'+FOGF+'}'}); + +var waterMat=new THREE.ShaderMaterial({uniforms:U,transparent:true,depthWrite:false,polygonOffset:true,polygonOffsetFactor:-1,polygonOffsetUnits:-3, + vertexShader:'attribute float aDepth;attribute vec2 aFlow;varying float vD;varying vec2 vF;varying vec3 vW;'+ + 'void main(){vD=aDepth;vF=aFlow;vW=position;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}', + fragmentShader:'precision highp float;uniform sampler2D tN;uniform float uT,uScan,uFogN,uFogF;uniform vec3 uCam,uSun,uSunC,uSky,uHor,uFog;varying float vD;varying vec2 vF;varying vec3 vW;'+ + 'void main(){if(vD<0.004)discard;'+ + 'vec2 uv=vW.xz*0.33;vec2 fl=clamp(vF,-1.6,1.6)*0.55;float sp=length(vF);'+ + 'float p0=fract(uT*0.35),p1=fract(uT*0.35+0.5);'+ + 'vec3 a=texture2D(tN,uv-fl*p0+vec2(uT*0.013,uT*0.009)).rgb;vec3 b=texture2D(tN,uv*1.07+0.37-fl*p1-vec2(uT*0.011,-uT*0.012)).rgb;'+ + 'vec3 m=mix(a,b,abs(1.0-2.0*p0));vec2 nn=m.xy*2.0-1.0;'+ + 'float calm=smoothstep(0.0,0.05,vD);float amp=(0.10+min(sp,1.2)*0.42)*calm;'+ + 'vec3 N=normalize(vec3(nn.x*amp,1.0,nn.y*amp));vec3 V=normalize(uCam-vW);'+ + 'float fres=0.03+0.97*pow(1.0-max(dot(N,V),0.0),5.0);'+ + 'float murk=1.0-exp(-max(vD,0.0)*6.5);'+ + 'vec3 body=mix(vec3(0.42,0.50,0.46),vec3(0.19,0.22,0.17),murk);float al=mix(0.16,0.95,murk);'+ + 'vec3 R=reflect(-V,N);vec3 skyc=mix(uHor,uSky,clamp(R.y*1.6,0.0,1.0));'+ + 'vec3 col=mix(body,skyc,fres*0.82);al=mix(al,1.0,fres*0.75);'+ + 'col+=uSunC*pow(max(dot(R,uSun),0.0),160.0)*0.9;'+ + 'float foam=smoothstep(0.22,0.9,sp)*smoothstep(0.52,0.78,m.b)*calm;col=mix(col,vec3(0.93,0.95,0.92),foam*0.7);al=max(al,foam*0.7);'+ + 'al*=smoothstep(0.004,0.022,vD);'+ + 'float sc=uScan*step(0.0045,vD)*(0.6+0.4*sin(uT*9.0-length(vW.xz-uCam.xz)*1.6));col=mix(col,vec3(0.25,1.0,0.92),sc*0.8);al=max(al,sc*0.85);'+ + 'gl_FragColor=vec4(col,al);'+FOGF+'}'}); + +// ---------------------------------------------------------------- a job site, drawn +var world=null,def=null,lv=null; // lv: this job's meshes and buffers +function Batch(){this.p=[];this.n=[];this.c=[]} +Batch.prototype.quad=function(a,b,c,d,nx,ny,nz,col,sh){var p=this.p,n=this.n,cc=this.c,r=((col>>16)&255)/255*sh,g=((col>>8)&255)/255*sh,bl=(col&255)/255*sh,v=[a,b,c,a,c,d]; + for(var k=0;k<6;k++){p.push(v[k][0],v[k][1],v[k][2]);n.push(nx,ny,nz);cc.push(r,g,bl)}}; +Batch.prototype.box=function(x0,y0,z0,x1,y1,z1,col){ + this.quad([x0,y1,z1],[x1,y1,z1],[x1,y1,z0],[x0,y1,z0],0,1,0,col,1.08); + this.quad([x0,y0,z1],[x1,y0,z1],[x1,y1,z1],[x0,y1,z1],0,0,1,col,1); + this.quad([x1,y0,z0],[x0,y0,z0],[x0,y1,z0],[x1,y1,z0],0,0,-1,col,0.9); + this.quad([x1,y0,z1],[x1,y0,z0],[x1,y1,z0],[x1,y1,z1],1,0,0,col,0.96); + this.quad([x0,y0,z0],[x0,y0,z1],[x0,y1,z1],[x0,y1,z0],-1,0,0,col,0.86)}; +Batch.prototype.mesh=function(){var g=new THREE.BufferGeometry();g.setAttribute('position',new THREE.Float32BufferAttribute(this.p,3));g.setAttribute('normal',new THREE.Float32BufferAttribute(this.n,3));g.setAttribute('color',new THREE.Float32BufferAttribute(this.c,3)); + return new THREE.Mesh(g,new THREE.MeshLambertMaterial({vertexColors:true}))}; +var TYPECOL=[[0.36,0.47,0.25],[0.60,0.59,0.55],[0.33,0.25,0.18],[0.70,0.71,0.68],[0.27,0.28,0.30],[0.52,0.49,0.44],[0.56,0.56,0.54]],TYPEPAT=[0,0.75,0,0.4,0,0,2.5]; +function shade(col,f){var r=Math.min(255,((col>>16)&255)*f)|0,g=Math.min(255,((col>>8)&255)*f)|0,b=Math.min(255,(col&255)*f)|0;return r<<16|g<<8|b} + +function drawBox(B,b){var x0=b.x0,x1=b.x1,z0=b.z0,z1=b.z1,y0=b.y0,y1=b.y1,c=b.col,k,i; + if(b.kind==='house'){B.box(x0,y0,z0,x1,y1,z1,c);B.box(x0-0.25,y1,z0-0.25,x1+0.25,y1+0.22,z1+0.25,0x4a4f55);B.box(x0+0.6,y1+0.22,z0+0.5,x1-0.6,y1+1.3,z1-0.4,0x3f444a); + var gy=y0+0.6;B.box(x0,gy,z1,x1,gy+0.32,z1+0.04,shade(c,0.72)); + for(k=x0+2.2;kz1-z0,len=lx?x1-x0:z1-z0;for(k=1.5;k0?i-1:i],gr=g[x0?i-W:i],gd=g[z0.0015){wp[i*3+1]=zb+dd;wd[i]=dd;S.vel(i,vv);wf[i*2]=vv[0];wf[i*2+1]=vv[1];if(wet[i]<1)wet[i]=Math.min(1,wet[i]+0.2)} + else{var s=0,sd=0,c=0;for(var oz=-1;oz<=1;oz++){var zz=z+oz;if(zz<0||zz>=H)continue;for(var ox=-1;ox<=1;ox++){var xx=x+ox;if(xx<0||xx>=W)continue;j=zz*W+xx;if(!solid[j]&&d[j]>0.004){s+=g[j]+bar[j]+d[j];sd+=d[j];c++}}} + if(c){var y=s/c;wp[i*3+1]=y;wd[i]=solid[i]?sd/c:Math.min(y-zb,0.012)}else{wp[i*3+1]=zb-0.03;wd[i]=-0.03} + wf[i*2]=0;wf[i*2+1]=0;if(wet[i]>0)wet[i]=Math.max(0,wet[i]-0.0006)} + } + lv.wg.attributes.position.needsUpdate=true;lv.wg.attributes.aDepth.needsUpdate=true;lv.wg.attributes.aFlow.needsUpdate=true;lv.tg.attributes.aWet.needsUpdate=true; + if(world.dirty.length){var seen={};world.dirty.forEach(function(i){[i,i-1,i+1,i-W,i+W].forEach(function(k){if(k>=0&&k0.02?1:0)} + for(k=0;kfeet+0.45)return true}return false} +function floorAt(x,z,feet){var w=world,S=w.S,gy=w.groundAt(x,z),ci=w.cell(x,z);if(ci>=0&&S.bar[ci]>0)gy+=S.bar[ci]; + for(var a=-1;a<=1;a+=2)for(var b=-1;b<=1;b+=2){var i=w.cell(x+a*RAD,z+b*RAD);if(i<0)continue;var t=S.solid[i]?w.sh[i]:S.bar[i]>0?S.g[i]+S.bar[i]:-99;if(t<=feet+0.45&&t>gy)gy=t}return gy} +function movePlayer(dt){ + var f=inp.mz,s=inp.mx,l=Math.hypot(f,s);if(l>1){f/=l;s/=l} + var dep=Math.max(0,world.depthAt(pl.x,pl.z)-Math.max(0,pl.y-floorAt(pl.x,pl.z,pl.y))); + var slow=1-Math.min(0.62,dep*(save.gear.waders?0.5:1.25)); + var crouching=inp.crouch;pl.crouch+=((crouching?1:0)-pl.crouch)*Math.min(1,dt*12); + var sp=(crouching?1.9:inp.sprint&&f>0.2?5.7:3.7)*slow; + var sy=Math.sin(pl.yaw),cy=Math.cos(pl.yaw),vx=(-sy*f+cy*s)*sp,vz=(-cy*f-sy*s)*sp; + var nx=pl.x+vx*dt;if(!blocked(nx,pl.z,pl.y))pl.x=nx; + var nz=pl.z+vz*dt;if(!blocked(pl.x,nz,pl.y))pl.z=nz; + var gy=floorAt(pl.x,pl.z,pl.y); + if(pl.ground){if(inp.jump&&!crouching){pl.vy=4.7*(dep>0.35?0.75:1);pl.ground=false;if(dep>0.05)sfx('splash',0.5)}else if(pl.y-gy>0.32){pl.ground=false}else pl.y+=(gy-pl.y)*Math.min(1,dt*18)} + if(!pl.ground){pl.vy-=15*dt;pl.y+=pl.vy*dt;if(pl.y<=gy){pl.y=gy;pl.ground=true;if(pl.vy<-3)sfx(dep>0.04?'splash':'thud',Math.min(1,-pl.vy/8));pl.vy=0}} + inp.jump=false; + var moving=l>0.1&&pl.ground;pl.speed=moving?sp*l:0; + if(moving){pl.bob+=dt*sp*1.9;pl.step+=dt*sp;if(pl.step>1.9){pl.step=0;sfx(dep>0.04?'wade':'step',0.5)}} + pl.dep=dep; + camera.position.set(pl.x,pl.y+EYE-pl.crouch*0.55+(moving?Math.sin(pl.bob)*0.035:0),pl.z);camera.rotation.set(pl.pitch,pl.yaw,0); +} +// where the player is pointing on the ground or the water, within reach +var aim={x:0,y:0,z:0,i:-1,ok:false,dx:0,dz:0}; +function updateAim(reach){ + var cp=Math.cos(pl.pitch),dx=-Math.sin(pl.yaw)*cp,dy=Math.sin(pl.pitch),dz=-Math.cos(pl.yaw)*cp,ox=camera.position.x,oy=camera.position.y,oz=camera.position.z,S=world.S; + aim.dx=-Math.sin(pl.yaw);aim.dz=-Math.cos(pl.yaw);aim.ok=false; + for(var t=0.3;t<=reach;t+=0.12){var x=ox+dx*t,y=oy+dy*t,z=oz+dz*t,i=world.cell(x,z);if(i<0)break; + if(S.solid[i]&&y=0&&!S.solid[hi]){aim.x=hx;aim.z=hz;aim.y=world.groundAt(hx,hz);aim.i=hi;aim.ok=true}} +} +// the nearest fitting the player is looking at +var focus=null,hold=0; +function findFocus(){ + var best=null,bs=0.9,cp=Math.cos(pl.pitch),dx=-Math.sin(pl.yaw)*cp,dy=Math.sin(pl.pitch),dz=-Math.cos(pl.yaw)*cp,c=camera.position; + function tryIt(kind,o,x,y,z,reach){var ex=x-c.x,ey=y-c.y,ez=z-c.z,q=Math.sqrt(ex*ex+ey*ey+ez*ez);if(q>reach)return;var dot=(ex*dx+ey*dy+ez*dz)/q;if(dot>bs){bs=dot;best={kind:kind,o:o}}} + world.valves.forEach(function(v){tryIt('valve',v,v.x+v.nx*0.15,world.groundAt(v.x,v.z)+v.y,v.z+v.nz*0.15,2.4)}); + world.leaks.forEach(function(l){if(l.wrench&&!l.fixed)tryIt('leak',l,l.px,world.groundAt(l.x,l.z)+l.y,l.pz,2.4)}); + return best; +} + +// ---------------------------------------------------------------- tools +var TOOLS={ + rake:{name:'Rake',tip:'Click: push debris away · Right click: pull it to you',ttip:'Use: push · Alt: pull',icon:''}, + bucket:{name:'Bucket',tip:'Click: fill from water, or tip out · Right click: tip out',ttip:'Use: fill or tip out',icon:''}, + wrench:{name:'Wrench',tip:'Hold click on a dripping joint to tighten it',ttip:'Hold Use on a dripping joint',icon:''} +}; +var bar=[],cur=0,bucketVol=0,BUCKET=0.03,swing=0,swingKind=0,useHeld=false,altHeld=false,cool=0; +function tool(){return bar[cur]} +function buildBar(){var h=$('hot');h.innerHTML='';bar.forEach(function(id,k){var t=TOOLS[id],b=document.createElement('button');b.setAttribute('data-no-ad-refresh','');b.setAttribute('aria-label',T(t.name)); + b.innerHTML=''+(k+1)+''+t.icon+''+T(t.name)+''; + b.addEventListener('click',function(e){e.preventDefault();selectTool(k);canvas.focus()});h.appendChild(b)});selectTool(Math.min(cur,bar.length-1))} +function selectTool(k){if(k<0||k>=bar.length)return;cur=k;var bs=$('hot').children;for(var i=0;i0||!id)return;updateAim(2.6); + if(id==='rake'){swing=0.42;swingKind=alt?2:1;cool=0.42;var px=pl.x,pz=pl.z,dx=aim.dx,dz=aim.dz;setTimeout(function(){if(!world)return;var n=world.rake(px,pz,dx,dz,alt);sfx(n?'rake':'swish',n?0.8:0.4);if(n)noteSeen('rake')},130)} + else if(id==='bucket'){cool=0.5;swing=0.4;swingKind=1; + if(bucketVol>0.001&&(alt||bucketVol>=BUCKET*0.5||!aim.ok||world.S.d[aim.i]<0.012)){if(!aim.ok){cool=0;return}var v=world.pour(aim.x,aim.z,bucketVol);if(v>0){bucketVol=0;sfx('pour',0.9)}} + else if(!alt&&aim.ok){var got=world.scoop(aim.x,aim.z,BUCKET-bucketVol);if(got>0.0005){bucketVol+=got;sfx('scoop',0.8)}else toast(T('No water to scoop here.'),1.4)} + } +} +function animView(dt){ + var id=tool(),m=vmods[id];if(!m)return;var b=m.userData.base,t=swing>0?1-swing/0.42:0,s=swing>0?Math.sin(t*Math.PI):0; + var sway=Math.sin(pl.bob)*0.012*(pl.speed>0?1:0); + m.position.set(b.p.x+sway,b.p.y+Math.abs(Math.cos(pl.bob))*0.012*(pl.speed>0?1:0)-0.0,b.p.z);m.rotation.set(b.r.x,b.r.y,b.r.z); + if(id==='rake'){m.rotation.x=b.r.x-s*0.5;m.position.z=b.p.z+(swingKind===2?s*0.22:-s*0.3);m.position.y=b.p.y-s*0.05} + else if(id==='bucket'){m.rotation.x=-s*0.9;m.position.y=b.p.y+s*0.1;m.userData.water.visible=bucketVol>0.002;m.userData.water.position.y=-0.12+0.2*clamp(bucketVol/BUCKET,0,1)} + else if(id==='wrench'){m.rotation.z=b.r.z+(hold>0&&focus&&focus.kind==='leak'?Math.sin(performance.now()*0.012)*0.5:0)} + if(swing>0)swing=Math.max(0,swing-dt);if(cool>0)cool-=dt; +} + +// ---------------------------------------------------------------- sound (filled in later; calls are already in place) +function sfx(){} +function audioTick(){} + +// ---------------------------------------------------------------- HUD +var toastT=0; +function toast(msg,secs){var t=$('toast');t.textContent=msg;t.classList.remove('off');toastT=secs||3} +function fmtTime(s){s=Math.floor(s);return Math.floor(s/60)+':'+(s%60<10?'0':'')+s%60} +var seen={};function noteSeen(k){seen[k]=1} +var scanT=0,scanCool=0; +function scan(){if(state!=='play'||scanCool>0)return;scanT=4.5;scanCool=9;$('scanfx').classList.add('on');sfx('scan',0.7); + toast(world.wet>0?T('{v} litres left on site.',{v:Math.round(world.left*1000)}):T('No standing water found.'),3)} +function tasks(){ + var out=[],w=world; + w.drains.forEach(function(d,k){var found=seen['d'+k];if(!found)out.push({t:T('Find where this water should be draining to'),s:T('Low points are a good place to look.'),done:false}); + else out.push({t:T('Keep the drain clear'),s:d.clear>=0.9?T('Running freely.'):T('{p}% blocked. Rake the debris well away, or it will wash back.',{p:Math.round((1-d.clear)*100)}),done:d.clear>=0.9})}); + w.leaks.forEach(function(l,k){var found=seen['l'+k];if(!found&&l.on)out.push({t:T('Find out if water is still getting in'),s:T('Listen and look along the walls.'),done:false}); + else out.push({t:T('Stop the leak'),s:l.on?(l.valve?T('The pipe is under pressure. Follow it back to a stop tap.'):T('Tighten it with the wrench.')):T('Stopped.'),done:!l.on})}); + var pc=Math.round(w.fraction()*100);out.push({t:T('Get the water under the green mark'),s:T('{p}% left. Small puddles are fine.',{p:pc}),done:w.fraction()<=EW.World.DONE}); + return out; +} +function openJournal(){$('jTitle').textContent=def.name+' · '+T(def.sub);$('jBrief').textContent=T(def.brief); + $('jTasks').innerHTML=tasks().map(function(t){return'
  • '+t.t+''+t.s+'
  • '}).join('');show('journal')} +function updateHud(dt){ + var fr=world.fraction();$('gaugeFill').style.width=clamp(fr*100,0,100).toFixed(1)+'%';$('pct').textContent=Math.round(fr*100)+'%';$('clock').textContent=fmtTime(world.t); + $('inflow').hidden=!world.incoming(); + if(toastT>0){toastT-=dt;if(toastT<=0)$('toast').classList.add('off')} + if(scanT>0){scanT-=dt;if(scanT<=0)$('scanfx').classList.remove('on')}if(scanCool>0)scanCool-=dt; + U.uScan.value+=((scanT>0?1:0)-U.uScan.value)*Math.min(1,dt*5); + var u=$('hot').children;for(var k=0;k0.001?Math.round(bucketVol*1000)+'L':''; + // discoveries, for the journal and the hints + world.drains.forEach(function(d,k){if(!seen['d'+k]&&Math.hypot(d.x-pl.x,d.z-pl.z)<3.2){seen['d'+k]=1;toast(d.clear<0.5?T('A drain, buried in debris. That is one reason the water is staying.'):T('A drain.'),4)}}); + world.leaks.forEach(function(l,k){if(!seen['l'+k]&&l.on&&Math.hypot(l.x-pl.x,l.z-pl.z)<4.5){seen['l'+k]=1;toast(T('Water is pouring out of a split pipe here. It will not drain while this runs.'),4.5)}}); + // prompt + focus=findFocus();var p=$('prompt'),act=touchUI?T('Hold Do'):T('Hold E'); + if(focus){var txt='';if(focus.kind==='valve')txt=act+': '+(focus.o.closed?T('open the stop tap'):T('shut the stop tap'));else if(focus.kind==='leak')txt=tool()==='wrench'?(touchUI?T('Hold Use'):T('Hold click'))+': '+T('tighten the joint'):T('Needs the wrench'); + $('promptTx').textContent=txt;p.hidden=false;$('promptBar').hidden=hold<=0;$('promptBar').firstChild.style.width=clamp(hold,0,1)*100+'%'}else{p.hidden=true;hold=0} + $('cross').classList.toggle('act',!!focus);$('tAct').hidden=!(focus&&focus.kind==='valve'); + // holding E on a fitting + var working=focus&&((focus.kind==='valve'&&inp.act)||(focus.kind==='leak'&&tool()==='wrench'&&useHeld)); + if(working){hold+=dt/(focus.kind==='valve'?1.0:1.8);if(hold>=1){hold=0;inp.act=false;if(focus.kind==='valve'){world.setValve(focus.o,!focus.o.closed);sfx('valve',0.9);toast(focus.o.closed?T('Stop tap shut.'):T('Stop tap open.'),2.2)}else{world.fixLeak(focus.o);sfx('valve',0.8);toast(T('Joint tightened.'),2.2)}}} + else if(hold>0)hold=Math.max(0,hold-dt*2); +} + +// ---------------------------------------------------------------- screens +var state='menu',selJob=EWMaps[0].id,endT=0; +var PANELS=['menu','pause','settings','how','journal','result'],backTo=null; +function show(id){PANELS.forEach(function(p){$(p).hidden=p!==id});if(id&&document.pointerLockElement)document.exitPointerLock()} +function starsHtml(n){return'★'.repeat(n)+''+'★'.repeat(3-n)+''} +function buildMenu(){var h=$('jobList');h.innerHTML='';EWMaps.forEach(function(m){var b=document.createElement('button');b.className='job';b.setAttribute('aria-pressed',m.id===selJob?'true':'false');var r=save.jobs[m.id]; + b.innerHTML='
    '+m.name+''+T(m.sub)+'
    '+starsHtml(r?r.stars:0)+'';b.addEventListener('click',function(){selJob=m.id;buildMenu()});h.appendChild(b)})} +function startJob(id){ + if(lv){scene.remove(lv.grp);lv.grp.traverse(function(o){if(o.geometry)o.geometry.dispose()});lv=null} + def=EWMaps.filter(function(m){return m.id===id})[0];world=new EW.World(def,{});lv=buildLevel(world); + pl.x=world.spawn.x;pl.z=world.spawn.z;pl.y=world.groundAt(pl.x,pl.z);pl.yaw=world.spawn.yaw;pl.pitch=0;pl.vy=0;pl.ground=true; + bar=['rake','bucket','wrench'].filter(function(t){return save.gear[t]});cur=0;bucketVol=0;seen={};endT=0;scanT=0;scanCool=0;hold=0;acc=0; + buildBar();$('plName').textContent=def.name;$('hud').hidden=false;updateWaterMesh(); + state='play';show(null);lockPointer();toast(T(def.brief),5); +} +function finishJob(){ + state='result';var t=world.t,fr=world.fraction(),stars=1+(t<=def.par*1.6?1:0)+(t<=def.par&&fr<=0.015?1:0),pay=Math.round(def.pay*(0.6+0.2*stars)); + var r=save.jobs[def.id]||{stars:0,best:0,n:0};var first=!r.n;r.n++;r.stars=Math.max(r.stars,stars);r.best=r.best?Math.min(r.best,Math.round(t)):Math.round(t);save.jobs[def.id]=r;save.coins+=pay;persist(); + $('rStars').innerHTML=starsHtml(stars); + $('rSum').innerHTML=''+T('Time')+''+fmtTime(t)+''+T('Water left')+''+(fr*100).toFixed(1)+'%'+T('Pay')+''+pay+' ◈'+T('Your coins')+''+save.coins+' ◈'; + void first;show('result');sfx('done',1); +} +function pause(){if(state!=='play')return;state='pause';show('pause')} +function resume(){if(state!=='pause')return;state='play';show(null);lockPointer()} +function quit(){state='menu';$('hud').hidden=true;buildMenu();show('menu')} +function lockPointer(){if(!touchUI&&canvas.requestPointerLock){try{var p=canvas.requestPointerLock();if(p&&p.catch)p.catch(function(){})}catch(e){}}canvas.focus()} +document.addEventListener('pointerlockchange',function(){if(!document.pointerLockElement&&state==='play'&&!touchUI&&$('journal').hidden)pause()}); +$('bStart').onclick=function(){startJob(selJob)}; +$('bResume').onclick=resume;$('bQuit').onclick=quit;$('bRestart').onclick=function(){startJob(def.id)}; +$('bAgain').onclick=function(){startJob(def.id)};$('bBack').onclick=quit; +function openSub(id){backTo=state==='menu'?'menu':'pause';if(state==='play')state='pause';if(id==='journal')openJournal();else show(id)} +$('bSet1').onclick=$('bSet2').onclick=function(){openSub('settings')};$('bHow').onclick=$('bHow2').onclick=function(){openSub('how')}; +$('bJournal').onclick=$('bJournal2').onclick=function(){openSub('journal')}; +$('bSetDone').onclick=$('bHowDone').onclick=function(){show(backTo)}; +$('bJDone').onclick=function(){if(backTo==='pause'&&$('pause').dataset.from!=='menu'){state='pause';resume()}else show(backTo)}; +$('bPause').onclick=pause;$('bScan').onclick=function(){scan();canvas.focus()}; +$('bFull').onclick=function(){var d=document;if(d.fullscreenElement)d.exitFullscreen();else if(d.documentElement.requestFullscreen)d.documentElement.requestFullscreen().catch(function(){})}; +// settings +function seg(id,key,after){var el=$(id);function paint(){[].forEach.call(el.children,function(b){b.setAttribute('aria-pressed',String(save.set[key])===b.dataset.v?'true':'false')})} + [].forEach.call(el.children,function(b){b.onclick=function(){save.set[key]=isNaN(+b.dataset.v)?b.dataset.v:+b.dataset.v;persist();paint();if(after)after()}});paint()} +$('sSens').value=save.set.sens;$('sVol').value=save.set.vol; +$('sSens').oninput=function(){save.set.sens=+this.value;persist()};$('sVol').oninput=function(){save.set.vol=+this.value;persist();audioTick(0)}; +seg('sQ','q',resize);seg('sInv','inv'); + +// ---------------------------------------------------------------- keyboard and mouse +addEventListener('keydown',function(e){ + if(e.target&&e.target.tagName==='INPUT')return;keys[e.code]=true; + if(state==='play'){ + if(e.code==='Space'){inp.jump=true;e.preventDefault()} + else if(e.code==='Tab'||e.code==='KeyJ'){e.preventDefault();openSub('journal')} + else if(e.code==='KeyF')scan(); + else if(e.code==='KeyE')inp.act=true; + else if(e.code==='KeyP')pause(); + else if(/^Digit[1-9]$/.test(e.code))selectTool(+e.code.slice(5)-1); + }else if(e.code==='Escape'||e.code==='Tab'||e.code==='KeyJ'){ + if(!$('journal').hidden){e.preventDefault();$('bJDone').onclick()}else if(state==='pause'&&!$('pause').hidden&&e.code==='Escape')resume(); + } +}); +addEventListener('keyup',function(e){keys[e.code]=false;if(e.code==='KeyE')inp.act=false}); +addEventListener('blur',function(){keys={};useHeld=altHeld=false;inp.act=false}); +document.addEventListener('mousemove',function(e){if(document.pointerLockElement!==canvas||state!=='play')return;var s=0.0022*save.set.sens;pl.yaw-=e.movementX*s;pl.pitch=clamp(pl.pitch-e.movementY*s*(save.set.inv?-1:1),-1.5,1.5)}); +canvas.addEventListener('mousedown',function(e){if(touchUI||state!=='play')return;if(document.pointerLockElement!==canvas){lockPointer();return} + if(e.button===0){useHeld=true;useTool(false)}else if(e.button===2){altHeld=true;useTool(true)}}); +addEventListener('mouseup',function(e){if(e.button===0)useHeld=false;else if(e.button===2)altHeld=false}); +canvas.addEventListener('contextmenu',function(e){e.preventDefault()}); +canvas.addEventListener('wheel',function(e){if(state!=='play')return;e.preventDefault();selectTool((cur+(e.deltaY>0?1:-1)+bar.length)%bar.length)},{passive:false}); +function readKeys(){if(touchUI)return;inp.mz=(keys.KeyW||keys.ArrowUp?1:0)-(keys.KeyS||keys.ArrowDown?1:0);inp.mx=(keys.KeyD||keys.ArrowRight?1:0)-(keys.KeyA||keys.ArrowLeft?1:0); + inp.sprint=!!(keys.ShiftLeft||keys.ShiftRight);inp.crouch=!!(keys.KeyC||keys.ControlLeft)} + +// ---------------------------------------------------------------- touch +(function(){ + var stick=$('stick'),nub=stick.firstElementChild,sid=null,sx=0,sy=0,lid=null,lx=0,ly=0; + addEventListener('touchstart',function(){if(!touchUI){setTouch(true);resize();if(state==='play')buildBar()}},{passive:true,once:true}); + function setStick(dx,dy){var m=Math.hypot(dx,dy),mx=46;if(m>mx){dx*=mx/m;dy*=mx/m}nub.style.transform='translate('+dx+'px,'+dy+'px)';inp.mx=dx/mx;inp.mz=-dy/mx;inp.sprint=m>mx*1.25} + canvas.addEventListener('touchstart',function(e){if(state!=='play')return;e.preventDefault();for(var k=0;kinnerHeight*0.38){sid=t.identifier;sx=t.clientX;sy=t.clientY;stick.style.left=(sx-59)+'px';stick.style.top=(sy-59)+'px';stick.style.bottom='auto';setStick(0,0)} + else if(lid===null){lid=t.identifier;lx=t.clientX;ly=t.clientY}}},{passive:false}); + canvas.addEventListener('touchmove',function(e){e.preventDefault();for(var k=0;k=STEP&&n<3){world.step(STEP);acc-=STEP;n++}if(n){updateWaterMesh();simMs+=(performance.now()-t0-simMs)*0.1}if(acc>STEP)acc=0; + if(useHeld&&tool()==='rake')useTool(false);if(altHeld&&tool()==='rake')useTool(true); + updateThings(dt,now/1000);animView(dt);updateHud(dt);audioTick(dt); + if(world.isDone()){endT+=dt;if(endT>2.5)finishJob()}else endT=0; + } + if(state==='menu'&&!lv)return; + if(state==='menu')return; + U.uT.value=now/1000;U.uCam.value.copy(camera.position); + renderer.render(scene,camera); +} +buildMenu();show('menu');requestAnimationFrame(frame); +// for tests and tuning from the console +window.__ew={ff:function(sec){for(var k=0;k + + + + + +Ebbwork + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + + + + + + + From afdf9f25dafdf867be45916edd61fa45c7a82fc6 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 02:48:41 +0000 Subject: [PATCH 2/6] Ebbwork: depot, shop, six jobs and the rest of the tools (still work in progress) Adds the depot (job board, gear bench, van), five more jobs, and the shovel, squeegee, sandbags, pump with power and hose, generator and debris sack, plus sound made in code and a first-job walkthrough. Still not linked from anywhere on the site. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01Cw2rM7oof2mCeBWM93T7t4 --- e63334287a3deaa3/ebbwork/core.js | 140 +++++++- e63334287a3deaa3/ebbwork/game.js | 499 ++++++++++++++++++++-------- e63334287a3deaa3/ebbwork/index.html | 64 +++- 3 files changed, 547 insertions(+), 156 deletions(-) diff --git a/e63334287a3deaa3/ebbwork/core.js b/e63334287a3deaa3/ebbwork/core.js index 37190c69..2f936927 100644 --- a/e63334287a3deaa3/ebbwork/core.js +++ b/e63334287a3deaa3/ebbwork/core.js @@ -132,9 +132,9 @@ var EW=(function(){ w.sink=new Uint8Array(n); // 1 = water here leaves the map (ditch, river outfall) w.hold=new Float32Array(n).fill(-1e9); // >-1e8: a river cell held at this surface level w.g0=null;w.boxes=[];w.drains=[];w.leaks=[];w.valves=[];w.debris=[];w.pumps=[];w.barriers=[];w.sockets=[];w.gens=[]; - w.signs=[];w.sinkList=[];w.holdList=[];w.dirty=[];w.spoil=0;w.t=0;w.tick=0;w.removed=0;w.added=0;w.holdIn=0;w._hin=0; + w.signs=[];w.stations=[];w.spots=[];w.sinkList=[];w.holdList=[];w.dirty=[];w.spoil=0;w.t=0;w.tick=0;w.removed=0;w.added=0;w.holdIn=0;w._hin=0; w.spawn={x:def.w/2,z:def.h/2,yaw:0};w.rand=mulberry(def.seed||7); - w.hoseLen=opt.hoseLen||9;w.cableLen=opt.cableLen||8;w.pumpRate=opt.pumpRate||0.085; + w.hoseLen=opt.hoseLen||9;w.cableLen=opt.cableLen||8;w.pumpRate=opt.pumpRate||0.16; def.build(w); w.g0=new Float32Array(S.g); for(var i=0;i-1e8){w.holdList.push(i);w.mask[i]=0}if(S.solid[i])w.mask[i]=0} @@ -165,6 +165,7 @@ var EW=(function(){ var b={x0:x0,z0:z0,x1:x1,z1:z1,y0:lo-0.6,y1:lo+h,col:col,kind:kind||'wall'};w.boxes.push(b);return b}; // drawn only, no collision (y0,y1 are above the ground at its centre) P.box=function(x0,z0,x1,z1,y0,y1,col,kind){var gy=this.groundAt((x0+x1)/2,(z0+z1)/2);var b={x0:x0,z0:z0,x1:x1,z1:z1,y0:gy+y0,y1:gy+y1,col:col,kind:kind||'deco'};this.boxes.push(b);return b}; + P.boxAbs=function(x0,z0,x1,z1,y0,y1,col,kind){var b={x0:x0,z0:z0,x1:x1,z1:z1,y0:y0,y1:y1,col:col,kind:kind||'deco'};this.boxes.push(b);return b}; P.drain=function(x,z,o){o=o||{};var d={x:x,z:z,i:this.cell(x,z),rate:o.rate||0.12,cap:o.cap||10,clear:1,flow:0,n:0,kind:o.kind||'grate'};this.drains.push(d);return d}; P.sinkArea=function(x0,z0,x1,z1){var w=this;w.each(x0,z0,x1,z1,function(i){w.sink[i]=1})}; P.noJob=function(x0,z0,x1,z1){var w=this;w.each(x0,z0,x1,z1,function(i){w.mask[i]=0})}; @@ -174,6 +175,9 @@ var EW=(function(){ P.leak=function(x,z,o){o=o||{};var l={x:x,z:z,i:this.cell(x,z),rate:o.rate||0.02,valve:o.valve||null,wrench:!!o.wrench,fixed:false,on:true,y:o.y==null?0.7:o.y,nx:o.nx||0,nz:o.nz||0,px:o.px==null?x:o.px,pz:o.pz==null?z:o.pz,label:o.label||''};this.leaks.push(l);return l}; P.valve=function(x,z,id,o){o=o||{};var v={x:x,z:z,id:id,closed:false,y:o.y==null?0.9:o.y,nx:o.nx||0,nz:o.nz||0,turn:0};this.valves.push(v);return v}; P.socket=function(x,z,o){o=o||{};var s={x:x,z:z,y:o.y==null?1.0:o.y,nx:o.nx||0,nz:o.nz||0};this.sockets.push(s);return s}; + P.station=function(x,z,kind,o){o=o||{};this.stations.push({x:x,z:z,kind:kind,y:o.y==null?1.2:o.y,nx:o.nx||0,nz:o.nz||0})}; + // something the player notices when they get near (r metres): shown once and kept in the journal + P.spot=function(x,z,r,text){this.spots.push({x:x,z:z,r:r,text:text,seen:false})}; P.sign=function(x,z,text,o){o=o||{};this.signs.push({x:x,z:z,text:text,y:o.y==null?1.4:o.y,nx:o.nx||0,nz:o.nz||0})}; P.litter=function(x,z,r,n,kind){var w=this;for(var k=0;k2.7)continue;var along=(ex*dx+ez*dz);if(q>0.5&&along/q<0.72)continue;if(along<-0.2)continue; var s=pull?-1:1,side=(ex*-dz+ez*dx);p.vx=s*dx*5.2+(-dz)*side*0.8+(w.rand()-0.5)*0.6;p.vz=s*dz*5.2+dx*side*0.8+(w.rand()-0.5)*0.6;p.kick=0.6;n++} return n}; + P.takeDebris=function(x,z,r,max){var w=this,out=[];for(var j=w.debris.length-1;j>=0&&out.length0.001){cells.push(i);tot+=S.d[i]*AREA}}); if(tot<=0)return 0;var take=Math.min(cap,tot*0.95),got=0;for(var k=0;k-1e8){this.removed+=vol;return vol}return this.S.add(i,vol)}; P.canDig=function(x,z){var i=this.cell(x,z);return i>=0&&this.soft[i]&&!this.S.solid[i]&&!this.S.bar[i]&&this.S.g[i]>this.g0[i]-World.DIGMAX+0.01}; P.dig=function(x,z){var w=this,S=w.S,i=w.cell(x,z);if(!w.canDig(x,z))return false; S.g[i]=Math.max(w.g0[i]-World.DIGMAX,S.g[i]-0.16);w.type[i]=T.SOIL;w.spoil++;w.dirty.push(i);S.wake(i); @@ -256,7 +261,7 @@ var EW=(function(){ // barrier: three cells in a row; rot 0..3 = along x, diagonal, along z, other diagonal var BD=[[1,0],[1,1],[0,1],[-1,1]]; P.barrierCells=function(x,z,rot){var w=this,cx=Math.floor(x/CS),cz=Math.floor(z/CS),o=BD[rot&3],out=[]; - for(var k=-1;k<=1;k++){var ax=cx+o[0]*k,az=cz+o[1]*k;if(ax<0||az<0||ax>=w.W||az>=w.H)return null;var i=az*w.W+ax;if(w.S.solid[i]||w.S.bar[i]>0||w.sink[i])return null; + for(var k=-1;k<=1;k++){var ax=cx+o[0]*k,az=cz+o[1]*k;if(ax<0||az<0||ax>=w.W||az>=w.H)return null;var i=az*w.W+ax;if(w.S.solid[i]||w.S.bar[i]>0||w.sink[i]||w.hold[i]>-1e8)return null; for(var q=0;q=0)this.gens.splice(k,1);for(k=0;k0.14} if(!p.on)p.why='off';else if(!p.src)p.why='power';else if(p.src.gen&&p.src.dead)p.why='wetgen';else if(!p.hose)p.why='hose';else{ var q=w.pumpRate*dt,got=S.take(p.i,q),nb=[p.i-1,p.i+1,p.i-w.W,p.i+w.W]; for(var m=0;m<4&&got=0&&iS.g[p.i]+0.004)got+=S.take(i,Math.min(q-got,S.d[i]*AREA*0.5))} - if(got>0){if(w.sink[p.hose.i])w.removed+=got;else S.add(p.hose.i,got)} + if(got>0){if(w.sink[p.hose.i]||w.hold[p.hose.i]>-1e8){w.removed+=got;p.away=true}else{S.add(p.hose.i,got);p.away=false}} p.flow+=(got/dt-p.flow)*0.2;p.run=true;p.why=got>q*0.05?'':'dry';return} p.flow*=0.8}; World.DONE=0.03;World.DIGMAX=0.64;World.BARH=0.36;World.T=T;World.CS=CS;World.vnoise=vnoise; @@ -290,7 +296,7 @@ var EWMaps=(function(){ function dist(x,z,a,b){return Math.sqrt((x-a)*(x-a)+(z-b)*(z-b))} var MAPS=[]; // 1. Marlow Row: a back yard. The patio drain is buried in leaves and the garden tap's pipe has split. - MAPS.push({id:'yard',name:'Marlow Row',sub:'Back yard',w:22,h:18,seed:11,pay:60,par:210,sky:'day', + MAPS.push({id:'yard',name:'Marlow Row',sub:'Back yard',w:22,h:18,seed:11,pay:60,par:300,sky:'day', brief:'The back yard has been under water since the storm, and it is not going down.', build:function(b){ b.ground(function(x,z){return 0.016*dist(x,z,8,6.5)+Math.max(0,z-9)*0.04}); @@ -307,8 +313,130 @@ var EWMaps=(function(){ b.sign(17.02,2.4,'STOP TAP',{nx:1,y:1.35}); b.litter(8,6.5,0.75,15);b.litter(8,6.5,5,8);b.litter(13,12,5,10);b.litter(4,6,3,4); b.flood(0,0,22,18,0.235); + b.spot(4.25,4.5,3.5,'The garden tap\'s pipe has split. Its supply pipe runs off along the wall towards the side passage.'); b.spawnAt(19.3,1.6,Math.PI); }}); + function bump(u){return u<-1||u>1?0:1-u*u} + // 2. Pell Street: shops, a forecourt, and a road whose gullies have vanished under the storm's leftovers. + MAPS.push({id:'street',name:'Pell Street',sub:'Shop fronts',w:24,h:20,seed:23,pay:110,par:300,sky:'day',needs:['rake','wrench'], + brief:'The road outside the shops is a pond and the loading bay has filled to the brim.', + build:function(b){ + b.ground(function(x,z){ + if(z>=13)return 0.03+0.02*Math.abs(z-13.4)+0.004*Math.min(Math.abs(x-5),Math.abs(x-19)); + var f=0.34-0.012*(z-3);if(z>12.5)return f-(z-12.5)*2*(f-0.04); + if(x>14.5&&x<19.5&&z>4.5&&z<11){if(z<8.5)return -0.12;return -0.12+(z-8.5)/2.5*(f+0.12)} + return f}); + b.surf(0,0,24,13,T.PAVE);b.surf(0,13,24,20,T.ROAD);b.surf(14.5,4.5,19.5,11,T.CONC); + b.shape(6,6.5,10,9.5,function(x,z,g){return g-0.05*bump(dist(x,z,8,8)/1.6)}); + b.noise(0.005,1.9); + b.wall(0,0,12,3,5.4,0xa89a86,'house');b.wall(12,0,24,3,6.0,0x8f8f97,'house'); + b.wall(0,3,0.5,20,2.2,0x3d5a73,'fence');b.wall(23.5,3,24,20,2.2,0x3d5a73,'fence');b.wall(0,19.5,24,20,5.0,0x9b8f80,'houseN'); + b.wall(2,3,3.5,3.5,0.9,0x3f6b4c,'bin');b.wall(9,3,10,4,0.75,0x7a5a3c,'planter');b.wall(15,5,16,6,0.7,0x8a6a3a,'crate');b.wall(18.5,4.5,19.5,5.5,1.0,0x7b6a55,'crate'); + b.wall(14,4,14.5,8.5,1.0,0x6d7478,'rail');b.wall(19.5,4,20,8.5,1.0,0x6d7478,'rail');b.wall(14,4,20,4.5,1.0,0x6d7478,'rail'); + b.drain(5,13.4,{rate:0.15,cap:12});b.drain(19,13.4,{rate:0.15,cap:12});b.drain(17,6.5,{rate:0.05,cap:8}); + b.leak(16.75,4.75,{rate:0.012,wrench:true,y:1.1,nz:1,pz:4.52,label:'Dripping joint'}); + b.litter(5,13.4,0.75,15);b.litter(19,13.4,0.75,14);b.litter(17,6.5,0.7,10);b.litter(12,15,7,16);b.litter(17,7,2,5); + b.flood(0,0,24,20,0.25);b.flood(6,6.5,10,9.5,0.275); + b.spot(17,9.5,3,'The loading bay is lower than everything around it. It has a small drain of its own somewhere under that water.');b.spot(8,8,2.2,'A dip in the paving. It will hold a puddle whatever the drains do.');b.spot(12,13.4,4,'A road like this has gullies along the kerb. None are showing.'); + b.spawnAt(2,9,-Math.PI/2); + }}); + // 3. Tanners Field: allotments in a hollow. No drain at all: the only way out is over, or through, the bank. + MAPS.push({id:'field',name:'Tanners Field',sub:'Allotments',w:34,h:24,seed:31,pay:160,par:660,sky:'day',needs:['shovel','rake'], + brief:'The allotments sit in a hollow. The water came in and has nowhere to go.', + build:function(b){ + b.ground(function(x,z){if(x>=30.5)return -0.6;var g=0.30+0.013*dist(x,z,20,12)+0.42*bump((x-28.25)/1.75);if(x>30)g=g+(x-30)*2*(-0.6-g);return g}); + b.surf(0,0,34,24,T.GRASS,1); + for(var k=0;k<4;k++)for(var j=0;j<3;j++)b.surf(3+k*6,5+j*6,7.5+k*6,9.5+j*6,T.SOIL,1); + b.surf(30.5,0,34,24,T.GRAVEL,0); + b.noise(0.014,2.2,0,0,30,24); + b.wall(0,0,34,0.5,1.6,0x4b6a3e,'hedge');b.wall(0,23.5,34,24,1.6,0x4b6a3e,'hedge');b.wall(0,0.5,0.5,23.5,1.6,0x4b6a3e,'hedge');b.wall(33.5,0.5,34,23.5,1.6,0x4b6a3e,'hedge'); + b.wall(2,1,6,3,2.2,0x6f5b47,'shed');b.wall(8,1,9,2,1.1,0x3e6f8a,'butt');b.wall(12,1,14,2.5,0.9,0x6a563f,'crate');b.wall(1,18,2.5,21,1.0,0x6a563f,'crate'); + b.sinkArea(30.5,0.5,33.5,23.5); + b.drain(26.25,18.25,{rate:0.05,cap:9,kind:'culvert'}); + b.valve(6.02,2,'sp',{nx:1,y:0.8});b.leak(6.75,2.25,{rate:0.03,valve:'sp',y:0.7,nx:1,px:6.02,pz:2.5,label:'Standpipe'}); + b.sign(6.02,1.4,'STANDPIPE',{nx:1,y:1.4}); + b.litter(26.25,18.25,0.75,12);b.litter(20,12,8,14); + b.flood(0,0,30,24,0.47); + b.spot(20,12,4,'The lowest point of the field, and there is no drain anywhere on it.');b.spot(28,12,3,'A bank. On the far side the ground drops into a ditch that is nearly empty.');b.spot(26.25,18.25,3,'A small pipe runs under the bank here. It is choked, and it sits too high to empty the middle of the field.'); + b.spawnAt(4,5,Math.PI*0.75+Math.PI); + }}); + // 4. Fenny Underpass: the road dips under a bridge. The sump pump is dead, so nothing leaves by itself. + MAPS.push({id:'under',name:'Fenny Underpass',sub:'Road under the bridge',w:12,h:30,seed:41,pay:220,par:380,sky:'day',needs:['pump','rake'], + brief:'The road under the bridge is shut. The council says its pump has given up.', + build:function(b){ + b.ground(function(x,z){var u=(z-15)/8;if(u>-1&&u<1)return -0.9*(1-u*u);if(z<=7)return -0.03*(7-z);return 0.02*(z-23)}); + b.surf(0,0,12,30,T.ROAD);b.surf(1.5,0,2.5,30,T.CONC);b.surf(9.5,0,10.5,30,T.CONC); + b.noise(0.004,1.8); + b.wall(0,0,1.5,30,3.6,0x8a8478,'wall');b.wall(10.5,0,12,30,3.6,0x8a8478,'wall');b.wall(1.5,0,10.5,0.5,1.1,0xd9b53a,'barrier');b.wall(1.5,29.5,10.5,30,1.1,0xd9b53a,'barrier'); + b.boxAbs(0,11.5,12,18.5,3.3,4.3,0x6f7478,'deck');b.boxAbs(0,11.5,12,11.8,2.7,3.3,0x5d6266,'deck');b.boxAbs(0,18.2,12,18.5,2.7,3.3,0x5d6266,'deck'); + b.sinkArea(1.5,0.5,10.5,1.5); + b.drain(9.25,15.25,{rate:0.03,cap:8}); + b.socket(1.52,9.5,{nx:1,y:1.1}); + b.valve(10.48,26,'main',{nx:-1,y:0.9});b.leak(9.75,19.25,{rate:0.03,valve:'main',y:1.0,nx:-1,px:10.48,pz:19.25,label:'Water main'}); + b.sign(10.48,26.7,'WATER MAIN',{nx:-1,y:1.4});b.sign(9.9,15.25,'PUMP OUT OF ORDER',{nx:-1,y:1.5});b.sign(1.52,10.2,'POWER',{nx:1,y:1.45}); + b.litter(9.25,15.25,0.7,10);b.litter(6,15,4,12); + b.flood(1.5,7,10.5,23,-0.42); + b.spot(6,10,2.5,'The road dips under the bridge and climbs out again. Whatever leaves this water has to be lifted out.');b.spot(6,5,2.5,'A storm channel crosses the road up here. Water that reaches it is gone for good.');b.spot(6,24,3,'This end slopes back down towards the bridge.'); + b.spawnAt(6,3.5,Math.PI); + }}); + // 5. Wharf Cellar: below the river's level. Water seeps in through the light well as fast as you take it out. + MAPS.push({id:'cellar',name:'Wharf Cellar',sub:'Warehouse cellar',w:16,h:14,seed:53,pay:280,par:400,sky:'cellar',needs:['pump','sandbags','wrench'], + brief:'The cellar under the old wharf keeps filling. The owner has bailed it twice already.', + build:function(b){ + b.ground(function(x,z){if(x>=9.5&&x<11.5&&z<5){return z<1.5?1.5:0.07+(5-z)/3.5*1.43}if(x>=12)return 0;return 0.02*dist(x,z,7,8.5)}); + b.surf(0,0,16,14,T.CONC);b.surf(0.5,5,11.5,13.5,T.TILE);b.surf(12,5,15.5,13.5,T.GRAVEL); + b.noise(0.004,1.6,0.5,0.5,11.5,13.5); + b.wall(0,0,16,0.5,2.7,0x7d7468,'wall');b.wall(0,13.5,16,14,2.7,0x7d7468,'wall');b.wall(0,0.5,0.5,13.5,2.7,0x7d7468,'wall');b.wall(15.5,0.5,16,13.5,2.7,0x7d7468,'wall'); + b.wall(9,0.5,9.5,5,2.7,0x857b6e,'wall');b.wall(11.5,0.5,16,5,2.7,0x857b6e,'wall'); + b.wall(0.5,4.5,3,5,2.7,0x857b6e,'wall');b.wall(4,4.5,9,5,2.7,0x857b6e,'wall'); + b.wall(11.5,5,12,8,2.7,0x857b6e,'wall');b.wall(11.5,9.5,12,13.5,2.7,0x857b6e,'wall'); + b.wall(1,10.5,2.5,12.5,1.0,0x7b6a55,'crate');b.wall(3,12,4,13,0.7,0x8a6a3a,'crate');b.wall(5.5,1,7.5,2,1.5,0x6d7478,'boiler');b.wall(1,5.5,1.5,7.5,1.6,0x5b4a3a,'crate'); + b.boxAbs(0,0,16,14,2.7,2.9,0x4c4740,'ceil'); + b.river(12.5,5,15.5,13.5,0.30);b.noJob(12,5,15.5,13.5); + b.sinkArea(9.5,0.5,11.5,1); + b.socket(8.5,5.02,{nz:1,y:1.2});b.sign(8.5,5.02,'POWER',{nz:1,y:1.55});b.sign(6.2,13.48,'SUMP PUMP: BROKEN',{nz:-1,y:1.4}); + b.leak(1.25,2.75,{rate:0.01,wrench:true,y:1.2,nx:1,px:0.52,pz:2.75,label:'Dripping joint'}); + b.litter(7,8.5,4,10); + b.flood(0.5,0.5,12,13.5,0.30); + b.spot(11,8.75,2.2,'A doorway into the light well. The river seeps into the well, and from there into here.');b.spot(7,8.5,2.2,'The floor falls to this point. The pump that used to sit here is broken.');b.spot(10.5,2.2,2,'A street gully at the top of the steps. Good place for a hose end.'); + b.spawnAt(10.5,1.6,Math.PI); + }}); + // 6. Mill Lane: the stream has broken its bank and is still coming. + MAPS.push({id:'mill',name:'Mill Lane',sub:'Lane by the stream',w:30,h:24,seed:67,pay:400,par:1050,sky:'day',needs:['sandbags','rake','pump','generator','shovel'], + brief:'The mill stream is through its bank and the whole lane is under. Start with whatever is still feeding it.', + build:function(b){ + b.ground(function(x,z){ + if(z<3.5)return 0; + if(z<6){var gap=x>17&&x<20;return gap?0.22:0.30+0.75*bump((z-4.75)/1.25)} + var g=0.30-0.0065*x+0.004*Math.abs(z-14); + if(x>1&&x<8&&z>14&&z<22)return -0.15; + var hd=dist(x,z,21,20);if(hd<3.5)g-=0.12*bump(hd/3.5);var cd=dist(x,z,28.25,15.25);if(cd<1.6)g-=0.2*bump(cd/1.6); + return g}); + b.surf(0,0,30,24,T.GRASS,1);b.surf(0,0,30,3.5,T.GRAVEL,0);b.surf(0,9,30,13,T.ROAD,0);b.surf(1,14,8,22,T.PAVE,0);b.surf(18,16.5,26,23.5,T.SOIL,1); + b.noise(0.01,2.1,0,6,30,24); + b.wall(0,0,0.5,24,2.0,0x6e6a62,'wall');b.wall(29.5,0,30,24,2.0,0x6e6a62,'wall');b.wall(0.5,23.5,29.5,24,1.8,0x4b6a3e,'hedge');b.wall(0.5,0,29.5,0.5,1.4,0x4b6a3e,'hedge'); + b.wall(0.5,13.5,8.5,14,1.7,0x9a7b63,'fence');b.wall(0.5,22,8.5,22.5,1.7,0x9a7b63,'fence');b.wall(8,14,8.5,17,1.7,0x9a7b63,'fence');b.wall(8,18.5,8.5,22,1.7,0x9a7b63,'fence'); + b.wall(10.5,15,16,20,4.6,0xb3a48e,'house');b.wall(22,6.5,26,8.5,2.3,0x5d7a6a,'shed'); + b.river(0.5,0.5,29.5,3.5,0.50); + b.drain(28.25,15.25,{rate:0.4,cap:16,kind:'culvert'});b.drain(14,11,{rate:0.12,cap:10}); + b.litter(28.25,15.25,0.8,20);b.litter(14,11,0.7,12);b.litter(15,11,10,18);b.litter(21,20,3,6); + b.sign(29.48,15.25,'CULVERT',{nx:-1,y:1.3}); + b.flood(0.5,3.5,29.5,23.5,0.46); + b.spot(18.5,7.5,3.5,'The stream is pouring through a gap in its bank. Nothing will dry out while it does.');b.spot(4.5,18,3.5,'A sunken garden with a wall round it. There is no drain in it and no power anywhere near.');b.spot(21,20,3,'A hollow in the vegetable patch. The ground between here and the culvert is soft.');b.spot(26.5,15.25,3,'The culvert under the lane. Everything on this side of the bank should be leaving through it.'); + b.spawnAt(3,9.5,-Math.PI/2); + }}); + // The depot: not a job. A yard to pick a job, buy gear and load the van, with a puddle to try tools on. + MAPS.depot={id:'depot',name:'The Depot',sub:'Your yard',w:16,h:12,seed:5,depot:true,sky:'day',brief:'', + build:function(b){ + b.ground(function(x,z){return 0.05+0.012*dist(x,z,4.5,8.5)-0.05*bump(dist(x,z,4.5,8.5)/2.5)}); + b.surf(0,0,16,12,T.CONC);b.surf(0.5,6,8,11.5,T.PAVE);b.surf(11,5,15.5,11.5,T.GRAVEL);b.noise(0.004,1.7); + b.wall(0,0,16,2.5,3.6,0x5f7d8c,'house');b.wall(0,2.5,0.5,12,2.0,0x6b5a45,'fence');b.wall(15.5,2.5,16,12,2.0,0x6b5a45,'fence');b.wall(0,11.5,16,12,2.0,0x6b5a45,'fence'); + b.wall(8,2.5,10.5,3.5,0.9,0x7a5a3c,'bench');b.wall(12,6,14.5,10.5,2.1,0xe9e4d6,'van');b.wall(1,2.5,2,3.5,1.0,0x7b6a55,'crate'); + b.station(4.5,2.52,'board',{nz:1,y:1.5});b.station(9.25,3.5,'shop',{nz:1,y:1.1});b.station(12,8.25,'van',{nx:-1,y:1.2}); + b.drain(4.5,8.5,{rate:0.08,cap:6});b.litter(4.5,8.5,0.7,7);b.litter(6,8,2.5,5); + b.flood(0.5,5,9,11.5,0.075); + b.spawnAt(7,7,0); + }}; return MAPS; })(); if(typeof module!=='undefined')module.exports={EWSim:EWSim,EW:EW,EWMaps:EWMaps}; diff --git a/e63334287a3deaa3/ebbwork/game.js b/e63334287a3deaa3/ebbwork/game.js index f1f6baeb..d98d4ae6 100644 --- a/e63334287a3deaa3/ebbwork/game.js +++ b/e63334287a3deaa3/ebbwork/game.js @@ -1,16 +1,38 @@ -/* Ebbwork: drawing, controls, HUD and menus. The rules of the water and of every tool are in core.js. */ +/* Ebbwork: drawing, controls, sound, HUD and menus. The rules of the water and of every tool are in core.js. */ (function(){ 'use strict'; var $=function(id){return document.getElementById(id)}; function T(s,v){if(window.BackRoomLang)return BackRoomLang.t(s,v);return v?s.replace(/\{(\w+)\}/g,function(m,k){return v[k]}):s} -var CS=EW.CS,FILM=EWSim.FILM,TT=EW.T; +var CS=EW.CS; var clamp=function(v,a,b){return vb?b:v}; -// ---------------------------------------------------------------- saved progress +// ---------------------------------------------------------------- gear and saved progress +// slot:1 = a tool you carry (takes a place on the van). The rest are upgrades that are always with you. +var GEAR=[ + {id:'rake',name:'Rake',slot:1,price:0,desc:'Pushes and pulls leaves and litter off a drain.'}, + {id:'bucket',name:'Bucket',slot:1,price:0,desc:'Carries 30 litres at a time, for the puddles nothing else can reach.'}, + {id:'wrench',name:'Wrench',slot:1,price:0,desc:'Tightens dripping joints.'}, + {id:'squeegee',name:'Squeegee',slot:1,price:50,desc:'Shoves thin water across a hard floor, towards a drain or a doorway.'}, + {id:'shovel',name:'Shovel',slot:1,price:80,desc:'Cuts a trench in soft ground so water can run downhill. It can pile the spoil back up, too.'}, + {id:'sack',name:'Debris sack',slot:1,price:90,desc:'Bags up to 40 bits of debris for good, so they cannot wash back.'}, + {id:'sandbags',name:'Sandbags',slot:1,price:90,desc:'Four rows of bags. Lay them across a gap to hold water back.'}, + {id:'pump',name:'Pump',slot:1,price:170,desc:'Lifts water out of places with no way down. It needs power within 8 m, and a hose end somewhere the water can get away.'}, + {id:'generator',name:'Generator',slot:1,price:240,desc:'Power for the pump where there is no socket. Keep it out of the water.'}, + {id:'bags2',name:'More sandbags',price:110,need:'sandbags',desc:'Four more rows on the van.'}, + {id:'hose2',name:'Long hose',price:130,need:'pump',desc:'16 m of hose in place of 9.'}, + {id:'reel',name:'Cable reel',price:80,need:'pump',desc:'18 m of cable in place of 8.'}, + {id:'pump2',name:'Second pump',price:260,need:'pump',desc:'Two pumps on the van.'}, + {id:'waders',name:'Waders',price:110,desc:'Deep water slows you far less.'}, + {id:'rack',name:'Van racking',price:150,desc:'Room for seven kinds of tool in place of five.'} +]; +var GEARBY={};GEAR.forEach(function(g){GEARBY[g.id]=g}); var SAVE_KEY='ebbwork:v1'; -var save={v:1,coins:0,gear:{rake:1,bucket:1,wrench:1},jobs:{},set:{sens:1,vol:0.8,q:'auto',inv:0},seen:{}}; -(function(){try{var o=JSON.parse(localStorage.getItem(SAVE_KEY)||'null');if(o&&o.v===1){for(var k in o)if(k==='set'||k==='gear'||k==='seen'||k==='jobs'){for(var j in o[k])save[k][j]=o[k][j]}else save[k]=o[k]}}catch(e){}})(); +var save={v:1,coins:0,gear:{rake:1,bucket:1,wrench:1},load:['rake','bucket','wrench'],jobs:{},set:{sens:1,vol:0.8,q:'auto',inv:0},tut:0}; +(function(){try{var o=JSON.parse(localStorage.getItem(SAVE_KEY)||'null');if(o&&o.v===1){for(var k in o)if(k==='set'||k==='gear'||k==='jobs'){for(var j in o[k])save[k][j]=o[k][j]}else save[k]=o[k]}}catch(e){} + if(!Array.isArray(save.load))save.load=['rake','bucket','wrench'];save.load=save.load.filter(function(t){return GEARBY[t]&&GEARBY[t].slot&&save.gear[t]})})(); function persist(){try{localStorage.setItem(SAVE_KEY,JSON.stringify(save))}catch(e){}} +function slots(){return save.gear.rack?7:5} +function unlocked(k){return k===0||!!(save.jobs[EWMaps[k-1].id]&&save.jobs[EWMaps[k-1].id].stars)} // ---------------------------------------------------------------- renderer var touchUI=matchMedia('(pointer: coarse)').matches&&!matchMedia('(any-pointer: fine)').matches; @@ -21,9 +43,10 @@ var renderer=new THREE.WebGLRenderer({canvas:canvas,antialias:!touchUI,powerPref var scene=new THREE.Scene(),camera=new THREE.PerspectiveCamera(74,1,0.06,260); camera.rotation.order='YXZ';scene.add(camera); var SKY={zen:new THREE.Color(0x7f97a6),hor:new THREE.Color(0xc5d0d0),fog:new THREE.Color(0xbcc8c9),sun:new THREE.Vector3(-0.45,0.72,0.52).normalize(),sunC:new THREE.Color(0xfff0d8),gnd:new THREE.Color(0x56605a)}; -scene.background=SKY.fog;scene.fog=new THREE.Fog(SKY.fog.getHex(),26,150); +scene.background=SKY.fog;scene.fog=new THREE.Fog(0xbcc8c9,26,150); var hemi=new THREE.HemisphereLight(0xd3dde2,0x525c50,0.82);scene.add(hemi); var sun=new THREE.DirectionalLight(0xfff0d8,0.62);sun.position.copy(SKY.sun).multiplyScalar(50);scene.add(sun); +var torch=new THREE.PointLight(0xffe9c4,0,16,1);camera.add(torch); function quality(){var q=save.set.q;return q==='auto'?(touchUI?'low':'high'):q} function resize(){var w=innerWidth,h=innerHeight,pr=Math.min(devicePixelRatio||1,quality()==='high'?2:touchUI?1.25:1); renderer.setPixelRatio(pr);renderer.setSize(w,h,false);camera.aspect=w/h;camera.fov=w0.02){vec2 q=vW.xz/vP;vec2 f=abs(fract(q)-0.5);float j=smoothstep(0.455,0.492,max(f.x,f.y));vec2 id=floor(q);float h=fract(sin(dot(id,vec2(12.9898,78.233)))*43758.5453);c*=(0.93+0.12*h)*(1.0-0.38*j);}'+ 'float wet=clamp(vWet,0.0,1.0);c*=mix(1.0,0.60,wet);'+ 'float dl=max(dot(n,uSun),0.0);vec3 col=c*(mix(uGnd,uSky,n.y*0.5+0.5)*1.05+uSunC*dl*0.62);'+ 'vec3 V=normalize(uCam-vW);float fr=pow(1.0-max(dot(n,V),0.0),4.0);col+=uSky*fr*wet*0.30;'+ + TORCHF+'col+=c*vec3(1.0,0.92,0.78)*tl*max(dot(n,V),0.2);'+ 'gl_FragColor=vec4(col,1.0);'+FOGF+'}'}); var waterMat=new THREE.ShaderMaterial({uniforms:U,transparent:true,depthWrite:false,polygonOffset:true,polygonOffsetFactor:-1,polygonOffsetUnits:-3, vertexShader:'attribute float aDepth;attribute vec2 aFlow;varying float vD;varying vec2 vF;varying vec3 vW;'+ 'void main(){vD=aDepth;vF=aFlow;vW=position;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}', - fragmentShader:'precision highp float;uniform sampler2D tN;uniform float uT,uScan,uFogN,uFogF;uniform vec3 uCam,uSun,uSunC,uSky,uHor,uFog;varying float vD;varying vec2 vF;varying vec3 vW;'+ + fragmentShader:'precision highp float;uniform sampler2D tN;uniform float uT,uScan,uFogN,uFogF,uTorch;uniform vec3 uCam,uSun,uSunC,uSky,uHor,uFog;varying float vD;varying vec2 vF;varying vec3 vW;'+ 'void main(){if(vD<0.004)discard;'+ 'vec2 uv=vW.xz*0.33;vec2 fl=clamp(vF,-1.6,1.6)*0.55;float sp=length(vF);'+ 'float p0=fract(uT*0.35),p1=fract(uT*0.35+0.5);'+ @@ -66,15 +91,18 @@ var waterMat=new THREE.ShaderMaterial({uniforms:U,transparent:true,depthWrite:fa 'float calm=smoothstep(0.0,0.05,vD);float amp=(0.10+min(sp,1.2)*0.42)*calm;'+ 'vec3 N=normalize(vec3(nn.x*amp,1.0,nn.y*amp));vec3 V=normalize(uCam-vW);'+ 'float fres=0.03+0.97*pow(1.0-max(dot(N,V),0.0),5.0);'+ - 'float murk=1.0-exp(-max(vD,0.0)*6.5);'+ - 'vec3 body=mix(vec3(0.42,0.50,0.46),vec3(0.19,0.22,0.17),murk);float al=mix(0.16,0.95,murk);'+ + 'float murk=1.0-exp(-max(vD,0.0)*6.5);'+TORCHF+ + 'vec3 body=mix(vec3(0.42,0.50,0.46),vec3(0.19,0.22,0.17),murk)*(uSky*1.25+0.12+tl);float al=mix(0.16,0.95,murk);'+ 'vec3 R=reflect(-V,N);vec3 skyc=mix(uHor,uSky,clamp(R.y*1.6,0.0,1.0));'+ 'vec3 col=mix(body,skyc,fres*0.82);al=mix(al,1.0,fres*0.75);'+ - 'col+=uSunC*pow(max(dot(R,uSun),0.0),160.0)*0.9;'+ - 'float foam=smoothstep(0.22,0.9,sp)*smoothstep(0.52,0.78,m.b)*calm;col=mix(col,vec3(0.93,0.95,0.92),foam*0.7);al=max(al,foam*0.7);'+ + 'col+=(uSunC+vec3(tl*0.5))*pow(max(dot(R,uSun),0.0),160.0)*0.9;col+=vec3(1.0,0.93,0.8)*tl*pow(max(dot(N,V),0.0),40.0)*0.25;'+ + 'float foam=smoothstep(0.22,0.9,sp)*smoothstep(0.52,0.78,m.b)*calm;col=mix(col,vec3(0.93,0.95,0.92)*(0.35+uSky*0.9+tl),foam*0.7);al=max(al,foam*0.7);'+ 'al*=smoothstep(0.004,0.022,vD);'+ 'float sc=uScan*step(0.0045,vD)*(0.6+0.4*sin(uT*9.0-length(vW.xz-uCam.xz)*1.6));col=mix(col,vec3(0.25,1.0,0.92),sc*0.8);al=max(al,sc*0.85);'+ 'gl_FragColor=vec4(col,al);'+FOGF+'}'}); +function setEnv(kind){var c=kind==='cellar'; + SKY.fog.setHex(c?0x0d1113:0xbcc8c9);SKY.zen.setHex(c?0x1a2023:0x7f97a6);SKY.hor.setHex(c?0x20272a:0xc5d0d0);SKY.gnd.setHex(c?0x14181a:0x56605a);SKY.sunC.setHex(c?0x000000:0xfff0d8); + scene.fog.color.copy(SKY.fog);scene.fog.near=U.uFogN.value=c?5:26;scene.fog.far=U.uFogF.value=c?30:150;hemi.intensity=c?0.2:0.82;sun.intensity=c?0:0.62;torch.intensity=c?1.25:0;U.uTorch.value=c?1:0} // ---------------------------------------------------------------- a job site, drawn var world=null,def=null,lv=null; // lv: this job's meshes and buffers @@ -86,32 +114,44 @@ Batch.prototype.box=function(x0,y0,z0,x1,y1,z1,col){ this.quad([x0,y0,z1],[x1,y0,z1],[x1,y1,z1],[x0,y1,z1],0,0,1,col,1); this.quad([x1,y0,z0],[x0,y0,z0],[x0,y1,z0],[x1,y1,z0],0,0,-1,col,0.9); this.quad([x1,y0,z1],[x1,y0,z0],[x1,y1,z0],[x1,y1,z1],1,0,0,col,0.96); - this.quad([x0,y0,z0],[x0,y0,z1],[x0,y1,z1],[x0,y1,z0],-1,0,0,col,0.86)}; + this.quad([x0,y0,z0],[x0,y0,z1],[x0,y1,z1],[x0,y1,z0],-1,0,0,col,0.86); + this.quad([x0,y0,z0],[x1,y0,z0],[x1,y0,z1],[x0,y0,z1],0,-1,0,col,0.6)}; Batch.prototype.mesh=function(){var g=new THREE.BufferGeometry();g.setAttribute('position',new THREE.Float32BufferAttribute(this.p,3));g.setAttribute('normal',new THREE.Float32BufferAttribute(this.n,3));g.setAttribute('color',new THREE.Float32BufferAttribute(this.c,3)); return new THREE.Mesh(g,new THREE.MeshLambertMaterial({vertexColors:true}))}; var TYPECOL=[[0.36,0.47,0.25],[0.60,0.59,0.55],[0.33,0.25,0.18],[0.70,0.71,0.68],[0.27,0.28,0.30],[0.52,0.49,0.44],[0.56,0.56,0.54]],TYPEPAT=[0,0.75,0,0.4,0,0,2.5]; function shade(col,f){var r=Math.min(255,((col>>16)&255)*f)|0,g=Math.min(255,((col>>8)&255)*f)|0,b=Math.min(255,(col&255)*f)|0;return r<<16|g<<8|b} -function drawBox(B,b){var x0=b.x0,x1=b.x1,z0=b.z0,z1=b.z1,y0=b.y0,y1=b.y1,c=b.col,k,i; - if(b.kind==='house'){B.box(x0,y0,z0,x1,y1,z1,c);B.box(x0-0.25,y1,z0-0.25,x1+0.25,y1+0.22,z1+0.25,0x4a4f55);B.box(x0+0.6,y1+0.22,z0+0.5,x1-0.6,y1+1.3,z1-0.4,0x3f444a); - var gy=y0+0.6;B.box(x0,gy,z1,x1,gy+0.32,z1+0.04,shade(c,0.72)); - for(k=x0+2.2;k4.6){fb(k,gy+3.3,k+1.5,gy+4.4,0.05,0x2a3a48);fb(k-0.08,gy+3.22,k+1.58,gy+3.3,0.09,0xe9e6dc)}} + fb(x1-2.6,gy,x1-1.6,gy+2.05,0.06,0x7d3b2c); + }else if(kd==='fence'){B.box(x0,y0,z0,x1,y1-0.1,z1,c);B.box(x0-0.04,y1-0.1,z0-0.04,x1+0.04,y1,z1+0.04,0x8d8a82); var lx=x1-x0>z1-z0,len=lx?x1-x0:z1-z0;for(k=1.5;kz1-z0,ln=lh?x1-x0:z1-z0;for(k=0;kz1-z0;if(lr){B.box(x0,y1-0.07,z0+0.2,x1,y1,z1-0.2,c);B.box(x0,y0+0.95,z0+0.22,x1,y0+1.0,z1-0.22,c);for(k=x0;k<=x1-0.1;k+=1.5)B.box(k,y0,z0+0.2,k+0.08,y1,z1-0.2,c)}else{B.box(x0+0.2,y1-0.07,z0,x1-0.2,y1,z1,c);B.box(x0+0.22,y0+0.95,z0,x1-0.22,y0+1.0,z1,c);for(k=z0;k<=z1-0.1;k+=1.5)B.box(x0+0.2,y0,k,x1-0.2,y1,k+0.08,c)} + }else if(kd==='barrier'){B.box(x0,y0,z0+0.15,x1,y1,z1-0.15,c);for(k=x0;k=0?world.S.bar[i]:0)+lift; + if(k===0&&ay!=null)gy=ay;if(k===n&&by!=null)gy=by;out.push(new THREE.Vector3(x,gy,z))}return out} +function rebuildDyn(){ + dynDirty=false;if(lv.dyn){lv.grp.remove(lv.dyn);disposeTree(lv.dyn)} + var g=lv.dyn=new THREE.Group(),B=new Batch(),S=world.S;lv.gush=[]; + world.barriers.forEach(function(b){b.cells.forEach(function(i,k){var x=world.cx(i),z=world.cz(i),y=S.g[i];B.box(x-0.27,y-0.05,z-0.27,x+0.27,y+0.19,z+0.27,k%2?0xb39b6b:0xa88f5e);B.box(x-0.23,y+0.19,z-0.23,x+0.23,y+0.36,z+0.23,k%2?0xa88f5e:0xbba473)})}); + world.gens.forEach(function(gn){var y=S.g[gn.i],x=gn.x,z=gn.z;B.box(x-0.3,y+0.1,z-0.2,x+0.3,y+0.5,z+0.2,0xe0b21c);B.box(x-0.34,y,z-0.24,x-0.3,y+0.58,z+0.24,0x2f3639);B.box(x+0.3,y,z-0.24,x+0.34,y+0.58,z+0.24,0x2f3639);B.box(x-0.34,y+0.54,z-0.24,x+0.34,y+0.58,z+0.24,0x2f3639);B.box(x-0.1,y+0.5,z-0.08,x+0.1,y+0.56,z+0.08,0xc8362b)}); + world.pumps.forEach(function(p){var y=S.g[p.i];B.box(p.x-0.24,y,p.z-0.18,p.x+0.24,y+0.3,p.z+0.18,0xe0701c);B.box(p.x-0.12,y+0.3,p.z-0.12,p.x+0.12,y+0.42,p.z+0.12,0x2f3639);B.box(p.x-0.22,y+0.42,p.z-0.02,p.x+0.22,y+0.46,p.z+0.02,0x2f3639); + if(p.hose){var hy=world.groundAt(p.hose.x,p.hose.z)+0.12;g.add(tube(linePts(p.x,p.z,p.hose.x,p.hose.z,y+0.2,hy,0.06),0.05,0x2a6f8f)); + var N=26,pp=new Float32Array(N*3),pg=new THREE.BufferGeometry();pg.setAttribute('position',new THREE.BufferAttribute(pp,3));var pts=new THREE.Points(pg,new THREE.PointsMaterial({color:0xe6f3f4,size:0.09,transparent:true,opacity:0.9,depthWrite:false}));pts.frustumCulled=false;pts.position.set(p.hose.x,hy,p.hose.z); + var dx=p.hose.x-p.x,dz=p.hose.z-p.z,dl=Math.hypot(dx,dz)||1;g.add(pts);lv.gush.push({p:p,pts:pts,pp:pp,dx:dx/dl,dz:dz/dl})} + if(p.src){var sy=p.src.gen?S.g[p.src.i]+0.3:world.groundAt(p.src.x,p.src.z)+p.src.y;g.add(tube(linePts(p.x,p.z,p.src.x,p.src.z,y+0.3,sy,0.03),0.018,0x17191b))}}); + g.add(B.mesh());lv.grp.add(g); +} var vv=[0,0],dummy=new THREE.Object3D(); function updateWaterMesh(){ @@ -187,29 +242,33 @@ function updateWaterMesh(){ lv.tg.attributes.position.needsUpdate=true;lv.tg.attributes.normal.needsUpdate=true;lv.tg.attributes.aCol.needsUpdate=true} } function updateThings(dt,time){ - var S=world.S,k; + var S=world.S,k,j; for(k=0;k0.02?1:0)} for(k=0;k0.004;if(!G.pts.visible)continue;var gp=G.pp; + for(j=0;jfeet+0.45)return true}return false} function floorAt(x,z,feet){var w=world,S=w.S,gy=w.groundAt(x,z),ci=w.cell(x,z);if(ci>=0&&S.bar[ci]>0)gy+=S.bar[ci]; for(var a=-1;a<=1;a+=2)for(var b=-1;b<=1;b+=2){var i=w.cell(x+a*RAD,z+b*RAD);if(i<0)continue;var t=S.solid[i]?w.sh[i]:S.bar[i]>0?S.g[i]+S.bar[i]:-99;if(t<=feet+0.45&&t>gy)gy=t}return gy} function movePlayer(dt){ - var f=inp.mz,s=inp.mx,l=Math.hypot(f,s);if(l>1){f/=l;s/=l} + var f=inp.mz,s=inp.mx,l=Math.hypot(f,s);if(l>1){f/=l;s/=l;l=1} var dep=Math.max(0,world.depthAt(pl.x,pl.z)-Math.max(0,pl.y-floorAt(pl.x,pl.z,pl.y))); - var slow=1-Math.min(0.62,dep*(save.gear.waders?0.5:1.25)); + var slow=1-Math.min(0.62,dep*(save.gear.waders?0.45:1.25)); var crouching=inp.crouch;pl.crouch+=((crouching?1:0)-pl.crouch)*Math.min(1,dt*12); var sp=(crouching?1.9:inp.sprint&&f>0.2?5.7:3.7)*slow; var sy=Math.sin(pl.yaw),cy=Math.cos(pl.yaw),vx=(-sy*f+cy*s)*sp,vz=(-cy*f-sy*s)*sp; @@ -220,7 +279,7 @@ function movePlayer(dt){ if(!pl.ground){pl.vy-=15*dt;pl.y+=pl.vy*dt;if(pl.y<=gy){pl.y=gy;pl.ground=true;if(pl.vy<-3)sfx(dep>0.04?'splash':'thud',Math.min(1,-pl.vy/8));pl.vy=0}} inp.jump=false; var moving=l>0.1&&pl.ground;pl.speed=moving?sp*l:0; - if(moving){pl.bob+=dt*sp*1.9;pl.step+=dt*sp;if(pl.step>1.9){pl.step=0;sfx(dep>0.04?'wade':'step',0.5)}} + if(moving){pl.bob+=dt*sp*l*1.9;pl.step+=dt*sp*l;if(pl.step>1.9){pl.step=0;sfx(dep>0.04?'wade':'step',dep>0.04?0.35+Math.min(0.5,dep):0.35)}} pl.dep=dep; camera.position.set(pl.x,pl.y+EYE-pl.crouch*0.55+(moving?Math.sin(pl.bob)*0.035:0),pl.z);camera.rotation.set(pl.pitch,pl.yaw,0); } @@ -229,156 +288,304 @@ var aim={x:0,y:0,z:0,i:-1,ok:false,dx:0,dz:0}; function updateAim(reach){ var cp=Math.cos(pl.pitch),dx=-Math.sin(pl.yaw)*cp,dy=Math.sin(pl.pitch),dz=-Math.cos(pl.yaw)*cp,ox=camera.position.x,oy=camera.position.y,oz=camera.position.z,S=world.S; aim.dx=-Math.sin(pl.yaw);aim.dz=-Math.cos(pl.yaw);aim.ok=false; - for(var t=0.3;t<=reach;t+=0.12){var x=ox+dx*t,y=oy+dy*t,z=oz+dz*t,i=world.cell(x,z);if(i<0)break; + for(var t=0.3;t<=reach;t+=0.1){var x=ox+dx*t,y=oy+dy*t,z=oz+dz*t,i=world.cell(x,z);if(i<0)break; if(S.solid[i]&&y=0&&!S.solid[hi]){aim.x=hx;aim.z=hz;aim.y=world.groundAt(hx,hz);aim.i=hi;aim.ok=true}} + if(dy<0.25){var r=Math.min(reach,1.8),hx=ox+aim.dx*r,hz=oz+aim.dz*r,hi=world.cell(hx,hz);if(hi>=0&&!S.solid[hi]){aim.x=hx;aim.z=hz;aim.y=world.groundAt(hx,hz);aim.i=hi;aim.ok=true}} } // the nearest fitting the player is looking at var focus=null,hold=0; function findFocus(){ var best=null,bs=0.9,cp=Math.cos(pl.pitch),dx=-Math.sin(pl.yaw)*cp,dy=Math.sin(pl.pitch),dz=-Math.cos(pl.yaw)*cp,c=camera.position; - function tryIt(kind,o,x,y,z,reach){var ex=x-c.x,ey=y-c.y,ez=z-c.z,q=Math.sqrt(ex*ex+ey*ey+ez*ez);if(q>reach)return;var dot=(ex*dx+ey*dy+ez*dz)/q;if(dot>bs){bs=dot;best={kind:kind,o:o}}} + function tryIt(kind,o,x,y,z,reach,wide){var ex=x-c.x,ey=y-c.y,ez=z-c.z,q=Math.sqrt(ex*ex+ey*ey+ez*ez);if(q>reach)return;var dot=(ex*dx+ey*dy+ez*dz)/q+(wide||0);if(dot>bs){bs=dot;best={kind:kind,o:o}}} world.valves.forEach(function(v){tryIt('valve',v,v.x+v.nx*0.15,world.groundAt(v.x,v.z)+v.y,v.z+v.nz*0.15,2.4)}); world.leaks.forEach(function(l){if(l.wrench&&!l.fixed)tryIt('leak',l,l.px,world.groundAt(l.x,l.z)+l.y,l.pz,2.4)}); + world.pumps.forEach(function(p){tryIt('pump',p,p.x,world.S.g[p.i]+0.3,p.z,2.6,0.03)}); + world.stations.forEach(function(s){tryIt('station',s,s.x,world.groundAt(s.x,s.z)+s.y,s.z,3.4,0.06)}); return best; } // ---------------------------------------------------------------- tools var TOOLS={ - rake:{name:'Rake',tip:'Click: push debris away · Right click: pull it to you',ttip:'Use: push · Alt: pull',icon:''}, - bucket:{name:'Bucket',tip:'Click: fill from water, or tip out · Right click: tip out',ttip:'Use: fill or tip out',icon:''}, - wrench:{name:'Wrench',tip:'Hold click on a dripping joint to tighten it',ttip:'Hold Use on a dripping joint',icon:''} + rake:{tip:'Click: push debris away · Right click: pull it to you',ttip:'Use: push debris · Alt: pull it',icon:''}, + bucket:{tip:'Click: fill from water, or tip out · Right click: tip out',ttip:'Use: fill, or tip out',icon:''}, + wrench:{tip:'Hold click on a dripping joint to tighten it',ttip:'Hold Use on a dripping joint',icon:''}, + squeegee:{tip:'Click: push thin water the way you face',ttip:'Use: push thin water forward',icon:''}, + shovel:{tip:'Click: dig soft ground · Right click: put spoil back',ttip:'Use: dig · Alt: put spoil back',icon:''}, + sack:{tip:'Click: bag the debris in front of you for good',ttip:'Use: bag debris for good',icon:''}, + sandbags:{tip:'Click: lay a row · R: turn it · Right click: pick a row up',ttip:'Use: lay a row · Turn · Alt: pick up',icon:''}, + pump:{tip:'Click: put the pump down, then click where the hose should empty · Right click: pick it up',ttip:'Use: place, then point the hose · Alt: pick up',icon:''}, + generator:{tip:'Click: put it down on dry ground · Right click: pick it up',ttip:'Use: put down · Alt: pick up',icon:''} }; -var bar=[],cur=0,bucketVol=0,BUCKET=0.03,swing=0,swingKind=0,useHeld=false,altHeld=false,cool=0; +var bar=[],cur=0,bucketVol=0,BUCKET=0.03,swing=0,swingKind=0,useHeld=false,altHeld=false,cool=0,rot=0,inv={},hosePump=null; function tool(){return bar[cur]} -function buildBar(){var h=$('hot');h.innerHTML='';bar.forEach(function(id,k){var t=TOOLS[id],b=document.createElement('button');b.setAttribute('data-no-ad-refresh','');b.setAttribute('aria-label',T(t.name)); - b.innerHTML=''+(k+1)+''+t.icon+''+T(t.name)+''; - b.addEventListener('click',function(e){e.preventDefault();selectTool(k);canvas.focus()});h.appendChild(b)});selectTool(Math.min(cur,bar.length-1))} -function selectTool(k){if(k<0||k>=bar.length)return;cur=k;var bs=$('hot').children;for(var i=0;i'+t.icon+''+T(GEARBY[id].name)+''; + b.addEventListener('click',function(e){e.preventDefault();selectTool(k,true);canvas.focus()});h.appendChild(b)});if(bar.length)selectTool(Math.min(cur,bar.length-1))} +function selectTool(k,say){if(k<0||k>=bar.length)return;cur=k;hosePump=null;var bs=$('hot').children;for(var i=0;i2.7)return} + else if(id==='sandbags'){cells=world.barrierCells(aim.x,aim.z,rot);ok=!!cells&&inv.sandbags>0;if(!cells)cells=[aim.i]} + else if(id==='pump'){if(hosePump){var p=hosePump,far=Math.hypot(aim.x-p.x,aim.z-p.z)>world.hoseLen;ok=!far&&!S.solid[aim.i];var a=ghostGeo.attributes.position.array;a[0]=p.x;a[1]=S.g[p.i]+0.3;a[2]=p.z;a[3]=aim.x;a[4]=aim.y+0.1;a[5]=aim.z;ghostGeo.attributes.position.needsUpdate=true;ghostLine.visible=true;ghostLine.material.color.setHex(ok?0x8fd66a:0xff6257)}else ok=inv.pump>0||!!near(world.pumps,1.0)} + else if(id==='generator')ok=inv.generator>0||!!near(world.gens,1.0); + ghostM.color.setHex(ok?0x8fd66a:0xff6257); + for(k=0;k0||!id)return;updateAim(2.6); - if(id==='rake'){swing=0.42;swingKind=alt?2:1;cool=0.42;var px=pl.x,pz=pl.z,dx=aim.dx,dz=aim.dz;setTimeout(function(){if(!world)return;var n=world.rake(px,pz,dx,dz,alt);sfx(n?'rake':'swish',n?0.8:0.4);if(n)noteSeen('rake')},130)} - else if(id==='bucket'){cool=0.5;swing=0.4;swingKind=1; + var id=tool();if(cool>0||!id||state!=='play')return;updateAim(id==='pump'||id==='generator'||id==='sandbags'?3.4:2.6); + if(id==='rake'){swing=0.42;swingKind=alt?2:1;cool=0.42;var px=pl.x,pz=pl.z,dx=aim.dx,dz=aim.dz;setTimeout(function(){if(!world)return;var n=world.rake(px,pz,dx,dz,alt);sfx(n?'rake':'swish',n?0.8:0.4)},130)} + else if(id==='bucket'){cool=0.5;swing=0.42;swingKind=1; if(bucketVol>0.001&&(alt||bucketVol>=BUCKET*0.5||!aim.ok||world.S.d[aim.i]<0.012)){if(!aim.ok){cool=0;return}var v=world.pour(aim.x,aim.z,bucketVol);if(v>0){bucketVol=0;sfx('pour',0.9)}} - else if(!alt&&aim.ok){var got=world.scoop(aim.x,aim.z,BUCKET-bucketVol);if(got>0.0005){bucketVol+=got;sfx('scoop',0.8)}else toast(T('No water to scoop here.'),1.4)} - } + else if(!alt&&aim.ok){var got=world.scoop(aim.x,aim.z,BUCKET-bucketVol);if(got>0.0005){bucketVol+=got;sfx('scoop',0.8)}else toast(T('No water to scoop here.'),1.4)}} + else if(id==='squeegee'){cool=0.4;swing=0.42;swingKind=1;var mv=world.squeegee(pl.x,pl.z,aim.dx,aim.dz);sfx(mv>0.0004?'squee':'swish',0.6)} + else if(id==='shovel'){if(!aim.ok||Math.hypot(aim.x-pl.x,aim.z-pl.z)>2.7)return;cool=0.34;swing=0.42;swingKind=1; + if(alt){if(world.pile(aim.x,aim.z))sfx('dig',0.7);else toast(world.spoil>0?T('You cannot pile soil there.'):T('No spoil to put back yet. Dig first.'),1.6)} + else if(world.dig(aim.x,aim.z))sfx('dig',0.9);else{var ci=aim.i;toast(!world.soft[ci]?T('Too hard to dig. Try soil or grass.'):T('That is as deep as this trench will go.'),1.6);sfx('thud',0.4)}} + else if(id==='sack'){cool=0.45;swing=0.42;swingKind=2;if(!aim.ok)return;if(inv.sack<=0){toast(T('The sack is full.'),1.6);return}var got2=world.takeDebris(aim.x,aim.z,1.1,Math.min(6,inv.sack));got2.forEach(function(p){dummy.position.set(0,-50,0);dummy.scale.setScalar(0.001);dummy.updateMatrix();p._m.setMatrixAt(p._j,dummy.matrix)});inv.sack-=got2.length;sfx(got2.length?'rake':'swish',0.6)} + else if(id==='sandbags'){cool=0.3;if(!aim.ok)return; + if(alt){var bb=null,bd=1.3;world.barriers.forEach(function(b){var q=Math.hypot(b.x-aim.x,b.z-aim.z);if(q0.1)toast(T('Too wet. It would drown here.'),1.8); + else if(world.placeGen(aim.x,aim.z)){inv.generator--;dynDirty=true;sfx('thud',0.9)}} } function animView(dt){ - var id=tool(),m=vmods[id];if(!m)return;var b=m.userData.base,t=swing>0?1-swing/0.42:0,s=swing>0?Math.sin(t*Math.PI):0; - var sway=Math.sin(pl.bob)*0.012*(pl.speed>0?1:0); - m.position.set(b.p.x+sway,b.p.y+Math.abs(Math.cos(pl.bob))*0.012*(pl.speed>0?1:0)-0.0,b.p.z);m.rotation.set(b.r.x,b.r.y,b.r.z); - if(id==='rake'){m.rotation.x=b.r.x-s*0.5;m.position.z=b.p.z+(swingKind===2?s*0.22:-s*0.3);m.position.y=b.p.y-s*0.05} - else if(id==='bucket'){m.rotation.x=-s*0.9;m.position.y=b.p.y+s*0.1;m.userData.water.visible=bucketVol>0.002;m.userData.water.position.y=-0.12+0.2*clamp(bucketVol/BUCKET,0,1)} + var id=tool(),m=vmods[id];if(!m)return;var b=m.userData.base,t=swing>0?1-swing/0.42:0,s=swing>0?Math.sin(t*Math.PI):0,mv=pl.speed>0?1:0; + m.position.set(b.p.x+Math.sin(pl.bob)*0.012*mv,b.p.y+Math.abs(Math.cos(pl.bob))*0.012*mv,b.p.z);m.rotation.set(b.r.x,b.r.y,b.r.z); + if(id==='rake'||id==='squeegee'){m.rotation.x=b.r.x-s*0.45;m.position.z=b.p.z+(swingKind===2?s*0.22:-s*0.3);m.position.y+=-s*0.05} + else if(id==='shovel'){m.rotation.x=b.r.x-s*0.55;m.position.y+=-s*0.14;m.position.z=b.p.z-s*0.12} + else if(id==='bucket'){m.rotation.x=-s*0.9;m.position.y+=s*0.1;m.userData.water.visible=bucketVol>0.002;m.userData.water.position.y=-0.12+0.2*clamp(bucketVol/BUCKET,0,1)} else if(id==='wrench'){m.rotation.z=b.r.z+(hold>0&&focus&&focus.kind==='leak'?Math.sin(performance.now()*0.012)*0.5:0)} + else m.position.y+=-s*0.08; if(swing>0)swing=Math.max(0,swing-dt);if(cool>0)cool-=dt; } -// ---------------------------------------------------------------- sound (filled in later; calls are already in place) -function sfx(){} -function audioTick(){} +// ---------------------------------------------------------------- sound, all made here in code +var AC=null,master=null,noiseBuf=null,amb={},lastGulp=0; +function audioInit(){if(AC)return;var C=window.AudioContext||window.webkitAudioContext;if(!C)return;try{AC=new C()}catch(e){return} + master=AC.createGain();master.gain.value=save.set.vol;master.connect(AC.destination); + noiseBuf=AC.createBuffer(1,AC.sampleRate*2,AC.sampleRate);var d=noiseBuf.getChannelData(0),b=0;for(var i=0;i0.01&&world.S.d[d.i]<0.07&&q<12&&world.t-lastGulp>0.9+Math.random()*1.6){lastGulp=world.t;sfx('gulp',0.9/(1+q*0.12))}} + for(k=0;k0)return;scanT=4.5;scanCool=9;$('scanfx').classList.add('on');sfx('scan',0.7); - toast(world.wet>0?T('{v} litres left on site.',{v:Math.round(world.left*1000)}):T('No standing water found.'),3)} +function scan(){if(state!=='play'||scanCool>0||def.depot)return;scanT=4.5;scanCool=9;$('scanfx').classList.add('on');sfx('scan',0.7); + toast(world.left>0.004?T('{v} litres still lying here, over {n} square metres.',{v:Math.round(world.left*1000),n:Math.round(world.wet*0.25)}):T('No standing water found.'),3.5)} function tasks(){ var out=[],w=world; w.drains.forEach(function(d,k){var found=seen['d'+k];if(!found)out.push({t:T('Find where this water should be draining to'),s:T('Low points are a good place to look.'),done:false}); - else out.push({t:T('Keep the drain clear'),s:d.clear>=0.9?T('Running freely.'):T('{p}% blocked. Rake the debris well away, or it will wash back.',{p:Math.round((1-d.clear)*100)}),done:d.clear>=0.9})}); - w.leaks.forEach(function(l,k){var found=seen['l'+k];if(!found&&l.on)out.push({t:T('Find out if water is still getting in'),s:T('Listen and look along the walls.'),done:false}); - else out.push({t:T('Stop the leak'),s:l.on?(l.valve?T('The pipe is under pressure. Follow it back to a stop tap.'):T('Tighten it with the wrench.')):T('Stopped.'),done:!l.on})}); + else out.push({t:d.kind==='culvert'?T('Keep the culvert clear'):T('Keep the drain clear'),s:d.clear>=0.9?T('Running freely.'):T('{p}% blocked. Rake the debris well away, or it will wash back.',{p:Math.round((1-d.clear)*100)}),done:d.clear>=0.9})}); + w.leaks.forEach(function(l,k){var found=seen['l'+k];if(!found&&l.on)out.push({t:T('Find out if water is still getting in'),s:T('Listen, and look along the walls.'),done:false}); + else out.push({t:T('Stop the leak'),s:l.on?(l.valve?T('The pipe is under pressure. Follow it back to a stop tap.'):T('A dripping joint. Tighten it with the wrench.')):T('Stopped.'),done:!l.on})}); + if(w.holdList.length){var blk=w.holdIn<=0.004&&w.barriers.length>0;out.push({t:T('Stop the water getting in from outside'),s:blk?T('Held back.'):T('Something has to stand in its way.'),done:blk})} + w.pumps.forEach(function(p){out.push({t:T('Pump'),s:pumpWhy(p),done:p.run&&p.away&&p.why===''})}); var pc=Math.round(w.fraction()*100);out.push({t:T('Get the water under the green mark'),s:T('{p}% left. Small puddles are fine.',{p:pc}),done:w.fraction()<=EW.World.DONE}); return out; } +function esc(s){return String(s).replace(/[&<>"]/g,function(c){return{'&':'&','<':'<','>':'>','"':'"'}[c]})} function openJournal(){$('jTitle').textContent=def.name+' · '+T(def.sub);$('jBrief').textContent=T(def.brief); - $('jTasks').innerHTML=tasks().map(function(t){return'
  • '+t.t+''+t.s+'
  • '}).join('');show('journal')} + var h=def.depot?'':tasks().map(function(t){return'
  • '+esc(t.t)+''+esc(t.s)+'
  • '}).join(''); + if(notes.length)h+='
  • '+esc(T('What you have noticed'))+notes.map(function(n){return'• '+esc(n)+''}).join('')+'
  • '; + if(def.depot)h+='
  • '+esc(T('The job board has the work, the bench sells gear, and the van takes you there.'))+'
  • '; + $('jTasks').innerHTML=h;show('journal')} +// the first job walks a new player through it, one line at a time +var TUT=[ + {t:'Walk into the yard and look for where the water ought to be going.',ok:function(){return seen.d0}}, + {t:'That is the drain, under the debris. Hold the rake (1) and click to push the debris off it. Push it a long way.',tt:'That is the drain, under the debris. With the rake, tap Use to push the debris off it. Push it a long way.',ok:function(){return world.drains[0].clear>0.85}}, + {t:'Better, but the gauge says water is still coming in. Find what is feeding it.',ok:function(){return seen.l0||!world.incoming()}}, + {t:'A split pipe. It cannot be mended under pressure: follow the pipe along the wall to its stop tap, and hold E on it.',tt:'A split pipe. It cannot be mended under pressure: follow the pipe along the wall to its stop tap, and hold Do on it.',ok:function(){return !world.incoming()}}, + {t:'Now keep the drain clear while it empties. Debris floats back. F shows the water that is left.',tt:'Now keep the drain clear while it empties. Debris floats back. The scan button shows the water that is left.',ok:function(){return world.fraction()<0.2}}, + {t:'Nearly there. The green mark on the gauge is all you need: small puddles do not matter.',ok:function(){return world.isDone()}} +],tutK=-1; function updateHud(dt){ - var fr=world.fraction();$('gaugeFill').style.width=clamp(fr*100,0,100).toFixed(1)+'%';$('pct').textContent=Math.round(fr*100)+'%';$('clock').textContent=fmtTime(world.t); - $('inflow').hidden=!world.incoming(); + var fr=world.fraction(),k; + if(!def.depot){$('gaugeFill').style.width=clamp(fr*100,0,100).toFixed(1)+'%';$('pct').textContent=Math.round(fr*100)+'%';$('clock').textContent=fmtTime(world.t);$('inflow').hidden=!world.incoming()} if(toastT>0){toastT-=dt;if(toastT<=0)$('toast').classList.add('off')} if(scanT>0){scanT-=dt;if(scanT<=0)$('scanfx').classList.remove('on')}if(scanCool>0)scanCool-=dt; U.uScan.value+=((scanT>0?1:0)-U.uScan.value)*Math.min(1,dt*5); - var u=$('hot').children;for(var k=0;k0.001?Math.round(bucketVol*1000)+'L':''; - // discoveries, for the journal and the hints - world.drains.forEach(function(d,k){if(!seen['d'+k]&&Math.hypot(d.x-pl.x,d.z-pl.z)<3.2){seen['d'+k]=1;toast(d.clear<0.5?T('A drain, buried in debris. That is one reason the water is staying.'):T('A drain.'),4)}}); - world.leaks.forEach(function(l,k){if(!seen['l'+k]&&l.on&&Math.hypot(l.x-pl.x,l.z-pl.z)<4.5){seen['l'+k]=1;toast(T('Water is pouring out of a split pipe here. It will not drain while this runs.'),4.5)}}); + var u=$('hot').children;for(k=0;k0.001?Math.round(bucketVol*1000)+'L':'';else if(inv[id]!=null)tx=String(inv[id]);if(u[k].lastChild.textContent!==tx)u[k].lastChild.textContent=tx} + // things noticed, for the journal and the hints + world.drains.forEach(function(d,k){if(!seen['d'+k]&&Math.hypot(d.x-pl.x,d.z-pl.z)<3.2){seen['d'+k]=1;if(!def.depot)toast(d.clear<0.5?T('A drain, buried in debris. That is one reason the water is staying.'):T('A drain.'),4)}}); + world.leaks.forEach(function(l,k){if(!seen['l'+k]&&l.on&&Math.hypot(l.x-pl.x,l.z-pl.z)<4.2){seen['l'+k]=1;toast(l.wrench?T('A joint is dripping steadily here.'):T('Water is pouring out of a split pipe here. Nothing will drain for long while this runs.'),4.5)}}); + world.spots.forEach(function(s){if(!s.seen&&Math.hypot(s.x-pl.x,s.z-pl.z)=0){if(TUT[tutK].ok()){tutK++;if(tutK>=TUT.length){tutK=-1;save.tut=1;persist()}}} + if(tutK>=0){var tx2=T(touchUI&&TUT[tutK].tt?TUT[tutK].tt:TUT[tutK].t);if(gd.textContent!==tx2)gd.textContent=tx2;gd.hidden=false}else gd.hidden=true; // prompt - focus=findFocus();var p=$('prompt'),act=touchUI?T('Hold Do'):T('Hold E'); - if(focus){var txt='';if(focus.kind==='valve')txt=act+': '+(focus.o.closed?T('open the stop tap'):T('shut the stop tap'));else if(focus.kind==='leak')txt=tool()==='wrench'?(touchUI?T('Hold Use'):T('Hold click'))+': '+T('tighten the joint'):T('Needs the wrench'); + focus=findFocus();var p=$('prompt'),tap=touchUI?T('Do'):'E',act=touchUI?T('Hold Do'):T('Hold E'),txt=''; + if(focus){var o=focus.o; + if(focus.kind==='valve')txt=act+': '+(o.closed?T('open the stop tap'):T('shut the stop tap')); + else if(focus.kind==='leak')txt=tool()==='wrench'?(touchUI?T('Hold Use'):T('Hold click'))+': '+T('tighten the joint'):T('A dripping joint. It needs the wrench.'); + else if(focus.kind==='pump')txt=pumpWhy(o)+' '+tap+': '+(o.on?T('switch off'):T('switch on')); + else if(focus.kind==='station')txt=tap+': '+(o.kind==='board'?T('look at the job board'):o.kind==='shop'?T('buy gear'):T('load the van')); $('promptTx').textContent=txt;p.hidden=false;$('promptBar').hidden=hold<=0;$('promptBar').firstChild.style.width=clamp(hold,0,1)*100+'%'}else{p.hidden=true;hold=0} - $('cross').classList.toggle('act',!!focus);$('tAct').hidden=!(focus&&focus.kind==='valve'); - // holding E on a fitting + $('cross').classList.toggle('act',!!focus);$('tAct').hidden=!(focus&&focus.kind!=='leak'); + if(focus&&inp.act&&(focus.kind==='pump'||focus.kind==='station')){inp.act=false;if(focus.kind==='pump'){focus.o.on=!focus.o.on;sfx('tick',1)}else openStation(focus.o.kind)} var working=focus&&((focus.kind==='valve'&&inp.act)||(focus.kind==='leak'&&tool()==='wrench'&&useHeld)); if(working){hold+=dt/(focus.kind==='valve'?1.0:1.8);if(hold>=1){hold=0;inp.act=false;if(focus.kind==='valve'){world.setValve(focus.o,!focus.o.closed);sfx('valve',0.9);toast(focus.o.closed?T('Stop tap shut.'):T('Stop tap open.'),2.2)}else{world.fixLeak(focus.o);sfx('valve',0.8);toast(T('Joint tightened.'),2.2)}}} else if(hold>0)hold=Math.max(0,hold-dt*2); } // ---------------------------------------------------------------- screens -var state='menu',selJob=EWMaps[0].id,endT=0; -var PANELS=['menu','pause','settings','how','journal','result'],backTo=null; +var state='menu',selJob=null,endT=0; +var PANELS=['menu','pause','settings','how','journal','result','board','shop','van'],backTo=null; function show(id){PANELS.forEach(function(p){$(p).hidden=p!==id});if(id&&document.pointerLockElement)document.exitPointerLock()} function starsHtml(n){return'★'.repeat(n)+''+'★'.repeat(3-n)+''} -function buildMenu(){var h=$('jobList');h.innerHTML='';EWMaps.forEach(function(m){var b=document.createElement('button');b.className='job';b.setAttribute('aria-pressed',m.id===selJob?'true':'false');var r=save.jobs[m.id]; - b.innerHTML='
    '+m.name+''+T(m.sub)+'
    '+starsHtml(r?r.stars:0)+'';b.addEventListener('click',function(){selJob=m.id;buildMenu()});h.appendChild(b)})} -function startJob(id){ - if(lv){scene.remove(lv.grp);lv.grp.traverse(function(o){if(o.geometry)o.geometry.dispose()});lv=null} - def=EWMaps.filter(function(m){return m.id===id})[0];world=new EW.World(def,{});lv=buildLevel(world); +function coinsTx(){$('coins').textContent=save.coins+' ◈'} +function jobBy(id){return EWMaps.filter(function(m){return m.id===id})[0]} +function enter(d){ + if(lv){scene.remove(lv.grp);disposeTree(lv.grp);lv=null} + def=d;setEnv(def.sky); + world=new EW.World(def,{hoseLen:save.gear.hose2?16:9,cableLen:save.gear.reel?18:8});lv=buildLevel(world); pl.x=world.spawn.x;pl.z=world.spawn.z;pl.y=world.groundAt(pl.x,pl.z);pl.yaw=world.spawn.yaw;pl.pitch=0;pl.vy=0;pl.ground=true; - bar=['rake','bucket','wrench'].filter(function(t){return save.gear[t]});cur=0;bucketVol=0;seen={};endT=0;scanT=0;scanCool=0;hold=0;acc=0; - buildBar();$('plName').textContent=def.name;$('hud').hidden=false;updateWaterMesh(); - state='play';show(null);lockPointer();toast(T(def.brief),5); + var own=function(t){return save.gear[t]}; + bar=def.depot?GEAR.filter(function(g){return g.slot&&own(g.id)}).map(function(g){return g.id}).slice(0,9):save.load.filter(own); + inv={};if(bar.indexOf('sandbags')>=0)inv.sandbags=save.gear.bags2?8:4;if(bar.indexOf('pump')>=0)inv.pump=save.gear.pump2?2:1;if(bar.indexOf('generator')>=0)inv.generator=1;if(bar.indexOf('sack')>=0)inv.sack=40; + cur=0;bucketVol=0;seen={};notes=[];endT=0;scanT=0;scanCool=0;hold=0;acc=0;rot=0;hosePump=null;dynDirty=true;inp.crouch=false;$('tCrouch').classList.remove('on'); + buildBar();$('plName').textContent=def.name;$('hud').hidden=false;coinsTx(); + $('statLbl').hidden=$('gauge').hidden=!!def.depot;$('clock').hidden=!!def.depot;$('bScan').hidden=!!def.depot;$('inflow').hidden=true;$('guide').hidden=true; + $('bQuit').hidden=$('bRestart').hidden=!!def.depot;$('bTitle').hidden=!def.depot; + tutK=(!def.depot&&def.id==='yard'&&!save.tut)?0:-1; + if(!def.depot){var r=save.jobs[def.id]||(save.jobs[def.id]={stars:0,best:0,n:0});r.seen=1;persist()} + updateWaterMesh();state='play';show(null);lockPointer(); + toast(def.depot?(selJob?T('Job taken: {j}. Load the van when you are ready.',{j:jobBy(selJob).name}):T('Your depot. The job board is on the wall ahead.')):T(def.brief),5); } function finishJob(){ - state='result';var t=world.t,fr=world.fraction(),stars=1+(t<=def.par*1.6?1:0)+(t<=def.par&&fr<=0.015?1:0),pay=Math.round(def.pay*(0.6+0.2*stars)); - var r=save.jobs[def.id]||{stars:0,best:0,n:0};var first=!r.n;r.n++;r.stars=Math.max(r.stars,stars);r.best=r.best?Math.min(r.best,Math.round(t)):Math.round(t);save.jobs[def.id]=r;save.coins+=pay;persist(); + state='result';var t=world.t,fr=world.fraction(),stars=1+(t<=def.par*1.6?1:0)+(t<=def.par&&fr<=0.015?1:0),r=save.jobs[def.id]||{stars:0,best:0,n:0},again=r.n>0,pay=Math.round(def.pay*(0.6+0.2*stars)*(again?0.5:1)); + r.n=(r.n||0)+1;r.stars=Math.max(r.stars,stars);r.best=r.best?Math.min(r.best,Math.round(t)):Math.round(t);save.jobs[def.id]=r;save.coins+=pay;persist(); $('rStars').innerHTML=starsHtml(stars); - $('rSum').innerHTML=''+T('Time')+''+fmtTime(t)+''+T('Water left')+''+(fr*100).toFixed(1)+'%'+T('Pay')+''+pay+' ◈'+T('Your coins')+''+save.coins+' ◈'; - void first;show('result');sfx('done',1); + $('rSum').innerHTML=''+esc(T('Time'))+''+fmtTime(t)+' ('+esc(T('target'))+' '+fmtTime(def.par)+')'+esc(T('Water left'))+''+(fr*100).toFixed(1)+'%'+esc(again?T('Pay (half: you have done this job before)'):T('Pay'))+''+pay+' ◈'+esc(T('Your coins'))+''+save.coins+' ◈'; + $('guide').hidden=true;show('result');sfx('done',1); } function pause(){if(state!=='play')return;state='pause';show('pause')} function resume(){if(state!=='pause')return;state='play';show(null);lockPointer()} -function quit(){state='menu';$('hud').hidden=true;buildMenu();show('menu')} +function toTitle(){state='menu';$('hud').hidden=true;show('menu')} +function toDepot(){enter(EWMaps.depot)} function lockPointer(){if(!touchUI&&canvas.requestPointerLock){try{var p=canvas.requestPointerLock();if(p&&p.catch)p.catch(function(){})}catch(e){}}canvas.focus()} -document.addEventListener('pointerlockchange',function(){if(!document.pointerLockElement&&state==='play'&&!touchUI&&$('journal').hidden)pause()}); -$('bStart').onclick=function(){startJob(selJob)}; -$('bResume').onclick=resume;$('bQuit').onclick=quit;$('bRestart').onclick=function(){startJob(def.id)}; -$('bAgain').onclick=function(){startJob(def.id)};$('bBack').onclick=quit; -function openSub(id){backTo=state==='menu'?'menu':'pause';if(state==='play')state='pause';if(id==='journal')openJournal();else show(id)} +document.addEventListener('pointerlockchange',function(){if(!document.pointerLockElement&&state==='play'&&!touchUI)pause()}); +$('bStart').onclick=toDepot; +$('bResume').onclick=resume;$('bQuit').onclick=toDepot;$('bTitle').onclick=toTitle;$('bRestart').onclick=function(){enter(def)}; +$('bAgain').onclick=function(){enter(def)};$('bBack').onclick=toDepot; +function openSub(id){if(state==='menu')backTo='menu';else if(state==='play'){state='pause';backTo='play'}else backTo='pause';if(id==='journal')openJournal();else show(id)} +function closeSub(){if(backTo==='play'){state='pause';resume()}else show(backTo)} $('bSet1').onclick=$('bSet2').onclick=function(){openSub('settings')};$('bHow').onclick=$('bHow2').onclick=function(){openSub('how')}; $('bJournal').onclick=$('bJournal2').onclick=function(){openSub('journal')}; -$('bSetDone').onclick=$('bHowDone').onclick=function(){show(backTo)}; -$('bJDone').onclick=function(){if(backTo==='pause'&&$('pause').dataset.from!=='menu'){state='pause';resume()}else show(backTo)}; +$('bSetDone').onclick=$('bHowDone').onclick=$('bJDone').onclick=$('bBoardX').onclick=$('bShopX').onclick=$('bVanX').onclick=closeSub; $('bPause').onclick=pause;$('bScan').onclick=function(){scan();canvas.focus()}; -$('bFull').onclick=function(){var d=document;if(d.fullscreenElement)d.exitFullscreen();else if(d.documentElement.requestFullscreen)d.documentElement.requestFullscreen().catch(function(){})}; +$('bFull').onclick=function(){var d=document;if(d.fullscreenElement)d.exitFullscreen();else if(d.documentElement.requestFullscreen){var p=d.documentElement.requestFullscreen();if(p&&p.catch)p.catch(function(){})}}; +// depot: job board, shop, van +var pick=null; +function openStation(kind){backTo='play';state='pause';if(kind==='board'){pick=selJob||EWMaps[0].id;drawBoard();show('board')}else if(kind==='shop'){drawShop();show('shop')}else{drawVan();show('van')}} +function drawBoard(){var h=$('jobList');h.innerHTML='';EWMaps.forEach(function(m,k){var b=document.createElement('button');b.className='job';b.disabled=!unlocked(k);b.setAttribute('aria-pressed',m.id===pick?'true':'false');var r=save.jobs[m.id]; + b.innerHTML='
    '+m.name+''+(unlocked(k)?esc(T(m.sub)):esc(T('Finish {j} first',{j:EWMaps[k-1].name})))+'
    '+starsHtml(r?r.stars:0)+'';b.addEventListener('click',function(){pick=m.id;drawBoard()});h.appendChild(b)}); + var m=jobBy(pick),r=save.jobs[m.id]||{},need=(m.needs||[]).map(function(g){return T(GEARBY[g].name)+(save.gear[g]?'':' ('+T('not owned')+')')}).join(', '); + $('jobInfo').innerHTML='

    '+m.name+'

    '+esc(T(m.brief))+'
    '+esc(T('Pays up to'))+''+m.pay+' ◈'+esc(T('Target time'))+''+fmtTime(m.par)+''+(r.best?''+esc(T('Your best'))+''+fmtTime(r.best)+'':'')+'
    '+ + '
    '+(r.seen&&need?''+esc(T('From your last visit, worth bringing:'))+' '+esc(need):esc(T('Nobody has looked at it yet. Go and see what it needs; you can always come back for more gear.')))+'
    '+(r.n?'
    '+esc(T('Done before: a repeat pays half.'))+'
    ':''); + $('bTake').disabled=!unlocked(EWMaps.indexOf(m)); +} +$('bTake').onclick=function(){selJob=pick;closeSub();toast(T('Job taken: {j}. Load the van when you are ready.',{j:jobBy(selJob).name}),4)}; +function drawShop(){$('shopCoins').textContent=save.coins+' ◈';var h=$('gearList');h.innerHTML='';GEAR.forEach(function(g){if(!g.price)return;var d=document.createElement('div');d.className='gi';var own=save.gear[g.id],locked=g.need&&!save.gear[g.need]; + d.innerHTML=''+esc(T(g.name))+''+esc(T(g.desc))+(locked?' '+esc(T('Needs: {g}.',{g:T(GEARBY[g.need].name)})):'')+''; + if(own){var s=document.createElement('span');s.className='own';s.textContent=T('Owned');d.appendChild(s)}else{var b=document.createElement('button');b.className='btn';b.setAttribute('data-noi18n','');b.textContent=g.price+' ◈';b.disabled=locked||save.coins=0,b=document.createElement('button');b.className='gi'+(on?' sel':'');b.setAttribute('aria-pressed',on?'true':'false'); + b.innerHTML=''+esc(T(g.name))+''+esc(T(g.desc))+''+(on?esc(T('On the van')):'')+''; + b.onclick=function(){var k=save.load.indexOf(g.id);if(k>=0)save.load.splice(k,1);else if(save.load.length0?1:-1)+bar.length)%bar.length)},{passive:false}); +canvas.addEventListener('wheel',function(e){if(state!=='play'||!bar.length)return;e.preventDefault();selectTool((cur+(e.deltaY>0?1:-1)+bar.length)%bar.length)},{passive:false}); function readKeys(){if(touchUI)return;inp.mz=(keys.KeyW||keys.ArrowUp?1:0)-(keys.KeyS||keys.ArrowDown?1:0);inp.mx=(keys.KeyD||keys.ArrowRight?1:0)-(keys.KeyA||keys.ArrowLeft?1:0); inp.sprint=!!(keys.ShiftLeft||keys.ShiftRight);inp.crouch=!!(keys.KeyC||keys.ControlLeft)} @@ -410,7 +618,7 @@ function readKeys(){if(touchUI)return;inp.mz=(keys.KeyW||keys.ArrowUp?1:0)-(keys (function(){ var stick=$('stick'),nub=stick.firstElementChild,sid=null,sx=0,sy=0,lid=null,lx=0,ly=0; addEventListener('touchstart',function(){if(!touchUI){setTouch(true);resize();if(state==='play')buildBar()}},{passive:true,once:true}); - function setStick(dx,dy){var m=Math.hypot(dx,dy),mx=46;if(m>mx){dx*=mx/m;dy*=mx/m}nub.style.transform='translate('+dx+'px,'+dy+'px)';inp.mx=dx/mx;inp.mz=-dy/mx;inp.sprint=m>mx*1.25} + function setStick(dx,dy){var m=Math.hypot(dx,dy),mx=46;inp.sprint=m>mx*1.3;if(m>mx){dx*=mx/m;dy*=mx/m}nub.style.transform='translate('+dx+'px,'+dy+'px)';inp.mx=dx/mx;inp.mz=-dy/mx} canvas.addEventListener('touchstart',function(e){if(state!=='play')return;e.preventDefault();for(var k=0;kinnerHeight*0.38){sid=t.identifier;sx=t.clientX;sy=t.clientY;stick.style.left=(sx-59)+'px';stick.style.top=(sy-59)+'px';stick.style.bottom='auto';setStick(0,0)} else if(lid===null){lid=t.identifier;lx=t.clientX;ly=t.clientY}}},{passive:false}); @@ -425,6 +633,7 @@ function readKeys(){if(touchUI)return;inp.mz=(keys.KeyW||keys.ArrowUp?1:0)-(keys btn('tAlt',function(){altHeld=true;useTool(true)},function(){altHeld=false}); btn('tJump',function(){inp.jump=true}); btn('tAct',function(){inp.act=true},function(){inp.act=false}); + btn('tRot',function(){rot=(rot+1)%4;sfx('tick',0.5)}); var cr=$('tCrouch');cr.addEventListener('touchstart',function(e){e.preventDefault();inp.crouch=!inp.crouch;cr.classList.toggle('on',inp.crouch)},{passive:false}); })(); @@ -433,20 +642,22 @@ var last=performance.now(),acc=0,STEP=1/30,simMs=0; function frame(now){ requestAnimationFrame(frame); var dt=Math.min(0.05,(now-last)/1000);last=now; - if(document.hidden)return; + if(document.hidden||!world)return; if(state==='play'){ readKeys();movePlayer(dt); acc+=dt;var n=0,t0=performance.now();while(acc>=STEP&&n<3){world.step(STEP);acc-=STEP;n++}if(n){updateWaterMesh();simMs+=(performance.now()-t0-simMs)*0.1}if(acc>STEP)acc=0; - if(useHeld&&tool()==='rake')useTool(false);if(altHeld&&tool()==='rake')useTool(true); - updateThings(dt,now/1000);animView(dt);updateHud(dt);audioTick(dt); - if(world.isDone()){endT+=dt;if(endT>2.5)finishJob()}else endT=0; + var hid=tool();if(useHeld&&(hid==='rake'||hid==='shovel'||hid==='squeegee'))useTool(false);if(altHeld&&hid==='rake')useTool(true); + updateThings(dt,now/1000);updateGhost();animView(dt);updateHud(dt); + if(!def.depot&&state==='play'&&world.isDone()){endT+=dt;if(endT>2.5)finishJob()}else endT=0; } - if(state==='menu'&&!lv)return; + audioTick(); if(state==='menu')return; U.uT.value=now/1000;U.uCam.value.copy(camera.position); renderer.render(scene,camera); } -buildMenu();show('menu');requestAnimationFrame(frame); +show('menu');requestAnimationFrame(frame); // for tests and tuning from the console -window.__ew={ff:function(sec){for(var k=0;k
    -
    Water left100%
    +
    Water left100%
    +
    @@ -267,7 +319,7 @@

    Job done

    -
    +
    From d6341093ca97f496db236a102fd80459e20aa423 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 03:02:33 +0000 Subject: [PATCH 3/6] Ebbwork: looks, phone layout, Spanish, and its place on the Back Room page - Water now mirrors the buildings on High graphics; sky, brickwork, contact shading and a smaller first-person arm. - Phone layout reworked so nothing overlaps upright or sideways; an automatic step down to Low graphics on slow machines. - Spanish for the whole game. - Card in the Arcade section, phone row and thumbnail, README section, What's new entry and the game's subagent. The Back Room header now says thirty games. This stays on the fork branch: it has not been played on a real phone or laptop yet. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01Cw2rM7oof2mCeBWM93T7t4 --- .claude/agents/ebbwork.md | 43 + .claude/scripts/gen_game_agents.py | 1 + README.md | 5 +- e63334287a3deaa3/ebbwork/core.js | 4 +- e63334287a3deaa3/ebbwork/es.js | 97 +++ e63334287a3deaa3/ebbwork/game.js | 663 ---------------- e63334287a3deaa3/ebbwork/index.html | 750 +++++++++++++++++- e63334287a3deaa3/ebbwork/preview.jpg | Bin 0 -> 190363 bytes e63334287a3deaa3/es.js | 19 +- e63334287a3deaa3/index.html | 35 +- e63334287a3deaa3/m/index.html | 1 + e63334287a3deaa3/m/thumbs/ebbwork.jpg | Bin 0 -> 24826 bytes .../news/ngcoding10-drain-game.json | 24 + 13 files changed, 946 insertions(+), 696 deletions(-) create mode 100644 .claude/agents/ebbwork.md create mode 100644 e63334287a3deaa3/ebbwork/es.js delete mode 100644 e63334287a3deaa3/ebbwork/game.js create mode 100644 e63334287a3deaa3/ebbwork/preview.jpg create mode 100644 e63334287a3deaa3/m/thumbs/ebbwork.jpg create mode 100644 e63334287a3deaa3/news/ngcoding10-drain-game.json diff --git a/.claude/agents/ebbwork.md b/.claude/agents/ebbwork.md new file mode 100644 index 00000000..03cfb773 --- /dev/null +++ b/.claude/agents/ebbwork.md @@ -0,0 +1,43 @@ +--- +name: ebbwork +description: Specialist for Ebbwork (e63334287a3deaa3/ebbwork/). Use for any change to Ebbwork: bug fixes, new features, balance, graphics, performance, phone/touch controls. Knows its files, storage keys and the repo rules that apply to it. +--- + +You are the specialist for **Ebbwork**, a game on Arjun's site (ascoding11.github.io). You make changes to this one game and leave the rest of the repo alone. + +## What it is + +Ebbwork (Back Room), a single-player first-person flood-drainage game: each job is a flooded place, and you work out why it flooded and get it dry (three.js r187 from the site's own build with its r128 layer, then `../autores.js`; no Firebase, no rooms, no stats.js, no ads). It is our own design: the name, the six places, the tools, the prices and the text are ours. **Files:** `index.html` (the page, its styles, and one inline script for drawing, controls, sound, HUD and menus), `core.js` (everything that is not drawing, with no DOM and no three.js in it, so `node` can load it: `require('./core.js')` gives `{EWSim, EW, EWMaps}`), `es.js` (its Spanish for `../lang.js`) and `preview.jpg`. + +## Where it lives + +- Folder: `e63334287a3deaa3/ebbwork/`: `core.js`, `es.js`, `index.html`, `preview.jpg` +- Docs: the bullet for `e63334287a3deaa3/ebbwork/` in `README.md` (and the indented points under it). This is the source of truth for how the game works and stores data; read it in full before changing anything, and update it when you change behaviour, storage or file layout. +- Phone page: a row in `GROUPS` in `e63334287a3deaa3/m/index.html` and thumbnail `e63334287a3deaa3/m/thumbs/ebbwork.jpg`. + +## What it uses (detected from the code) + +- three.js (global r128 build from cdnjs, not ES modules) +- `../autores.js` loaded straight after three.min.js (automatic resolution) + +## Must stay true + +- Keep every storage path, room prefix, localStorage key, stats/leaderboard id and saved-data format working exactly as it is, so players' saved progress, settings, ratings and invite links carry over. Old names mentioned above (folder, keys, ids) are kept on purpose: never "tidy" them. +- Don't change Firebase security rules or the Firebase config, and don't create a new Firebase project. If a change needs storage the rules don't allow, stop and say so instead. +- Keep the keyboard-and-mouse version unchanged on computers, and keep the touch controls working: shown only on touch screens, nothing overlapping in portrait or with the phone sideways. +- This is a Back Room page: keep ``, keep it out of `sitemap.xml`, and never link to it from the public pages. +- Write all game text, questions and prompts in your own words; no copyrighted text. No new outside scripts, trackers or ads. + +## How to work + +1. Read `CLAUDE.md`, then this game's README entry, then the code you are about to change. Follow the code where the docs and the code disagree, and fix the docs. +2. Make the smallest change that does the job. One feature or fix per pull request; leave unrelated code alone. +3. Any change players can notice gets an entry at the top of `NEWS` in `e63334287a3deaa3/news.js` (follow the how-to at the top of that file: date, next version, `kind`, short title, bullets written for players) and the Spanish for each new line in `e63334287a3deaa3/news-es.js`. +4. Test by serving the repo (`python3 -m http.server` from the repo root) and opening `/e63334287a3deaa3/ebbwork/` with Playwright (pre-installed; `require('playwright')`, `chromium.launch()`): a laptop size such as 1366×768, a phone in portrait (390×844) and sideways (844×390) with touch on. Check the console for errors. +5. Commit and push only when asked; never open a pull request unless asked. When you do, start the description with plain-English bullets of what changed and which pages it affects, and call out anything risky. + +## Skills to use + +Load the ones that fit the task with the Skill tool: `game-graphics` (looks), `game-performance` (frame rate, load time), `threejs-materials-lighting` and `threejs-scene-setup` (they target r187 ES modules: translate to this game's r128 global build), `level-design`, `physics-tuning`, `audio-design`. General skills often show Godot or Unity code; translate the idea to plain JavaScript, and where they disagree with `CLAUDE.md` or the repo's own skills, those win. + +When you finish, report what you changed (files and why), how you tested it, and anything you could not do or that Arjun needs to decide. diff --git a/.claude/scripts/gen_game_agents.py b/.claude/scripts/gen_game_agents.py index 9069bbb6..ccf0b3d4 100644 --- a/.claude/scripts/gen_game_agents.py +++ b/.claude/scripts/gen_game_agents.py @@ -76,6 +76,7 @@ 'patchwork-tower': ['create-game-assets', 'game-feel'], 'flickerwood': ['game-ai', 'level-design', 'create-game-assets'], 'lanternhold': ['tower-defense', 'game-ai'], + 'ebbwork': ['level-design', 'physics-tuning', 'audio-design'], 'ninefold': ['puzzle'], 'quartets': ['puzzle'], 'crosslet': ['puzzle'], 'sleight': ['puzzle'], 'poopdle': ['puzzle'], 'back-four': ['puzzle'], 'starhop': ['game-feel'], 'quarry': ['survival-crafting', 'procedural-gen'], diff --git a/README.md b/README.md index 01b6b92a..0104248e 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ Personal site hosted with GitHub Pages at **https://ascoding11.github.io**, the - `offline.js`, `sw.js`, `offline.html`: offline mode (version 2). `offline.js` (a deferred ` + Ebbwork @@ -83,13 +84,14 @@ #gauge{height:9px;border-radius:5px;background:#0b1113;margin-top:4px;overflow:hidden;position:relative} #gauge i{position:absolute;left:0;top:0;bottom:0;background:var(--water);border-radius:5px;width:100%} #gauge u{position:absolute;top:-2px;bottom:-2px;width:2px;background:var(--ok);left:3%} -#inflow{margin-top:6px;font-size:12.5px;font-weight:700;color:var(--warn)} +#inflow{margin-top:6px;font-size:12.5px;font-weight:700;color:var(--warn);line-height:1.2} #right{position:absolute;right:calc(12px + env(safe-area-inset-right,0px));top:calc(12px + env(safe-area-inset-top,0px));display:flex;gap:8px;align-items:center} #clock{font-family:var(--f-d);font-weight:700;font-size:21px;letter-spacing:.04em;min-width:62px;text-align:center} #prompt{position:absolute;left:50%;top:calc(50% + 34px);transform:translateX(-50%);font-weight:700;font-size:15px;white-space:nowrap;text-align:center} #prompt .bar{height:4px;border-radius:2px;background:#0b1113;margin-top:5px;overflow:hidden} #prompt .bar i{display:block;height:100%;background:var(--hi);width:0} -#toast{position:absolute;left:50%;top:22%;transform:translateX(-50%);max-width:min(520px,86vw);text-align:center;font-weight:600;font-size:15.5px;line-height:1.35;transition:opacity .3s} +#msgs{position:absolute;left:50%;top:calc(66px + env(safe-area-inset-top,0px));transform:translateX(-50%);width:min(540px,88vw);display:flex;flex-direction:column;align-items:center;gap:8px} +#toast{max-width:100%;text-align:center;font-weight:600;font-size:15.5px;line-height:1.35;transition:opacity .3s} #toast.off{opacity:0} #hot{position:absolute;left:50%;bottom:calc(14px + env(safe-area-inset-bottom,0px));transform:translateX(-50%);display:flex;gap:6px;pointer-events:auto} #hot button{width:62px;height:58px;border-radius:10px;border:1px solid var(--line);background:rgba(14,20,23,.74);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;padding:0;position:relative;color:var(--tx-2)} @@ -134,12 +136,10 @@ .gi .own{font-weight:700;font-size:13px;color:var(--ok)} .gi.sel{border-color:var(--hi);box-shadow:inset 0 0 0 1px var(--hi)} button.gi{min-height:64px} -#guide{position:absolute;left:50%;top:calc(64px + env(safe-area-inset-top,0px));transform:translateX(-50%);max-width:min(480px,88vw);text-align:center;font-weight:700;font-size:15px;line-height:1.35;border-color:var(--hi)} -body.touch #guide{top:calc(124px + env(safe-area-inset-top,0px))} -body.touch #toast{top:calc(190px + env(safe-area-inset-top,0px))} -#tRot{width:50px;height:50px;right:calc(178px + env(safe-area-inset-right,0px));bottom:calc(78px + env(safe-area-inset-bottom,0px));font-size:12px} +#guide{max-width:100%;text-align:center;font-weight:700;font-size:15px;line-height:1.35;border-color:var(--hi)} +#tRot{width:50px;height:50px;right:calc(178px + env(safe-area-inset-right,0px));bottom:calc(78px + env(safe-area-inset-bottom,0px));font-size:10.5px;letter-spacing:0} @media (max-width:640px){.split{grid-template-columns:1fr}} -@media (orientation:landscape) and (max-height:440px){body.touch #guide{top:calc(66px + env(safe-area-inset-top,0px))}body.touch #toast{top:calc(120px + env(safe-area-inset-top,0px))}.gear,.load{max-height:44vh}} +@media (orientation:landscape) and (max-height:440px){.gear,.load{max-height:44vh}} /* ---------- touch ---------- */ #touch{display:none;position:absolute;inset:0;pointer-events:none;font-family:var(--f-d)} @@ -154,13 +154,14 @@ #tAlt{width:60px;height:60px;right:calc(108px + env(safe-area-inset-right,0px));bottom:calc(18px + env(safe-area-inset-bottom,0px))} #tJump{width:60px;height:60px;right:calc(24px + env(safe-area-inset-right,0px));bottom:calc(114px + env(safe-area-inset-bottom,0px))} #tAct{width:62px;height:62px;right:calc(104px + env(safe-area-inset-right,0px));bottom:calc(92px + env(safe-area-inset-bottom,0px));background:rgba(86,199,207,.55)} -#tCrouch{width:50px;height:50px;right:calc(178px + env(safe-area-inset-right,0px));bottom:calc(18px + env(safe-area-inset-bottom,0px));font-size:12px} -body.touch #hot{bottom:auto;top:calc(64px + env(safe-area-inset-top,0px))} -body.touch #hot button{width:52px;height:50px} +#tCrouch{width:50px;height:50px;right:calc(178px + env(safe-area-inset-right,0px));bottom:calc(18px + env(safe-area-inset-bottom,0px));font-size:10.5px;letter-spacing:0} +body.touch #hot{bottom:auto;top:calc(114px + env(safe-area-inset-top,0px))} +body.touch #msgs{top:calc(176px + env(safe-area-inset-top,0px))} +body.touch #hot{max-width:calc(100vw - 12px)} +body.touch #hot button{flex:0 1 52px;min-width:34px;width:auto;height:50px} body.touch #hot button svg{width:22px;height:22px} body.touch #hot button span,body.touch #hot button em{display:none} body.touch #tip{display:none} -body.touch #toast{top:calc(124px + env(safe-area-inset-top,0px))} @media (orientation:portrait){ body.touch #stat{min-width:0;max-width:calc(100vw - 186px - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px))} body.touch #clock{display:none} @@ -168,7 +169,8 @@ } @media (orientation:landscape) and (max-height:440px){ body.touch #hot{top:calc(10px + env(safe-area-inset-top,0px))} - body.touch #toast{top:calc(70px + env(safe-area-inset-top,0px))} + body.touch #hot button{flex-basis:46px;height:44px} + body.touch #msgs{top:calc(64px + env(safe-area-inset-top,0px));width:min(430px,52vw)} body.touch #stat{min-width:150px;max-width:26vw} body.touch #stat .lbl{font-size:11px} .card{padding:13px 15px} @@ -198,8 +200,7 @@ -
    - +