1import{r as e,j as t}from"./vendor-CYC9ZCxI.js";import{z as s,R as r,Z as a,J as n}from"./ui-BO3fKhHF.js";import{m as l}from"./animations-DCL67Ucd.js";const i=({difficulty:i,onBack:d})=>{const c=e.useRef(null),o=e.useRef(0),x=e.useRef(0),[u,m]=e.useState(0),[h,b]=e.useState(!1),[p,f]=e.useState([]),[j,v]=e.useState(0),[g,w]=e.useState("pro"===i?8.2:6.4),[N,k]=e.useState(!1),[y,S]=e.useState(!1),[R,C]=e.useState("Jump cacti and duck under birds."),E=e.useRef(0),M=e.useRef("pro"===i?8.2:6.4),z=e.useRef(!1),D=e.useRef(0);e.useEffect(()=>{E.current=j},[j]),e.useEffect(()=>{M.current=g},[g]),e.useEffect(()=>{z.current=h},[h]),e.useEffect(()=>{D.current=u},[u]);const A="pro"===i?700:420,T=e.useCallback(()=>{m(0),b(!1),f([]),v(0),w("pro"===i?8.2:6.4),k(!1),S(!1),C("Jump cacti and duck under birds."),x.current=0,o.current=0,E.current=0,M.current="pro"===i?8.2:6.4,z.current=!1,D.current=0},[i]),J=e.useCallback(()=>{N&&!y&&0===x.current&&0===D.current&&(x.current=18)},[y,N]),L=e.useCallback(e=>{!N||y||D.current>0||b(e)},[y,N]);e.useEffect(()=>{const e=e=>{"Space"!==e.code&&"ArrowUp"!==e.key||(e.preventDefault(),J()),"ArrowDown"===e.key&&L(!0)},t=e=>{"ArrowDown"===e.key&&L(!1)};return window.addEventListener("keydown",e),window.addEventListener("keyup",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t)}},[L,J]),e.useEffect(()=>{if(!N||y)return;const e=()=>{if(x.current-=1.2,m(e=>{const t=Math.max(0,e+x.current);return 0===t&&x.current<0&&(x.current=0),t}),o.current+=1,o.current>=("pro"===i?150:180)){o.current=0;const e=Math.random()<.65?"cactus":"bird";f(t=>[...t,{id:Date.now()+Math.random(),x:108,kind:e,height:"bird"===e?Math.random()<.5?84:118:38}])}f(e=>{const t=e.map(e=>({...e,x:e.x-M.current})).filter(e=>e.x>-12);return t.some(e=>{const t=z.current?28:24,s=e.x;if(e.x+("bird"===e.kind?12:9)<12||s>t)return!1;const r=D.current;return"cactus"===e.kind?r<38&&!z.current:!z.current&&r<e.height+18})&&(S(!0),k(!1),C("The run ended on an obstacle.")),t}),v(e=>{const t=e+1;return t>0&&t%960==0&&w(e=>e+.22),t}),c.current=window.setTimeout(e,16)};return c.current=window.setTimeout(e,16),()=>{c.current&&window.clearTimeout(c.current)}},[i,y,N]);const B=()=>{T(),k(!0),C("Run is live. React early.")};return t.jsx("div",{className:"min-h-screen bg-gradient-to-br from-gray-100 via-white to-slate-200 p-4 text-slate-950 sm:p-6",children:t.jsxs("div",{className:"mx-auto max-w-6xl",children:[t.jsxs("div",{className:"mb-6 flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[t.jsxs("button",{onClick:d,className:"flex items-center gap-2 rounded-xl border border-slate-300 bg-white px-4 py-2",children:[t.jsx(s,{size:18}),"Back"]}),t.jsxs("div",{className:"text-center",children:[t.jsx("h1",{className:"text-3xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-slate-950 via-slate-700 to-slate-500",children:"Chrome Dino Run"}),t.jsx("p",{className:"text-sm text-slate-600",children:"Continuous run with jump, duck and progressive speed."})]}),t.jsxs("button",{onClick:T,className:"flex items-center gap-2 rounded-xl bg-purple-500 px-4 py-2 font-semibold text-white",children:[t.jsx(r,{size:18}),"Reset"]})]}),t.jsxs("div",{className:"mb-4 grid gap-4 md:grid-cols-3",children:[t.jsxs("div",{className:"rounded-2xl border border-slate-300 bg-white p-4 text-center",children:[t.jsx("div",{className:"text-xs uppercase tracking-[0.2em] text-slate-500",children:"Score"}),t.jsx("div",{className:"mt-2 text-3xl font-bold",children:j})]}),t.jsxs("div",{className:"rounded-2xl border border-slate-300 bg-white p-4 text-center",children:[t.jsx("div",{className:"text-xs uppercase tracking-[0.2em] text-slate-500",children:"Speed"}),t.jsx("div",{className:"mt-2 text-3xl font-bold",children:g.toFixed(1)})]}),t.jsxs("div",{className:"rounded-2xl border border-slate-300 bg-white p-4 text-center",children:[t.jsx("div",{className:"text-xs uppercase tracking-[0.2em] text-slate-500",children:"Aflah Mark"}),t.jsx("div",{className:"mt-2 text-3xl font-bold",children:A})]})]}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_260px]",children:[t.jsxs("div",{children:[t.jsx("div",{className:"overflow-hidden rounded-[34px] border border-slate-300 bg-white p-4 shadow-xl",children:t.jsxs("div",{className:"relative mx-auto h-[46vh] min-h-[320px] max-h-[420px] w-full max-w-5xl overflow-hidden rounded-[24px] border-4 border-slate-900 bg-white",children:[t.jsx("div",{className:"absolute left-0 right-0 top-12 border-t-2 border-dashed border-slate-400"}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-2 bg-slate-900"}),t.jsx(l.div,{className:"absolute right-[-10%] top-10 text-4xl opacity-50",animate:{x:[0,-800]},transition:{duration:12,repeat:1/0,ease:"linear"},children:"â"}),t.jsx(l.div,{className:"absolute right-[-20%] top-20 text-3xl opacity-40",animate:{x:[0,-950]},transition:{duration:18,repeat:1/0,ease:"linear"},children:"â"}),Array.from({length:18}).map((e,s)=>t.jsx(l.div,{className:"absolute bottom-2 h-1 w-6 bg-slate-400",style:{left:6.5*s+"%"},animate:{x:[0,-60]},transition:{duration:.5,repeat:1/0,ease:"linear",delay:.03*s}},s)),p.map(e=>t.jsx("div",{className:"absolute text-5xl",style:{left:`${e.x}%`,bottom:`${"bird"===e.kind?e.height:0}px`},children:"bird"===e.kind?"ð¦
":"ðµ"},e.id)),t.jsx(l.div,{className:"absolute left-[12%] text-6xl",animate:{y:-u,scaleY:h?.75:1,scaleX:h?1.18:1},transition:{duration:.1},style:{bottom:"10px"},children:"ð¦"}),y&&t.jsx("div",{className:"absolute inset-0 grid place-items-center bg-white/80",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"text-6xl",children:"ð¥"}),t.jsx("div",{className:"mt-4 text-3xl font-bold",children:"Run Over"}),t.jsx("div",{className:"mt-2 text-slate-600",children:R}),j>=A&&t.jsx("div",{className:"mt-2 text-emerald-600",children:"You cleared the benchmark."})]})}),N&&t.jsx("div",{className:"absolute right-6 top-5 font-mono text-xl font-semibold",children:j.toString().padStart(5,"0")})]})}),t.jsx("div",{className:"mt-4 rounded-2xl border border-slate-300 bg-white p-4 text-sm text-slate-600",children:R})]}),t.jsx("div",{className:"space-y-4",children:t.jsxs("div",{className:"rounded-2xl border border-slate-300 bg-white p-4",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm uppercase tracking-[0.2em] text-slate-500",children:[t.jsx(a,{size:14}),"Controls"]}
1),t.jsxs("ul",{className:"space-y-2 text-sm text-slate-600",children:[t.jsx("li",{children:"Jump over cacti."}),t.jsx("li",{children:"Hold duck for low birds."}),t.jsx("li",{children:"Speed climbs as the score rises."})]})]})})]}),t.jsx("div",{className:"sticky bottom-3 z-20 mt-6 rounded-3xl border border-slate-300 bg-white/90 p-4 backdrop-blur",children:t.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[!N&&!y&&t.jsxs("button",{onClick:B,className:"flex items-center gap-2 rounded-2xl bg-emerald-500 px-6 py-3 font-semibold text-white",children:[t.jsx(n,{size:18}),"Start Run"]}),y&&t.jsxs("button",{onClick:B,className:"flex items-center gap-2 rounded-2xl bg-emerald-500 px-6 py-3 font-semibold text-white",children:[t.jsx(n,{size:18}),"Run Again"]}),t.jsx("button",{onClick:J,className:"rounded-2xl bg-sky-500 px-5 py-3 font-semibold text-white",children:"Jump"}),t.jsx("button",{onMouseDown:()=>L(!0),onMouseUp:()=>L(!1),onMouseLeave:()=>L(!1),onTouchStart:()=>L(!0),onTouchEnd:()=>L(!1),className:"rounded-2xl bg-amber-500 px-5 py-3 font-semibold text-slate-950",children:"Duck"})]})})]})})};export{i as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.