Files

24 lines
21 KiB
JavaScript

(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=`https://advent-of-slop.quesma.com`,t=`
nav {
position: fixed;
top: 0;
right: 0;
z-index: 2147483647;
display: flex;
flex-wrap: wrap;
gap: 0 0.35em;
max-width: 100vw;
box-sizing: border-box;
padding: 0.35rem 0.7rem;
border-bottom-left-radius: 0.5rem;
background: #b8232f;
font: 700 0.8125rem/1.2 system-ui, sans-serif;
}
a {
color: #f6ecd6;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
`,n=(e,t)=>{let n=document.createElement(`a`);return n.href=e,n.textContent=t,n},r=class extends HTMLElement{connectedCallback(){let r=Number(this.getAttribute(`day`));if(!Number.isInteger(r)||r<1||r>24)throw Error(`<advent-badge> needs day="1" to day="24", got ${this.getAttribute(`day`)}`);let i=this.getAttribute(`name`);if(i===null||i.trim()===``)throw Error(`<advent-badge> needs name="...", the title of its day, such as name="Living fishtank"`);let a=document.createElement(`style`);a.textContent=t;let o=document.createElement(`nav`);o.append(n(`${e}/`,`Advent of AI Slop`),n(`${e}/day/${r}/`,`[Day ${r}] ${i}`)),this.attachShadow({mode:`open`}).append(a,o)}};customElements.define(`advent-badge`,r);var i=1200,a=e=>{let t=Math.sin(e*127.1+311.7)*43758.5453;return t-Math.floor(t)};function o(e,t){let n=Math.random()*1e4,r=t===0?[140,300]:t===1?[100,220]:[70,150],i=r[0]+Math.random()*(r[1]-r[0]);return{x:e,w:t===0?70+Math.random()*90:t===1?60+Math.random()*80:55+Math.random()*70,h:i,tone:Math.random(),seed:n,spire:Math.random()<.16}}function s(e,t){let n=e.createLinearGradient(0,0,0,508);n.addColorStop(0,`#0c1024`),n.addColorStop(.55,`#1c2748`),n.addColorStop(.85,`#3a3f6b`),n.addColorStop(1,`#6b4a63`),e.fillStyle=n,e.fillRect(0,0,i,508);for(let n=0;n<70;n++){let r=a(n*3.7)*i,o=a(n*9.1)*508*.55;e.fillStyle=`rgba(240,240,255,${(.25+.5*(.35+.65*Math.abs(Math.sin(t*(.6+a(n)*1.4)+n))))*(1-o/(508*.7))})`,e.fillRect(r,o,2,2)}let r=1010,o=e.createRadialGradient(r,92,8,r,92,60);o.addColorStop(0,`rgba(255,244,214,0.55)`),o.addColorStop(1,`rgba(255,244,214,0)`),e.fillStyle=o,e.fillRect(950,32,120,120),e.fillStyle=`#f8ecc8`,e.beginPath(),e.arc(r,92,26,0,Math.PI*2),e.fill(),e.fillStyle=`rgba(200,180,140,0.35)`,e.beginPath(),e.arc(1002,86,5,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(1017,100,7,0,Math.PI*2),e.fill()}function c(e,t,n,r){let i=508-(n===2?26:n===1?12:0),o=n===0?[`#141a33`,`#182040`]:n===1?[`#1d2547`,`#232c52`]:[`#2a3358`,`#323d66`];for(let s of t){if(s.x>1210||s.x+s.w<-10)continue;let t=i-s.h;if(e.fillStyle=o[+(s.tone>.5)],e.fillRect(s.x,t,s.w,s.h),s.spire&&(e.beginPath(),e.moveTo(s.x+s.w*.5-8,t),e.lineTo(s.x+s.w*.5,t-34),e.lineTo(s.x+s.w*.5+8,t),e.closePath(),e.fill()),e.fillStyle=`rgba(226,234,250,0.85)`,e.fillRect(s.x-2,t,s.w+4,5),n>0){let n=Math.max(2,Math.floor(s.w/22)),i=Math.max(2,Math.floor(s.h/26));for(let o=0;o<i;o++)for(let c=0;c<n;c++){let l=a(s.seed+o*31.3+c*7.7);if(l<.42)continue;let u=l>.9?.6+.4*Math.sin(r*3+s.seed+o):1;e.fillStyle=l>.75?`rgba(255,196,102,${.75*u})`:`rgba(160,200,255,${.4*u})`,e.fillRect(s.x+8+c*((s.w-16)/n),t+12+o*((s.h-20)/i),8,10)}}}}function l(e,t){e.fillStyle=`#cfd8ea`,e.fillRect(0,482,i,26),e.fillStyle=`#eef3fb`,e.fillRect(0,482,i,6),e.fillStyle=`#9aa6c0`,e.fillRect(0,504,i,4);let n=e.createLinearGradient(0,508,0,600);n.addColorStop(0,`#3a4056`),n.addColorStop(1,`#232838`),e.fillStyle=n,e.fillRect(0,508,i,92),e.fillStyle=`rgba(226,234,250,0.5)`;let r=t%104;for(let t=-r;t<i;t+=104)e.fillRect(t,552,46,6);e.fillStyle=`#e8eefb`;let o=t%210;for(let n=-o;n<1410;n+=210){let r=a(Math.floor((t+n)/210)*13.7);e.beginPath(),e.ellipse(n,502,40+r*30,9+r*5,0,Math.PI,0),e.fill()}}function u(e,t,n){e.strokeStyle=`#4a5474`,e.lineWidth=5,e.beginPath(),e.moveTo(t,502),e.lineTo(t,358),e.quadraticCurveTo(t,340,t+22,340),e.stroke(),e.lineWidth=1;let r=t+26,i=e.createRadialGradient(r,344,2,r,344,46);i.addColorStop(0,`rgba(255,214,140,${.5+.06*Math.sin(n*7+t)})`),i.addColorStop(1,`rgba(255,214,140,0)`),e.fillStyle=i,e.fillRect(r-46,298,92,92),e.fillStyle=`#ffdf9e`,e.beginPath(),e.ellipse(r,344,8,6,0,0,Math.PI*2),e.fill(),e.fillStyle=`#38405c`,e.fillRect(r-10,332,20,6)}function d(e,t,n){let r=t.x,i=t.x+t.w;e.strokeStyle=`#4a5474`,e.lineWidth=5,e.beginPath(),e.moveTo(r,502),e.lineTo(r,358),e.stroke(),e.beginPath(),e.moveTo(i,502),e.lineTo(i,358),e.stroke(),e.lineWidth=1,e.strokeStyle=`#69719a`,e.beginPath(),e.moveTo(r,358),e.quadraticCurveTo((r+i)/2,468,i,358),e.stroke();let a=[`#ff5d5d`,`#ffd166`,`#5dd06a`,`#5da9ff`];for(let t=1;t<11;t++){let o=t/11,s=(1-o)*(1-o)*r+2*(1-o)*o*((r+i)/2)+o*o*i,c=(1-o)*(1-o)*358+2*(1-o)*o*468+o*o*358,l=a[t%a.length],u=.65+.35*Math.sin(n*4+t*1.3),d=e.createRadialGradient(s,c+8,1,s,c+8,14);d.addColorStop(0,l+`aa`),d.addColorStop(1,l+`00`),e.fillStyle=d,e.fillRect(s-14,c-6,28,28),e.globalAlpha=.55+.45*u,e.fillStyle=l,e.beginPath(),e.ellipse(s,c+8,4.5,6.5,0,0,Math.PI*2),e.fill(),e.globalAlpha=1}}function f(e,t,n){switch(t.kind){case`pothole`:e.fillStyle=`#161a26`,e.beginPath(),e.ellipse(t.x+t.w/2,524,t.w/2,10,0,0,Math.PI*2),e.fill(),e.strokeStyle=`rgba(226,234,250,0.5)`,e.beginPath(),e.ellipse(t.x+t.w/2,522,t.w/2+4,12,0,Math.PI*1.05,Math.PI*1.95),e.stroke();break;case`snowman`:{let n=t.x+t.w/2;e.fillStyle=`#f2f6ff`,e.beginPath(),e.arc(n,488,20,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(n,458,14,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(n,436,10,0,Math.PI*2),e.fill(),e.fillStyle=`#20242f`,e.beginPath(),e.arc(n-4,434,1.8,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(n+3,434,1.8,0,Math.PI*2),e.fill(),e.fillStyle=`#ff7f3f`,e.beginPath(),e.moveTo(n+8,436),e.lineTo(n+20,439),e.lineTo(n+8,441),e.fill(),e.fillStyle=`#b8232f`,e.fillRect(n-12,424,24,4),e.fillRect(n-8,412,16,13),e.strokeStyle=`#7a5a3a`,e.lineWidth=2,e.beginPath(),e.moveTo(n-12,456),e.lineTo(n-26,446),e.stroke(),e.beginPath(),e.moveTo(n+12,456),e.lineTo(n+26,448),e.stroke(),e.lineWidth=1;break}case`tree`:{let n=t.x+t.w/2;e.fillStyle=`#5a3a26`,e.fillRect(n-5,490,10,18);let r=[`#1e5c3a`,`#236b44`,`#2a7a4e`];for(let t=0;t<3;t++){let i=490-t*24,a=30-t*7;e.fillStyle=r[t],e.beginPath(),e.moveTo(n-a,i),e.lineTo(n,i-34),e.lineTo(n+a,i),e.closePath(),e.fill(),e.fillStyle=`rgba(232,238,251,0.8)`,e.beginPath(),e.moveTo(n-a,i),e.lineTo(n,i-34),e.lineTo(n+a,i),e.lineTo(n+a-8,i),e.lineTo(n,i-26),e.lineTo(n-a+8,i),e.closePath(),e.fill()}e.fillStyle=`#ffd166`,e.beginPath(),e.arc(n,416,4,0,Math.PI*2),e.fill();break}case`gift`:{let n=[{dx:0,w:46,h:30,c:`#b8232f`,r:`#ffd166`},{dx:8,w:34,h:24,c:`#2f7d5c`,r:`#f2ecdd`}],r=508;for(let i of n)r-=i.h,e.fillStyle=i.c,e.fillRect(t.x+i.dx,r,i.w,i.h),e.fillStyle=i.r,e.fillRect(t.x+i.dx+i.w/2-3,r,6,i.h),e.fillRect(t.x+i.dx,r+i.h/2-2,i.w,4);e.strokeStyle=`rgba(232,238,251,0.7)`,e.strokeRect(t.x-1,453,48,1);break}case`bin`:e.fillStyle=`#2f5d4a`,e.beginPath(),e.moveTo(t.x+4,508),e.lineTo(t.x,456),e.lineTo(t.x+40,456),e.lineTo(t.x+36,508),e.closePath(),e.fill(),e.fillStyle=`#3d7460`,e.fillRect(t.x-3,448,46,9),e.fillStyle=`#20453a`,e.fillRect(t.x+14,442,12,6),e.fillStyle=`#dfe6f4`,e.beginPath(),e.arc(t.x+20,442,10,Math.PI,0),e.fill();break;case`garland`:d(e,t,n)}}function p(e,t,n){if(t.taken)return;let r=Math.sin(n*3+t.x*.05)*5,i=t.y+r;e.save(),e.translate(t.x,i);let a=e.createRadialGradient(0,0,2,0,0,26);a.addColorStop(0,`rgba(255,220,150,0.35)`),a.addColorStop(1,`rgba(255,220,150,0)`),e.fillStyle=a,e.fillRect(-26,-26,52,52),t.kind===`fish`?(e.rotate(Math.sin(n*2+t.x)*.12),e.fillStyle=`#b8c8dd`,e.beginPath(),e.ellipse(0,0,15,8,0,0,Math.PI*2),e.fill(),e.fillStyle=`#93a7c2`,e.beginPath(),e.moveTo(-13,0),e.lineTo(-22,-7),e.lineTo(-22,7),e.closePath(),e.fill(),e.fillStyle=`#20242f`,e.beginPath(),e.arc(7,-2,1.8,0,Math.PI*2),e.fill(),e.strokeStyle=`rgba(255,255,255,0.5)`,e.beginPath(),e.arc(2,0,8,-.6,.9),e.stroke()):(e.fillStyle=`#ff8c42`,e.beginPath(),e.moveTo(12,-4),e.lineTo(-10,6),e.lineTo(-8,12),e.lineTo(12,2),e.closePath(),e.fill(),e.fillStyle=`#3f9d5a`,e.beginPath(),e.moveTo(11,-3),e.quadraticCurveTo(18,-14,22,-10),e.quadraticCurveTo(17,-6,13,0),e.closePath(),e.fill(),e.beginPath(),e.moveTo(12,0),e.quadraticCurveTo(23,-6,25,-1),e.quadraticCurveTo(18,1,13,3),e.closePath(),e.fill()),e.restore()}function m(e,t,n,r,i){e.strokeStyle=`#181c28`,e.lineWidth=5,e.beginPath(),e.arc(t,n,r,0,Math.PI*2),e.stroke(),e.strokeStyle=`#8f9ab8`,e.lineWidth=1.6;for(let a=0;a<3;a++){let o=i+a*Math.PI/3;e.beginPath(),e.moveTo(t-Math.cos(o)*r,n-Math.sin(o)*r),e.lineTo(t+Math.cos(o)*r,n+Math.sin(o)*r),e.stroke()}e.fillStyle=`#c9d2e6`,e.beginPath(),e.arc(t,n,3,0,Math.PI*2),e.fill(),e.lineWidth=1}function h(e,t,n,r,i){let a=(t+r)/2+12,o=(n+i)/2+6;e.strokeStyle=`#d9a24a`,e.lineWidth=5,e.beginPath(),e.moveTo(t,n),e.quadraticCurveTo(a,o,r,i),e.stroke(),e.lineWidth=1}function g(e,t,n,r,i,a){let o={x:t-36,y:n-24},s={x:t+36,y:n-24};m(e,o.x,o.y,24,r),m(e,s.x,s.y,24,r),e.strokeStyle=`#c23a3a`,e.lineWidth=4,e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(t-4,n-52),e.lineTo(s.x,s.y),e.moveTo(t-4,n-52),e.lineTo(t+2,n-26),e.lineTo(o.x,o.y),e.moveTo(t+2,n-26),e.lineTo(s.x-6,n-56),e.moveTo(s.x-6,n-56),e.lineTo(s.x,s.y),e.stroke(),e.lineWidth=1,e.strokeStyle=`#39415f`,e.lineWidth=3.5,e.beginPath(),e.moveTo(s.x-6,n-56),e.lineTo(s.x+2,n-66),e.lineTo(s.x+12,n-62),e.stroke(),e.lineWidth=1;let c=t+2+Math.cos(r*2)*13,l=n-26+Math.sin(r*2)*13,u=t+2-Math.cos(r*2)*13,d=n-26-Math.sin(r*2)*13;e.strokeStyle=`#20242f`,e.lineWidth=3,e.beginPath(),e.moveTo(c-6,l),e.lineTo(c+6,l),e.stroke(),e.beginPath(),e.moveTo(u-6,d),e.lineTo(u+6,d),e.stroke(),e.lineWidth=1;let f=i*20,p=n-78+f,g=Math.sin(a*11)*1.4;h(e,t-6,p+16,c,l),h(e,t-8,p+16,u,d),e.fillStyle=`#e4ddca`,e.beginPath(),e.moveTo(t-26,p-4+g),e.lineTo(t-44,p-12+g),e.lineTo(t-28,p+8+g),e.closePath(),e.fill(),e.fillStyle=`#f4f1e8`,e.beginPath(),e.ellipse(t-4,p+g,27,20,-.08,0,Math.PI*2),e.fill(),e.fillStyle=`rgba(180,175,155,0.35)`,e.beginPath(),e.ellipse(t-6,p+8+g,22,11,-.08,0,Math.PI),e.fill();let _=t+26-i*10,v=p-30+f*1.4+g;e.strokeStyle=`#f4f1e8`,e.lineWidth=12,e.lineCap=`round`,e.beginPath(),e.moveTo(t+8,p-6+g),e.quadraticCurveTo(t+22-i*14,p-22+f+g,_,v),e.stroke(),e.lineWidth=1,e.lineCap=`butt`,e.fillStyle=`#f4f1e8`,e.beginPath(),e.arc(_,v,11,0,Math.PI*2),e.fill(),e.strokeStyle=`#e4ddca`,e.lineWidth=2.5,e.beginPath(),e.moveTo(_-4,v-9),e.quadraticCurveTo(_-10,v-18,_-4,v-20),e.stroke(),e.lineWidth=1,e.fillStyle=`#ff9d3c`,e.beginPath(),e.moveTo(_+6,v-5),e.lineTo(_+46,v+1),e.lineTo(_+8,v+6),e.closePath(),e.fill(),e.fillStyle=`#f2852a`,e.beginPath(),e.moveTo(_+8,v+4),e.quadraticCurveTo(_+28,v+18,_+44,v+2),e.lineTo(_+8,v+7),e.closePath(),e.fill(),e.fillStyle=`#20242f`,e.beginPath(),e.arc(_+4,v-3,2.2,0,Math.PI*2),e.fill(),e.fillStyle=`#e8e2d0`,e.beginPath(),e.moveTo(t+2,p-6+g),e.quadraticCurveTo(t+24,p-2+g,s.x+8,n-64),e.quadraticCurveTo(t+20,p+6+g,t+4,p+2+g),e.closePath(),e.fill()}function _(e,t,n,r,i,a){let o={x:t,y:n-27};m(e,o.x,o.y,27,r),e.strokeStyle=`#39415f`,e.lineWidth=4,e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(t-2,n-74),e.stroke(),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x+16,o.y-6),e.stroke(),e.lineWidth=1,e.fillStyle=`#6b3a2a`,e.beginPath(),e.ellipse(t-4,n-78,16,5,-.06,0,Math.PI*2),e.fill();let s=o.x+Math.cos(r*2)*15,c=o.y+Math.sin(r*2)*15,l=o.x-Math.cos(r*2)*15,u=o.y-Math.sin(r*2)*15;e.strokeStyle=`#20242f`,e.lineWidth=3,e.beginPath(),e.moveTo(s-6,c),e.lineTo(s+6,c),e.stroke(),e.beginPath(),e.moveTo(l-6,u),e.lineTo(l+6,u),e.stroke(),e.lineWidth=1;let d=i*18,f=n-100+d,p=Math.sin(a*10+1)*1.4;e.strokeStyle=`#7a4e33`,e.lineWidth=6,e.lineCap=`round`,e.beginPath(),e.moveTo(t-6,f+14),e.quadraticCurveTo(t+12,f+40,s,c),e.stroke(),e.beginPath(),e.moveTo(t-10,f+14),e.quadraticCurveTo(t+6,f+44,l,u),e.stroke(),e.lineWidth=1,e.lineCap=`butt`,e.fillStyle=`#f2ecdd`,e.beginPath(),e.arc(t-32,f-2+p,6,0,Math.PI*2),e.fill(),e.fillStyle=`#8a5a3c`,e.beginPath(),e.ellipse(t-8,f+p,28,17,-.1,0,Math.PI*2),e.fill(),e.fillStyle=`rgba(240,230,210,0.25)`,e.beginPath(),e.ellipse(t-10,f+7+p,22,8,-.1,0,Math.PI),e.fill();let h=t+24-i*12,g=f-26+d*1.6+p;e.strokeStyle=`#8a5a3c`,e.lineWidth=11,e.lineCap=`round`,e.beginPath(),e.moveTo(t+8,f-4+p),e.quadraticCurveTo(t+20-i*12,f-16+d+p,h,g),e.stroke(),e.lineWidth=1,e.lineCap=`butt`,e.fillStyle=`#8a5a3c`,e.beginPath(),e.ellipse(h+4,g+2,13,9,.15,0,Math.PI*2),e.fill(),e.fillStyle=`#6b4228`,e.beginPath(),e.arc(h+14,g+4,5,0,Math.PI*2),e.fill(),e.fillStyle=`#20242f`,e.beginPath(),e.arc(h+17,g+3,1.8,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(h+6,g-2,2,0,Math.PI*2),e.fill(),e.fillStyle=`#7a4e33`,e.beginPath(),e.ellipse(h-6,g-4,6,3,-.6,0,Math.PI*2),e.fill(),e.strokeStyle=`#d9c9a3`,e.lineWidth=3,e.lineCap=`round`;for(let t of[-1,1]){let n=h-2+t*4;e.beginPath(),e.moveTo(n,g-7),e.quadraticCurveTo(n+t*6,g-24,n+t*2,g-32),e.stroke(),e.beginPath(),e.moveTo(n+t*4,g-18),e.lineTo(n+t*13,g-24),e.stroke(),e.beginPath(),e.moveTo(n+t*3,g-26),e.lineTo(n+t*11,g-33),e.stroke()}let _=e.createRadialGradient(h+17,g+3,1,h+17,g+3,12);_.addColorStop(0,`rgba(255,60,60,0.55)`),_.addColorStop(1,`rgba(255,60,60,0)`),e.fillStyle=_,e.fillRect(h+5,g-9,24,24),e.lineWidth=1,e.lineCap=`butt`}var v={pelican:{v0:330,accel:9,vmax:700,jumpV:980,jumps:1,standH:118,duckH:66},reindeer:{v0:300,accel:7,vmax:640,jumpV:850,jumps:2,standH:132,duckH:62}},y=2600,b=190,x=84,S=(e,t)=>e+Math.random()*(t-e),C=class{phase=`menu`;char=`pelican`;time=0;scroll=0;speed=0;pickupsGot=0;best=0;spec=v.pelican;rider=this.freshRider();far=[];mid=[];near=[];lamps=[];obstacles=[];pickups=[];flakes=[];distSinceSpawn=1e9;distSincePickup=0;garlandCooldown=0;score=0;onHud;onCrash;constructor(e,t){this.onHud=e,this.onCrash=t,this.buildLayer();let n=60;for(;n<i+300;)this.lamps.push(n),n+=300;for(let e=0;e<130;e++)this.flakes.push({x:Math.random()*i,y:Math.random()*600,r:S(1,3),vy:S(26,70),sway:S(10,30),phase:Math.random()*Math.PI*2})}buildLayer(){for(let[e,t]of[[0,this.far],[1,this.mid],[2,this.near]]){let n=-40;for(;n<i+200;){let r=o(n,e);t.push(r),n+=r.w+S(6,40)}}}freshRider(){return{y:508,vy:0,onGround:!0,jumpsLeft:1,duck:0,crank:0,crashT:0}}setChar(e,t){this.char=e,this.spec=v[e],this.best=t}start(){this.phase=`playing`,this.time=0,this.scroll=0,this.speed=this.spec.v0,this.rider=this.freshRider(),this.rider.jumpsLeft=this.spec.jumps,this.obstacles=[],this.pickups=[],this.pickupsGot=0,this.score=0,this.distSinceSpawn=600,this.distSincePickup=0,this.garlandCooldown=3}jump(){if(this.phase!==`playing`)return;let e=this.rider;e.onGround?(e.vy=-this.spec.jumpV,e.onGround=!1,e.jumpsLeft=this.spec.jumps-1):e.jumpsLeft>0&&(e.vy=-this.spec.jumpV*.88,--e.jumpsLeft)}setDuck(e){this.duckOn=e}duckOn=!1;get crashDone(){return this.rider.crashT>1.15}pause(e){e&&this.phase===`playing`?this.phase=`paused`:!e&&this.phase===`paused`&&(this.phase=`playing`)}get meters(){return Math.floor(this.scroll/40)}get kmh(){return Math.round(this.speed*.065)}get scoreNow(){return this.score}update(e){this.time+=e;for(let t of this.flakes)t.y+=t.vy*e,t.x-=(this.phase===`playing`?this.speed*.12:18)*e+Math.sin(this.time*2+t.phase)*t.sway*e,t.y>600&&(t.y=-4,t.x=Math.random()*i),t.x<-4&&(t.x=i+4);if(this.phase!==`playing`&&this.phase!==`crashed`){this.pushHud();return}let t=this.rider;if(this.phase===`crashed`){t.crashT+=e,t.vy+=y*e,t.y=Math.min(508,t.y+t.vy*e);return}this.speed=Math.min(this.spec.vmax,this.spec.v0+this.spec.accel*this.time);let n=this.speed*e;this.scroll+=n,t.crank+=n*.045;let r=[.22,.45,.72];for(let[e,t]of[[0,this.far],[1,this.mid],[2,this.near]]){for(let i of t)i.x-=n*r[e];let i=0;for(let e of t)i=Math.max(i,e.x+e.w);for(let n of t)if(n.x+n.w<-60){n.x=i+S(6,40);let t=o(n.x,e);n.w=t.w,n.h=t.h,n.tone=t.tone,n.seed=t.seed,n.spire=t.spire,i=n.x+n.w}}for(let e=0;e<this.lamps.length;e++)this.lamps[e]-=n,this.lamps[e]<-40&&(this.lamps[e]=Math.max(...this.lamps)+300);let a=this.duckOn&&t.onGround?1:this.duckOn?.5:0;t.duck+=(a-t.duck)*Math.min(1,e*14);let s=this.duckOn&&!t.onGround?y*1.55:y;t.vy+=s*e,t.y+=t.vy*e,t.y>=508&&(t.y=508,t.vy=0,t.onGround=!0,t.jumpsLeft=this.spec.jumps),this.distSinceSpawn+=n;let c=240+this.speed*.42;if(this.distSinceSpawn>c*S(.85,1.6)){this.distSinceSpawn=0,--this.garlandCooldown;let e=[`pothole`,`snowman`,`tree`,`gift`,`bin`];if(this.garlandCooldown<=0&&this.time>12)this.garlandCooldown=5,this.obstacles.push({kind:`garland`,x:i+60,w:230,h:0,seed:Math.random()});else{let t=e[Math.floor(Math.random()*e.length)],[n,r]={pothole:[64,16],snowman:[40,96],tree:[60,92],gift:[46,54],bin:[40,66]}[t];this.obstacles.push({kind:t,x:i+60,w:n,h:r,seed:Math.random()})}}if(this.distSincePickup+=n,this.distSincePickup>200){this.distSincePickup=0;let e=this.char===`pelican`?`fish`:`carrot`,t=Math.random()<.45,n=t?508-S(120,175):478;for(let r=0;r<3;r++)this.pickups.push({kind:e,x:i+80+r*42,y:t?n-Math.sin(r/2*Math.PI)*26:n,taken:!1})}let l=t.y-(this.spec.standH-(this.spec.standH-this.spec.duckH)*t.duck),u=b-x/2;for(let e of this.obstacles)if(e.x-=n,e.kind===`garland`)218>e.x+14&&u<e.x+e.w-14&&l<438&&t.y>358&&this.crash();else if(e.kind!==`pothole`){let n=508-e.h;218>e.x+6&&u<e.x+e.w-6&&t.y>n+8&&this.crash()}else 218>e.x+10&&168<e.x+e.w-10&&t.onGround&&this.crash();this.obstacles=this.obstacles.filter(e=>e.x+e.w>-80);for(let e of this.pickups)e.x-=n,!e.taken&&Math.abs(e.x-b)<34&&Math.abs(e.y-(t.y-70))<52&&(e.taken=!0,this.pickupsGot+=1,this.score+=50);this.pickups=this.pickups.filter(e=>e.x>-40),this.score=Math.max(this.score,0),this.score+=n*.1,this.pushHud()}crash(){if(this.phase!==`playing`)return;this.phase=`crashed`,this.rider.crashT=0,this.rider.vy=-420;let e=Math.floor(this.score),t=e>this.best;this.onCrash(e,this.meters,this.pickupsGot,Math.max(this.best,e),t)}pushHud(){this.onHud({score:Math.floor(this.score),meters:this.meters,kmh:this.kmh,fish:this.pickupsGot,best:this.best})}render(e){s(e,this.time),c(e,this.far,0,this.time),c(e,this.mid,1,this.time),c(e,this.near,2,this.time),l(e,this.scroll);for(let t of this.lamps)t>-60&&t<1260&&u(e,t,this.time);for(let t of this.obstacles)t.kind===`garland`&&f(e,t,this.time);for(let t of this.obstacles)t.kind!==`garland`&&f(e,t,this.time);for(let t of this.pickups)p(e,t,this.time);let t=this.rider;if(e.save(),this.phase===`crashed`){e.translate(b,t.y-60),e.rotate(t.crashT*5.2),e.translate(-190,-(t.y-60)),e.fillStyle=`#ffd166`;for(let n=0;n<6;n++){let r=n/6*Math.PI*2+t.crashT*3,i=40+t.crashT*60;e.beginPath(),e.arc(b+Math.cos(r)*i,t.y-70+Math.sin(r)*i*.6,4-t.crashT*2,0,Math.PI*2),e.fill()}}this.char===`pelican`?g(e,b,t.y,t.crank,t.duck,this.time):_(e,b,t.y,t.crank,t.duck,this.time),e.restore(),e.fillStyle=`rgba(240,245,255,0.9)`;for(let t of this.flakes)e.globalAlpha=.35+t.r/4,e.beginPath(),e.arc(t.x,t.y,t.r,0,Math.PI*2),e.fill();e.globalAlpha=1;let n=e.createRadialGradient(i/2,300,330,i/2,300,630);n.addColorStop(0,`rgba(0,0,0,0)`),n.addColorStop(1,`rgba(5,8,18,0.5)`),e.fillStyle=n,e.fillRect(0,0,i,600)}},w=document.getElementById(`game`),T=w?.getContext(`2d`);if(!w||!T)throw Error(`canvas #game missing`);var E=T,D=e=>{let t=document.getElementById(e);if(!t)throw Error(`missing #${e}`);return t},O=D(`hud-score`),k=D(`hud-dist`),A=D(`hud-speed`),j=D(`hud-fish`),M=D(`hud-best`),N=D(`menu`),P=D(`pause`),F=D(`gameover`),I=D(`final-score`),L=D(`final-dist`),R=D(`final-fish`),z=D(`best-line`),B=D(`crash-line`),V=e=>`aos5-best-${e}`,H=e=>Number(localStorage.getItem(V(e))??`0`)||0,U=new C(e=>{O.textContent=String(e.score),k.textContent=String(e.meters),A.textContent=String(e.kmh),j.textContent=String(e.fish),M.textContent=String(e.best)},(e,t,n,r,i)=>{I.textContent=String(e),L.textContent=String(t),R.textContent=String(n),i?(localStorage.setItem(V(U.char),String(r)),z.textContent=`★ new personal best!`,z.classList.add(`new`)):(z.textContent=`best: ${r}`,z.classList.remove(`new`));let a=U.char===`pelican`?[`Squawk.`,`Honk. That was not a ramp.`,`The fish saw everything.`]:[`Clatter.`,`The unicycle disagrees.`,`Rudolph needs a moment.`];B.textContent=a[Math.floor(Math.random()*a.length)],F.classList.remove(`hidden`),M.textContent=String(r)});function W(e){U.setChar(e,H(e)),M.textContent=String(H(e)),U.start(),N.classList.add(`hidden`),F.classList.add(`hidden`)}for(let e of document.querySelectorAll(`#cards .card`))e.addEventListener(`click`,()=>{let t=e.dataset.char;(t===`pelican`||t===`reindeer`)&&W(t)});D(`restart-btn`).addEventListener(`click`,()=>W(U.char)),D(`menu-btn`).addEventListener(`click`,()=>{F.classList.add(`hidden`),N.classList.remove(`hidden`),U.phase=`menu`});var G=new Set([`Space`,`ArrowUp`,`KeyW`]),K=new Set([`ArrowDown`,`KeyS`]);window.addEventListener(`keydown`,e=>{if(!e.repeat){if(G.has(e.code)){if(e.preventDefault(),U.phase===`menu`&&!N.classList.contains(`hidden`))return;U.phase===`crashed`&&U.crashDone&&W(U.char),U.jump()}else K.has(e.code)?(e.preventDefault(),U.setDuck(!0)):e.code===`KeyR`&&(U.phase===`crashed`||U.phase===`playing`)?W(U.char):e.code===`KeyP`||e.code===`Escape`?(U.pause(U.phase===`playing`),P.classList.toggle(`hidden`,U.phase!==`paused`)):U.phase===`menu`&&!N.classList.contains(`hidden`)&&(e.code===`Digit1`&&W(`pelican`),e.code===`Digit2`&&W(`reindeer`))}}),window.addEventListener(`keyup`,e=>{K.has(e.code)&&U.setDuck(!1)}),w.addEventListener(`pointerdown`,e=>{e.preventDefault(),U.phase===`playing`&&U.jump()});var q=performance.now();function J(e){let t=Math.min(.033,(e-q)/1e3);q=e,U.update(t),U.render(E),requestAnimationFrame(J)}requestAnimationFrame(J),window.__aos5=U;