✕
🧩 Gry Mrówczego Świata
🎃 Halloween
✖ Wróć do menu
🧩 Gry Mrówczego Świata
Wszystkie gry dzielą jedną kasę 💰 i Twoje postępy
← Wróć do menu
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <title>🎃 Mrówcze Halloween — event</title> <style> html,body{margin:0;height:100%;background:#0a0610;color:#ffd9a0;font-family:'Segoe UI',sans-serif; display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;overflow:hidden; -webkit-user-select:none;user-select:none;-webkit-touch-callout:none} /* przytrzymanie palcem nie zaznacza napisu pod grą */ canvas{border:3px solid #6a3a10;border-radius:10px;background:#120a1c;max-width:100vw;max-height:93vh; touch-action:none;box-shadow:0 0 40px rgba(255,120,20,0.25)} .tip{font-size:12px;color:#8a6a4a} </style> </head> <body> <canvas id="c" width="900" height="620"></canvas> <div class="tip">🎃 LIMITOWANY EVENT · ulica otwarta 16:00–24:00 · ◀ ▶ albo dotknij domu (←/→, A/D) · SPACJA pukasz · ESC = menu</div> <script> // ══════════════════════════════════════════════════════════════════ // 🎃 MRÓWCZE HALLOWEEN — limitowany event (osobny plik, prefiks hw*) // Zawiera: tryb „Cukierek albo Psikus" (źródło cukierków), sklep z // limitowanymi skinami, 3 skrzynie z tabelami dropu i animacją. // Wspólne z grą: md_coins_saved (monety), md_mpWeapon (broń do „Gra // z Kolegami" — Kosa!), md_candy (cukierki), md_hwOwned (kolekcja). // ══════════════════════════════════════════════════════════════════ const C=document.getElementById('c'),ctx=C.getContext('2d'); const W=C.width,H=C.height; let gs='menu', frame=0; const mouse={x:0,y:0}; const clicks=[]; const keyq=[]; const keys={}; function rr(x,y,w,h,r,fill,stroke,lw=2){ctx.beginPath();ctx.roundRect(x,y,w,h,r);if(fill){ctx.fillStyle=fill;ctx.fill();}if(stroke){ctx.strokeStyle=stroke;ctx.lineWidth=lw;ctx.stroke();}} function tx(s,x,y,sz,col,al='center',bold=false){ctx.font=(bold?'bold ':'')+sz+"px 'Segoe UI'";ctx.fillStyle=col;ctx.textAlign=al;ctx.textBaseline='middle';ctx.fillText(s,x,y);} function isOR(mx,my,x,y,w,h){return mx>=x&&mx<=x+w&&my>=y&&my<=y+h;} function cl(v,lo,hi){return Math.max(lo,Math.min(hi,v));} function evPos(e){const r=C.getBoundingClientRect(),b=3;return{x:(e.clientX-r.left-b)*(W/(r.width-2*b)),y:(e.clientY-r.top-b)*(H/(r.height-2*b))};} C.addEventListener('mousemove',e=>{const m=evPos(e);mouse.x=m.x;mouse.y=m.y;}); C.addEventListener('mousedown',e=>{if(e.button===0){const m=evPos(e);mouse.x=m.x;mouse.y=m.y;clicks.push(m);}}); C.addEventListener('contextmenu',e=>e.preventDefault()); C.addEventListener('touchstart',e=>{e.preventDefault();const t=e.changedTouches[0],p=evPos(t);mouse.x=p.x;mouse.y=p.y;clicks.push(p);},{passive:false}); C.addEventListener('touchmove',e=>{e.preventDefault();const t=e.changedTouches[0],p=evPos(t);mouse.x=p.x;mouse.y=p.y;},{passive:false}); window.addEventListener('keydown',e=>{keys[e.key]=true;keyq.push(e.key);if([' ','ArrowLeft','ArrowRight'].indexOf(e.key)>=0)e.preventDefault();}); window.addEventListener('keyup',e=>{keys[e.key]=false;}); // 📱 przytrzymanie ◀ ▶ na telefonie — Pointer Events, żeby działało kilka palców naraz const ptrs=new Map(); C.addEventListener('pointerdown',e=>{ptrs.set(e.pointerId,evPos(e));}); C.addEventListener('pointermove',e=>{if(ptrs.has(e.pointerId))ptrs.set(e.pointerId,evPos(e));}); ['pointerup','pointercancel','pointerleave'].forEach(t=>C.addEventListener(t,e=>{ptrs.delete(e.pointerId);})); // 🌙 ulica „Cukierek albo Psikus" działa tylko wieczorem: 16:00–24:00 (realny zegar) const HW_OPEN_H=16; function hwOpenNow(){return new Date().getHours()>=HW_OPEN_H;} function hwMinsTo(h){const d=new Date();return (h*60-(d.getHours()*60+d.getMinutes())+1440)%1440;} function hwFmtMins(m){return (m>=60?Math.floor(m/60)+' h ':'')+(m%60)+' min';} // ── DŹWIĘK ──────────────────────────────────────────────────────── let AC=null; // jeden wspólny AudioContext z grą główną — dwa naraz na słabszym telefonie potrafią rwać dźwięk function beep(f,d,type,vol,f2){try{if(!AC){try{if(parent!==window&&parent.getAC)AC=parent.getAC();}catch(e){}if(!AC)AC=new (window.AudioContext||window.webkitAudioContext)();} const o=AC.createOscillator(),g=AC.createGain();o.type=type||'square';o.frequency.value=f; if(f2)o.frequency.exponentialRampToValueAtTime(f2,AC.currentTime+d); g.gain.value=vol||0.08;g.gain.exponentialRampToValueAtTime(0.001,AC.currentTime+d); o.connect(g);g.connect(AC.destination);o.start();o.stop(AC.currentTime+d);}catch(e){}} const sndCandy=()=>beep(660,0.09,'square',0.07,980); const sndBad=()=>beep(150,0.25,'sawtooth',0.09,70); const sndKnock=()=>beep(160,0.06,'square',0.10); const sndBig=()=>{beep(520,0.10,'square',0.08);setTimeout(()=>beep(780,0.16,'square',0.08),90);}; // ── WALUTY I ZAPIS (wspólne z grą) ──────────────────────────────── function getCoins(){return parseInt(localStorage.getItem('md_coins_saved')||'0')||0;} function setCoins(v){try{localStorage.setItem('md_coins_saved',Math.max(0,Math.floor(v)));}catch(e){}} let candy=0, owned={}, pity=0, equipped={weapon:null,pet:null,skin:null}; function hwLoad(){ candy=parseInt(localStorage.getItem('md_candy')||'0')||0; pity=parseInt(localStorage.getItem('md_hwPity')||'0')||0; try{const o=JSON.parse(localStorage.getItem('md_hwOwned'));if(o&&typeof o==='object')owned=o;}catch(e){owned={};} try{const e=JSON.parse(localStorage.getItem('md_hwEquip'));if(e&&typeof e==='object')equipped=Object.assign(equipped,e);}catch(e){} } function hwSave(){try{ localStorage.setItem('md_candy',Math.max(0,Math.floor(candy))); localStorage.setItem('md_hwPity',pity); localStorage.setItem('md_hwOwned',JSON.stringify(owned)); localStorage.setItem('md_hwEquip',JSON.stringify(equipped)); }catch(e){}} function have(id){return (owned[id]||0)>0;} function give(id,n){owned[id]=(owned[id]||0)+(n||1);} // ── PRZEDMIOTY EVENTU ───────────────────────────────────────────── // kind: skin | bron | pet | ozdoba | zapas ; rar: klucz do RAR const RAR={zwykly:{n:'Zwykły',c:'#c8c8c8',dup:0},rzadki:{n:'Rzadki',c:'#5ab0ff',dup:60}, bardzo:{n:'Bardzo Rzadki',c:'#7dff6b',dup:150},epicki:{n:'Epicki',c:'#b06bff',dup:400}, legend:{n:'Legendarny',c:'#ffd24a',dup:900},mit:{n:'Mityczny',c:'#ff4a4a',dup:2000}, kosmos:{n:'Kosmiczny',c:'#4ff0ff',dup:4000}}; const ITEMS={ candy100:{n:'Garść Cukierków',ic:'🍬',rar:'zwykly',kind:'zapas',d:'+100 🍬 od razu'}, candy250:{n:'Duża Garść',ic:'🍬',rar:'zwykly',kind:'zapas',d:'+250 🍬 od razu'}, candy600:{n:'Wielka Garść',ic:'🍬',rar:'zwykly',kind:'zapas',d:'+600 🍬 od razu'}, candy1500:{n:'Ogromna Garść',ic:'🍬',rar:'zwykly',kind:'zapas',d:'+1500 🍬 od razu'}, jajko: {n:'Jajko-Psikus',ic:'🥚',rar:'zwykly',kind:'zapas',d:'Psikus: zawsze +6 🍬'}, pajeczyna:{n:'Ślad Pajączków',ic:'🕸️',rar:'rzadki',kind:'ozdoba',d:'Pajęczynka za mrówką'}, czapka: {n:'Dyniowa Czapka',ic:'🎃',rar:'rzadki',kind:'ozdoba',d:'Dynia na głowie'}, bumerang:{n:'Kość-Bumerang',ic:'🦴',rar:'rzadki',kind:'bron',d:'Wraca po rzucie'}, baton: {n:'Baton Mocy',ic:'🍫',rar:'rzadki',kind:'zapas',d:'+1 ❤️ odwagi na ulicy'}, sok: {n:'Krwawy Sok',ic:'🧃',rar:'bardzo',kind:'zapas',d:'Seria nie pęka raz'}, pajaczek:{n:'Mrówka-Pajączek',ic:'🕷️',rar:'bardzo',kind:'ozdoba',d:'Osiem nóżek!'}, eliksir:{n:'Eliksir Ducha',ic:'👻',rar:'bardzo',kind:'zapas',d:'Ucieczka zawsze się udaje'}, lizak: {n:'Lizak-Maczuga',ic:'🍭',rar:'epicki',kind:'bron',d:'+50% 🍬 z domu'}, szkielet:{n:'Szkielet Mrówki',ic:'💀',rar:'epicki',kind:'ozdoba',d:'Świecące kości'}, pupil: {n:'Pajączek-Pupil',ic:'🕷️',rar:'legend',kind:'pet',d:'Zbiera cukierki z ziemi'}, korona: {n:'Dyniowa Korona',ic:'👑',rar:'legend',kind:'ozdoba',d:'Król Halloween'}, miotacz:{n:'Dyniomiotacz',ic:'🎃',rar:'mit',kind:'bron',d:'Strzela dyniami'}, kosa: {n:'KOSA KOSTUCHY',ic:'⚰️',rar:'mit',kind:'bron', d:'W „Gra z Kolegami": ×2 obrażenia i OŚLEPIA przeciwnika'}, nietoperz:{n:'Nietoperz — Pupil Skarbnik',ic:'🦇',rar:'kosmos',kind:'pet',d:'×2 monety i ×2 cukierki'}, skinBobr:{n:'Bóbr z Głową Dyni',ic:'🎃',rar:'kosmos',kind:'skin',d:'LIMITOWANY skin — płonąca dynia zamiast głowy'}, skinJamnik:{n:'Jamnik Halloween',ic:'👻',rar:'mit',kind:'skin',d:'LIMITOWANY skin — jamnik-duch w prześcieradle'}, }; // ── SKRZYNIE (szanse sumują się do 100) ─────────────────────────── const CRATES=[ {id:'c1',n:'Dyniowa Torba',ic:'🕯️',cost:200,col:'#ff9a3a', drops:[['candy100',30],['jajko',24],['pajeczyna',12],['czapka',10],['bumerang',9], ['baton',8],['sok',4],['pajaczek',2],['lizak',1]]}, {id:'c2',n:'Skrzynia Nawiedzonego Domu',ic:'🕷️',cost:500,col:'#a86bd0', drops:[['candy250',12],['jajko',8],['pajeczyna',12],['czapka',10],['bumerang',10], ['baton',9],['sok',9],['pajaczek',8],['eliksir',7],['lizak',6], ['szkielet',4.5],['pupil',2.5],['miotacz',1],['kosa',0.7],['nietoperz',0.3]]}, {id:'c3',n:'Trumna Kostuchy',ic:'⚰️',cost:1000,col:'#ff4a4a', drops:[['candy600',8],['sok',11],['eliksir',10],['pajaczek',9],['lizak',14], ['szkielet',13],['pupil',13],['korona',9],['miotacz',6],['kosa',4],['nietoperz',3]]}, {id:'c4',n:'Kocioł Wielkiej Wiedźmy',ic:'🎃',cost:2500,col:'#8a2be2', drops:[['candy1500',10],['nietoperz',6],['kosa',8],['korona',14],['pupil',16], ['miotacz',12],['szkielet',12],['eliksir',10],['sok',6],['lizak',6]]}, ]; const SHOP=[['skinBobr',10000],['skinJamnik',5000],['lizak',1200],['korona',2500],['baton',150],['eliksir',300]]; // ── EFEKTY POSIADANYCH RZECZY ───────────────────────────────────── const hasBat=()=>have('nietoperz'); const candyMul=()=>hasBat()?2:1; // Kosa → broń do „Gra z Kolegami" (index.html czyta md_mpWeapon) function equipScythe(on){ try{ if(on){localStorage.setItem('md_mpWeapon',JSON.stringify( {n:'Kosa Kostuchy',ic:'⚰️',dmg:24,rate:26,fx:['blind']}));equipped.weapon='kosa';} else{localStorage.removeItem('md_mpWeapon');equipped.weapon=null;} }catch(e){} hwSave(); } // ══════════════════════════════════════════════════════════════════ // 🎃 TRYB: CUKIEREK ALBO PSIKUS // ══════════════════════════════════════════════════════════════════ const HW_RES={ babcia:{ic:'👵',n:'Miła Babcia',col:'#7ad04a',prop:'🌻', hi:['O, jaka słodka mrówka! I tak sama chodzisz po nocy?', 'Ojej, przebranie za mrówkę! Widziałam już ducha i trzy dynie, ale mrówki jeszcze nie!', 'Poczekaj, mam gdzieś miskę… zaraz, gdzie ja ją położyłam?'], treat:[{t:'Cukierek? Bierz całą miskę, dziecko! I zjedz coś ciepłego!',c:7}, {t:'Masz, masz, i jeszcze jeden na drogę. Uważaj na tego psa spod trójki!',c:6}], trick:[{t:'Psikus? Chi chi chi! Za mojej młodości chodziliśmy z burakiem! Masz cukierka za odwagę.',c:3}, {t:'Oj ty urwisie. Trzymaj, ale babci nie strasz, bo mam kolana.',c:3}]}, dziad:{ic:'👴',n:'Zły Dziad',col:'#e74c3c',prop:'🚫', hi:['CZEGO?! Dopiero co ktoś pukał! Kto to znowu?!', 'Nie ma cukierków. Nie ma. Idź do sąsiada, on ma za dużo.', 'Ja tu próbuję oglądać wiadomości, a wy pukacie i pukacie!'], treat:[{t:'Masz. Jeden. I to jest ten dobry, więc doceń.',c:1}, {t:'Cukierków nie mam. Mam gruszkę. Chcesz gruszkę? Nie? To nie.',c:0}], trick:[{t:'AAA! ZABIERZ TO! Dobra, MASZ CAŁY SŁOIK, tylko idź stąd!',c:12}, {t:'MIOTŁA! GDZIE JEST MOJA MIOTŁA?! WRACAJ TU!',c:0,chase:true}]}, pies:{ic:'🐕',n:'Dom z Psem',col:'#f1c40f',prop:'🦴', hi:['Cześć! Nie bój się, Burek jest grzeczny… no, przeważnie.', 'HAU HAU HAU! (zza drzwi coś bardzo dużego drapie w framugę)'], treat:[{t:'Masz cukierki! Burek, SIAD! BUREK, SIAD!',c:3}, {t:'Proszę bardzo… Burek, ZOSTAW! …Burek nie usiadł.',c:2,chase:true}], trick:[{t:'Psikus? Burek uważa, że to zabawa w gonionego. Burek zawsze wygrywa.',c:0,chase:true}, {t:'Burek poczuł kiełbaskę i przyniósł ci… czyjś worek cukierków.',c:10}]}, duch:{ic:'👻',n:'Nawiedzony Dom',col:'#c86adc',prop:'🕸️', hi:['Buuuuu… ojej, przepraszam, nie chciałem tak głośno.', 'Nikogo nie ma w domu. Mówi to drzwi. Drzwi same. Normalne drzwi.', 'Czy ty… mnie widzisz? MNIE NIKT NIE WIDZI OD DWUSTU LAT!'], treat:[{t:'Mam cukierki-widmo! Są bardzo dobre. Chyba.',c:9}, {t:'Proszę… o nie, znowu przeleciały ci przez ręce. Duchowe rzeczy tak mają.',c:0}], trick:[{t:'PSIKUS?! Ja robię psikusy od dwustu lat! Pokaż… …dobre. NAPRAWDĘ DOBRE. Bierz wszystko!',c:15}, {t:'Dobry psikus! A teraz mój psikus. BUUU!',c:15,heart:true}]}, wiedzma:{ic:'🧙',n:'Wiedźma',col:'#00cec9',prop:'🍲', hi:['Wchodź, wchodź… znaczy nie wchodź. Nie wolno wchodzić. Ale postój.', 'Akurat gotuję. Nie pytaj co. Naprawdę nie pytaj.', 'Kot mówi, że jesteś mrówką. Kot rzadko się myli.'], treat:[{t:'Cukierek? Mam lepiej. Mam ELIKSIR.',c:2,item:true}, {t:'Chwila… to nie były cukierki. To były żaby. Przepraszam.',c:-3}], trick:[{t:'Psikus na wiedźmę? ODWAŻNA MRÓWKA! Zaklęcie: PODWÓJNIE!',c:0,dbl:true}, {t:'Psikus na wiedźmę? Zaklęcie: MINUS PIĘĆ. Następnym razem pomyśl.',c:-5}]}, dynia:{ic:'🎃',n:'Dyniogłowy Żartowniś',col:'#ff8a2a',prop:'🎃', hi:['O! Konkurencja! Jak ci idzie zbieranie?', 'Cukierek albo psikus? Ja wybieram PSIKUS. Zawsze psikus. Twoja kolej.'], treat:[{t:'Cukierek? Nuuudy. Masz dwa, bo mi ciebie żal.',c:2}], trick:[{t:'HA! TO BYŁO GENIALNE! Bierz połowę mojego worka!',c:14}, {t:'Nieźle, nieźle. Ale ja robiłem lepsze. Masz cztery.',c:4}]}, ciemny:{ic:'🚪',n:'Ciemny Dom',col:'#7a6a60',prop:'', hi:['(Nikt nie otwiera. Na wycieraczce stoi miska. Kartka: „Weź JEDEN. Wiem, ile ich jest.")'], treat:[{t:'Wziąłeś jednego. Gdzieś w środku ktoś się uśmiechnął.',c:2}], trick:[{t:'Wziąłeś wszystkie… W oknie na piętrze zapaliło się światło. Ktoś patrzy.',c:8,heart:true}, {t:'Wziąłeś wszystkie i nikt nie zauważył. Chyba.',c:8}]}, mrowki:{ic:'🐜',n:'Dom Mrówek',col:'#ffd24a',prop:'🚩', hi:['Ej, ty też z mrowiska? Wymiana! Daj 5 cukierków, dam ci coś lepszego.'], treat:[{t:'Wymiana zrobiona! Masz coś z naszego worka.',c:-5,item:true}], trick:[{t:'Spoko. Uważaj na dom z pajęczyną. Tam coś… mieszka.',c:2}]}, }; const EASY=['babcia','dynia','pies','mrowki'], HARD=['dziad','duch','wiedzma','ciemny']; // 👹 BOSS — ostatni (13.) dom ulicy, za trzecią falą; pokonany = ulica zaliczona, dalej w prawo zaczyna się następna (trudniejsza, lepsze nagrody). // Każdy boss ma głowę-dynię, rzuca cukierkami i ma własne sztuczki (atk). const HW_BOSSES=[ {n:'Król Dyń',ic:'🎃',col:'#ff8a2a',cloak:'#3a1450',trim:'#ff9a2a',hand:'#2a1a10',hat:'crown',atk:['shot','rain','bomb'], hi:'HA HA HA! Cukierki od KRÓLA DYŃ? Najpierw musisz mnie pokonać!'}, {n:'Kostucha Dyniogłowa',ic:'💀',col:'#d8d8ff',cloak:'#16121c',trim:'#7a7a9a',hand:'#e8e4d8',hat:'hood',atk:['shot','ghost','bomb'], hi:'Kto puka do Kostuchy o tej porze?… Mrówka? Dobra. Pokaż, co potrafisz!'}, {n:'Wielka Wiedźma',ic:'🧙',col:'#7dff6b',cloak:'#1e3a22',trim:'#b06bff',hand:'#7ad04a',hat:'witch',atk:['shot','potion','rain'], hi:'Mój kocioł potrzebuje mrówki! Chyba że obrzucisz mnie cukierkami szybciej, niż czaruję…'}, {n:'Hrabia Nietoperz',ic:'🦇',col:'#ff4a6a',cloak:'#120a14',trim:'#c0203a',hand:'#d8c8d0',hat:'wings',atk:['shot','bats','bomb'], hi:'Witaj w moim zamku. Cukierki? Moje. Wszystkie. Chyba że wygrasz.'}, ]; // 🧟 co 4 domy brama fali (HW_GATEW = dodatkowe miejsce na bramę); ulica = 12 domów + 3 fale + boss const HW_GAP=230, HW_PER=13, HW_WAVE=4, HW_GATEW=170, HW_GPS=(HW_PER-1)/HW_WAVE, HW_GROUND=480; let hwPhase='walk', hwStreet=1, hwHouses=[], hwIdx=-1, hwPx=120, hwCam=0; let hwCandy=0, hwHearts=3, hwStreak=0, hwBubble=null, hwT=0, hwChase=0, hwChaseNeed=0, hwFloats=[], hwParts=[]; let hwLastGain=0, hwTarget=null, hwAuto=-1, hwDir=1, hwWalkT=0, hwMoving=false, hwLastT=0; let hwF=null; // trwająca walka z bossem let hwW=null, hwGates=[]; // trwająca fala potworów, bramy fal na ulicy function hwFloat(x,y,t,col){hwFloats.push({x,y,t,col,l:70});} function hwPart(x,y,col,n){for(let i=0;i<n;i++)hwParts.push({x,y,vx:(Math.random()-0.5)*3,vy:-Math.random()*3-1,l:30+Math.random()*20,col});} // 🏠 wygląd domu losowany raz: kolory, piętro z balkonem, komin, dynie, lampki, pajęczyna, nagrobek, nietoperz, duszek const HW_WALLS=['#3a2a4a','#2a3a4c','#4a2a2c','#2a4036','#4a3a24','#3a3050','#2c2c40','#4a2a40']; const HW_ROOFS=['#3a2a2a','#2a1a2e','#1e2a2a','#4a2418','#2a2030','#3a1a1a']; const HW_DOORS=['#4a2f18','#2a3a5a','#5a1a1a','#2a4a2a','#3a2a4a']; function hwStyle(){ const r=Math.random,two=r()<0.42; const pk=[];const n=1+((r()*3)|0); for(let k=0;k<n;k++)pk.push({dx:(k%2?1:-1)*(40+k*14+r()*10),s:0.65+r()*0.55}); return{wall:HW_WALLS[(r()*HW_WALLS.length)|0],roof:HW_ROOFS[(r()*HW_ROOFS.length)|0],door:HW_DOORS[(r()*HW_DOORS.length)|0], w:150+((r()*4)|0)*12,two,balcony:two&&r()<0.75,chimney:r()<0.5,lights:r()<0.55,web:r()<0.5, tomb:r()<0.35,bat:r()<0.35,ghost:two&&r()<0.4,pk}; } function hwStreetOf(k){return Math.floor(k/HW_PER)+1;} // x domu k: równy odstęp + miejsce na każdą bramę przed nim function hwHX(k){const st=Math.floor(k/HW_PER),j=k%HW_PER;return 150+k*HW_GAP+(st*HW_GPS+Math.floor(j/HW_WAVE))*HW_GATEW;} function hwKAt(x){let b=0,bd=1e9;for(let i=0;i<hwHouses.length;i++){const d=Math.abs(hwHouses[i].x-x);if(d<bd){bd=d;b=i;}}return b;} function hwRes(h){return h.t==='boss'?{ic:h.boss.ic,n:h.boss.n,col:h.boss.col,prop:'💀'}:HW_RES[h.t];} function hwMakeHouse(k){ const st=hwStreetOf(k), x=hwHX(k); if(k%HW_PER===HW_PER-1)return{t:'boss',x,st,done:false,open:0,boss:HW_BOSSES[(st-1)%HW_BOSSES.length]}; const hardW=cl(0.15+st*0.12,0,0.62); const pool=(k===0)?EASY:(Math.random()<hardW?HARD:EASY); return{t:pool[(Math.random()*pool.length)|0],x,st,done:false,open:0,s:hwStyle()}; } function hwHouseTop(h){return h.t==='boss'?96:420-(h.s.two?270:190)-62;} // domy dobudowują się przed mrówką — w prawo ulica się nie kończy function hwGenMore(){while(hwHX(hwHouses.length)<hwPx+W*1.5){const k=hwHouses.length,j=k%HW_PER;hwHouses.push(hwMakeHouse(k)); if(j%HW_WAVE===HW_WAVE-1&&j<HW_PER-1){const n=(j+1)/HW_WAVE,st=hwStreetOf(k); hwGates.push({x:hwHX(k)+(HW_GAP+HW_GATEW)/2,st,n,g:(st-1)*HW_GPS+n,done:false});}}} function hwStart(){ if(!hwOpenNow()){msg('🌙 Ulica budzi się o 16:00 — jeszcze '+hwFmtMins(hwMinsTo(HW_OPEN_H)));return;} hwHouses=[];hwIdx=-1;hwPx=120;hwCam=0;hwPhase='walk';hwBubble=null;hwTarget=null;hwAuto=-1;hwDir=1;hwLastT=0; hwStreet=1;hwCandy=0;hwHearts=3;hwStreak=0;hwFloats=[];hwParts=[];hwF=null;hwW=null;hwGates=[]; hwGenMore();gs='street'; } function hwMul(){const s=[1,1.2,1.4,1.6,2.0][Math.min(4,hwStreak)];return s*(1+0.15*(hwStreet-1));} // 🍬 każdy zysk/strata od razu trafia do zapisanego worka (md_candy) — wyjście w dowolnej chwili niczego nie kasuje function hwAddCandy(gain){const before=hwCandy;hwCandy=Math.max(0,hwCandy+gain);candy=Math.max(0,candy+(hwCandy-before));hwSave();} function hwNearHouse(){ for(let i=0;i<hwHouses.length;i++){const h=hwHouses[i]; if(!h.done&&Math.abs(hwPx-h.x)<60)return i;} return -1; } function hwKnockAt(i){hwIdx=i;hwStreet=hwHouses[i].st;hwPhase='knock';hwT=0;hwTarget=null;hwAuto=-1;sndKnock();} function hwKnock(){const i=hwNearHouse();if(i>=0)hwKnockAt(i);} function hwToWalk(){if(hwIdx>=0&&!hwHouses[hwIdx].done)hwHouses[hwIdx].open=0;hwBubble=null;hwPhase='walk';hwIdx=-1;hwF=null;hwW=null;} function hwPick(arr){return arr[(Math.random()*arr.length)|0];} function hwChoose(kind){ if(hwPhase!=='greet'||hwIdx<0)return; const h=hwHouses[hwIdx], R=HW_RES[h.t]; const list=(kind==='treat')?R.treat:R.trick; const res=hwPick(list); let gain=res.c||0; if(res.dbl)gain=Math.round(hwCandy*0.5); if(gain>0)gain=Math.round(gain*hwMul()*candyMul()); hwLastGain=gain; hwAddCandy(gain); if(gain>0){hwStreak=Math.min(4,hwStreak+1);sndCandy();hwFloat(h.x-hwCam,300,(gain>0?'+':'')+gain+' 🍬','#ffd24a');hwPart(h.x-hwCam,320,'#ffd24a',12);} else if(gain<0){sndBad();hwFloat(h.x-hwCam,300,gain+' 🍬','#ff6a5a');hwStreak=0;} if(res.item){const pool=['baton','sok','eliksir','jajko','lizak'];const it=pool[(Math.random()*pool.length)|0]; give(it,1);hwSave();hwFloat(h.x-hwCam,270,ITEMS[it].ic+' '+ITEMS[it].n,'#7dff6b');} if(gain>=12)sndBig(); hwBubble={txt:res.t,col:gain>=0?'#2a4a1a':'#4a1a1a',bd:gain>=0?'#7dff6b':'#ff6a5a'}; if(res.chase){hwPhase='chase';hwChase=0;hwChaseNeed=6;hwT=0;} else{ if(res.heart){hwHearts--;hwStreak=0;sndBad();hwFloat(h.x-hwCam,250,'-1 ❤️','#ff5a5a');} hwPhase='react';hwT=0; } h.done=true; } function hwChaseTap(){ if(hwPhase!=='chase')return; hwChase++; if(hwChase>=hwChaseNeed){hwPhase='react';hwT=0;hwBubble={txt:'Uciekłeś! 🏃 Serce bije jak młotem, ale worek cały.',col:'#2a4a1a',bd:'#7dff6b'};} } function hwUpdChase(){ hwT++; if(hwT>150){ // nie zdążył if(have('eliksir')){owned.eliksir--;hwSave();hwBubble={txt:'👻 Eliksir Ducha! Przeniknąłeś przez płot. Uff.',col:'#2a4a1a',bd:'#7dff6b'};} else{hwHearts--;hwStreak=0;sndBad();hwBubble={txt:'Dogonili cię! Straciłeś odwagę, ale nie cukierki.',col:'#4a1a1a',bd:'#ff6a5a'};} hwPhase='react';hwT=0; } } // ══════════════════════════════════════════════════════════════════ // 👹 WALKA Z BOSSEM — boss lata przed zamczyskiem, rzuca cukierkami, dyniami-bombami, nietoperzami, // duchami albo eliksirem; co chwilę włącza tarczę. Mrówka ucieka ◀ ▶ i rzuca cukierkami (🍬 RZUCAJ). // Tarcza mrówki: 5 trafień → przegrana (−1 ❤️). Czas liczony zegarem, nie klatkami. // ══════════════════════════════════════════════════════════════════ const HW_CANDY_COLS=['#ff4a8a','#5adcff','#ffe14a','#7dff6b','#ff8a2a','#b06bff']; function hwBossStart(){ const h=hwHouses[hwIdx],now=performance.now(),hp=20+6*h.st; hwF={h,B:h.boss,hp,max:hp,pips:5,inv:0,t0:now,next:now+1600,windAtk:null,wind:0,shUntil:0,nextSh:now+5200, ents:[],mine:[],flash:0,cool:0,shake:0,angry:false,bx:h.x,by:250}; hwBubble=null;hwPhase='boss';hwT=0; } function hwThrow(){ const F=hwF,now=performance.now();if(!F||now<F.cool)return; F.cool=now+200;hwDir=Math.sign(F.bx-hwPx)||1; F.mine.push({x0:hwPx+hwDir*30,y0:448,t0:now,T:420,col:hwPick(HW_CANDY_COLS)}); beep(620+Math.random()*200,0.04,'square',0.04,900); } function hwHit(txt){ const F=hwF,now=performance.now();if(now<F.inv)return; F.pips--;F.inv=now+1000;F.shake=now+220;sndBad();hwFloat(hwPx-hwCam,400,txt,'#ff6a5a');hwPart(hwPx-hwCam,460,'#ff6a5a',10); } function hwBossAttack(k,now){ const F=hwF,ax=hwPx,hx=F.bx,hy=F.by+10,L=hwCam+50,R=hwCam+W-50; const lob=(tx,delay,T,arc,kk)=>F.ents.push({k:kk,x0:hx+30,y0:hy,tx:cl(tx,L,R),t0:now+delay,T,arc,col:hwPick(HW_CANDY_COLS),rot:Math.random()*6}); if(k==='shot'){const n=F.angry?5:3;for(let i=0;i<n;i++)lob(ax+(i-(n-1)/2)*55+(Math.random()-0.5)*20,i*150,1100,150,'candy');} else if(k==='rain'){const n=F.angry?10:7;for(let i=0;i<n;i++){const tx=cl(ax+(Math.random()-0.5)*560,L,R); F.ents.push({k:'rain',x0:tx,y0:-30,tx,t0:now+i*130,T:1300,arc:0,col:HW_CANDY_COLS[i%6],rot:Math.random()*6});}} else if(k==='bomb'){lob(ax,0,1300,260,'bomb');if(F.angry)lob(ax+(Math.random()<0.5?-140:140),350,1300,240,'bomb');} else if(k==='potion'){lob(ax,0,1100,200,'potion');if(F.angry)lob(ax+(ax<hwCam+W/2?160:-160),300,1100,200,'potion');} else if(k==='bats'){const n=F.angry?5:3;for(let i=0;i<n;i++) F.ents.push({k:'bat',x0:hx,y0:hy-20,tx:cl(ax+(i-(n-1)/2)*45,L,R),t0:now+i*240,T:1300,arc:0});} else if(k==='ghost'){F.ents.push({k:'ghost',x:hx,vx:Math.sign(ax-hx||1)*(F.angry?0.17:0.13),t0:now,T:5200});} beep(220,0.12,'triangle',0.06,440); } function hwUpdBoss(now,dt){ const F=hwF,h=F.h,B=F.B; const d=hwInputDir(); if(d){hwPx=cl(hwPx+d*0.26*dt,h.x-W/2+50,h.x+W/2-50);hwDir=d;hwWalkT+=dt/16.7;hwMoving=true;} const t=now-F.t0; F.bx=h.x+Math.sin(t*0.0009)*(F.angry?170:110);F.by=250+Math.sin(t*0.003)*8; if(!F.angry&&F.hp<=F.max/2){F.angry=true;hwFloat(F.bx-hwCam,150,'😡 '+B.n+' się wściekł!','#ff6a5a');sndBad();} if(now>F.nextSh&&now>F.shUntil){F.shUntil=now+1400;F.nextSh=now+1400+4200+Math.random()*2200;beep(880,0.2,'sine',0.05,1320);} if(!F.windAtk&&now>F.next){F.windAtk=hwPick(B.atk);F.wind=now+380;} if(F.windAtk&&now>F.wind){hwBossAttack(F.windAtk,now);F.windAtk=null;F.next=now+(F.angry?1300:1900)+Math.random()*500;} for(let i=F.ents.length-1;i>=0;i--){const e=F.ents[i];if(now<e.t0)continue;const p=(now-e.t0)/e.T; if(e.k==='ghost'){e.x+=e.vx*dt; if(Math.abs(e.x-hwPx)<30){hwHit('👻 BUU!');F.ents.splice(i,1);}else if(p>=1)F.ents.splice(i,1);continue;} if(e.k==='puddle'){if(Math.abs(e.x-hwPx)<e.r){e.stand+=dt;if(e.stand>500){hwHit('🧪 Fuj, glut!');F.ents.splice(i,1);continue;}} if(p>=1)F.ents.splice(i,1);continue;} if(p>=1){ const r=e.k==='bomb'?72:34; if(Math.abs(e.tx-hwPx)<r)hwHit(e.k==='bomb'?'💥 BUM!':(e.k==='bat'?'🦇 Ugryzł!':'🍬 Au!')); hwPart(e.tx-hwCam,HW_GROUND-6,e.k==='bomb'?'#ff8a2a':(e.k==='bat'?'#b06bff':(e.k==='potion'?'#7dff6b':e.col)),e.k==='bomb'?28:8); if(e.k==='bomb'){F.shake=now+260;beep(90,0.3,'sawtooth',0.1,40);} if(e.k==='potion')F.ents.push({k:'puddle',x:e.tx,r:55,t0:now,T:3200,stand:0}); F.ents.splice(i,1);} } for(let i=F.mine.length-1;i>=0;i--){const m=F.mine[i];if((now-m.t0)/m.T<1)continue; F.mine.splice(i,1); if(now<F.shUntil){hwFloat(F.bx-hwCam,F.by-90,'🛡️ odbite!','#9ad8ff');beep(1200,0.05,'triangle',0.05);} else{F.hp--;F.flash=now+110;hwPart(F.bx-hwCam,F.by-30,'#ffd24a',6);beep(300+Math.random()*200,0.06,'square',0.06,150); if(F.hp<=0){hwBossWin();return;}}} if(F.pips<=0)hwBossLose(); } function hwBossWin(){ const F=hwF,h=F.h,B=F.B; const reward=Math.round((25+10*h.st)*hwMul()*candyMul()); hwAddCandy(reward); const pool=['baton','sok','eliksir','jajko','lizak'],it=pool[(Math.random()*pool.length)|0];give(it,1);hwSave(); hwHearts=Math.min(3,hwHearts+1);hwStreak=Math.min(4,hwStreak+1); h.done=true;h.open=40;hwPhase='react';hwT=0;sndBig();F.ents=[]; hwFloat(F.bx-hwCam,200,'+'+reward+' 🍬','#ffd24a');hwFloat(F.bx-hwCam,170,ITEMS[it].ic+' '+ITEMS[it].n,'#7dff6b'); for(let k=0;k<4;k++)hwPart(F.bx-hwCam+(k-1.5)*30,F.by-20,HW_CANDY_COLS[k],12); hwBubble={txt:'🏆 '+B.n+' pokonany! Ulica '+h.st+' zaliczona: +'+reward+' 🍬, +1 ❤️ i '+ITEMS[it].n+'. Idź dalej w prawo — tam zaczyna się ulica '+(h.st+1)+'!',col:'#2a4a1a',bd:'#7dff6b'}; } function hwBossLose(){ const B=hwF.B; hwHearts--;hwStreak=0;sndBad();hwPhase='react';hwT=0;hwF.ents=[]; hwFloat(hwPx-hwCam,400,'-1 ❤️','#ff5a5a'); hwBubble={txt:B.n+' się śmieje: „Za mało cukierków, mrówko!" Straciłeś 1 ❤️. Możesz zapukać jeszcze raz.',col:'#4a1a1a',bd:'#ff6a5a'}; } // ══════════════════════════════════════════════════════════════════ // 🧟 FALE POTWORÓW — co 4 domy brama z mgłą. Podejście = fala: potwory wychodzą z obu stron // (zombie, nietoperze, szkielety rzucające kośćmi, skaczące dyniaki, znikające duchy, pająki na nitkach, // wiedźmy z eliksirem). Mrówka rzuca w nie cukierkami: dotknij potwora albo 🍬 RZUCAJ (trzymanie = seria). // Tarcza 5 trafień → −1 ❤️ i odwrót spod bramy. Siła fali g rośnie z każdą bramą, także na dalszych ulicach: // więcej potworów, więcej życia, szybsze, nowe rodzaje. // ══════════════════════════════════════════════════════════════════ const HW_EN={ zombie:{hp:3,sp:0.045,w:24,col:'#8ac76a',hit:'🧟 Ałć!',from:1,nm:'🧟 zombie'}, bat: {hp:1,sp:0.10, w:20,col:'#b06bff',hit:'🦇 Ugryzł!',from:1,nm:'🦇 nietoperze'}, skel: {hp:2,sp:0.07, w:20,col:'#ece6d4',hit:'💀 Kościsty cios!',from:2,nm:'💀 szkielety rzucające kośćmi'}, pump: {hp:3,sp:0, w:24,col:'#ff8a2a',hit:'🎃 Bęc!',from:3,nm:'🎃 skaczące dynie'}, ghost: {hp:2,sp:0.05, w:22,col:'#f4f0ff',hit:'👻 BUU!',from:3,nm:'👻 znikające duchy'}, spider:{hp:2,sp:0.09, w:22,col:'#c0203a',hit:'🕷️ Ugryzł!',from:4,nm:'🕷️ pająki z sufitu'}, witch: {hp:4,sp:0.07, w:28,col:'#7dff6b',hit:'🧪 Plusk!',from:5,nm:'🧙 wiedźmy z eliksirem'}, }; function hwWaveStart(G){ const now=performance.now(),g=G.g,kinds=Object.keys(HW_EN); const pool=kinds.filter(k=>HW_EN[k].from<=g),fresh=kinds.filter(k=>HW_EN[k].from===g); const n=Math.min(24,4+2*g),q=[]; for(let i=0;i<n;i++)q.push(i<fresh.length*2?fresh[i%fresh.length]:hwPick(pool)); // nowy rodzaj pokazuje się od razu hwW={G,g,q,fresh,ens:[],shots:[],mine:[],total:n,kills:0,pips:5,inv:0,cool:0,shake:0,t0:now,next:now+1300, cx:G.x-W*0.45,hpM:1+0.25*(g-1),spM:Math.min(1.6,1+0.07*(g-1)),maxOn:Math.min(8,2+g),burst:1+Math.ceil(g/2)}; hwPx=Math.min(hwPx,G.x-50);hwTarget=null;hwAuto=-1;hwBubble=null;hwPhase='wave';hwT=0; sndBad();beep(200,0.6,'sawtooth',0.06,80); } function hwSpawn(k,now){ const V=hwW,D=HW_EN[k],L=V.cx+50,R=V.cx+W-50,left=V.g>=2&&Math.random()<0.3; const e={k,x:left?V.cx-50-Math.random()*90:V.cx+W+50+Math.random()*90,y:0,by:0,dir:left?1:-1,hp:Math.max(1,Math.round(D.hp*V.hpM)),ph:Math.random()*6, kbv:0,flash:0,stop:0,jy:0,t0:now,next:now+1200+Math.random()*1400}; e.max=e.hp; if(k==='bat')e.by=e.y=240+Math.random()*90; if(k==='witch')e.by=e.y=165+Math.random()*40; if(k==='spider'){const s=Math.random()<0.5?-1:1;let x=hwPx+s*(170+Math.random()*130); // zjeżdża na nitce obok mrówki, nie na nią if(x<L+30||x>R-30)x=hwPx-s*(170+Math.random()*130); e.x=cl(x,L+30,R-30);e.y=48;e.drop=true;e.dir=Math.sign(hwPx-e.x)||1;} V.ens.push(e); } // środek potwora (świat) — tu leci cukierek function hwEnC(e){ if(e.k==='bat'||e.k==='witch')return{x:e.x,y:e.y}; if(e.k==='spider')return{x:e.x,y:e.y-18}; if(e.k==='pump')return{x:e.x,y:HW_GROUND-30-e.jy}; if(e.k==='ghost')return{x:e.x,y:436}; return{x:e.x,y:HW_GROUND-56}; } // duch co 3,6 s znika na chwilę — wtedy cukierki przez niego przelatują function hwGhostA(e,now){const c=((now-e.t0)%3600)/3600; return c<0.62?0.9:c<0.7?0.9-(c-0.62)/0.08*0.78:c<0.92?0.12:0.12+(c-0.92)/0.08*0.78;} const hwGhostVis=(e,now)=>hwGhostA(e,now)>0.5; function hwWThrow(sx,sy){ const V=hwW,now=performance.now();if(!V||now<V.cool||!V.ens.length)return; let best=null,bd=1e9; if(sx!=null)for(const o of V.ens){const c=hwEnC(o),d=Math.hypot(c.x-hwCam-sx,c.y-sy);if(d<bd){bd=d;best=o;}} if(!best||bd>150){best=null;bd=1e9; // dotknięcie obok potwora / przycisk → najbliższy mrówce (niewidzialny duch na końcu) for(const o of V.ens){const c=hwEnC(o),d=Math.abs(c.x-hwPx)+Math.max(0,HW_GROUND-60-c.y)*0.4+(o.k==='ghost'&&!hwGhostVis(o,now)?600:0); if(d<bd){bd=d;best=o;}}} const c=hwEnC(best);V.cool=now+210;hwDir=Math.sign(c.x-hwPx)||hwDir; V.mine.push({x0:hwPx+hwDir*30,y0:448,t0:now,T:Math.min(420,200+Math.abs(c.x-hwPx)*0.35),col:hwPick(HW_CANDY_COLS),e:best,tx:c.x,ty:c.y}); beep(620+Math.random()*200,0.04,'square',0.04,900); } function hwWHit(txt){ const V=hwW,now=performance.now();if(!V||now<V.inv)return; V.pips--;V.inv=now+1000;V.shake=now+220;sndBad();hwFloat(hwPx-hwCam,400,txt,'#ff6a5a');hwPart(hwPx-hwCam,460,'#ff6a5a',10); } function hwWDmg(e,now){ const V=hwW,c=hwEnC(e);e.hp--;e.flash=now+120;hwPart(c.x-hwCam,c.y,'#ffd24a',5); if(!e.hop&&!e.drop&&e.k!=='bat'&&e.k!=='witch')e.kbv=Math.sign(e.x-hwPx||1)*0.22; beep(300+Math.random()*200,0.05,'square',0.05,150); if(e.hp>0)return; V.ens.splice(V.ens.indexOf(e),1);V.kills++; hwPart(c.x-hwCam,c.y,HW_EN[e.k].col,16); const gain=Math.round(candyMul());hwAddCandy(gain);hwFloat(c.x-hwCam,c.y-30,'+'+gain+' 🍬','#ffd24a'); if(V.pips<5&&Math.random()<0.12){V.pips++;hwFloat(c.x-hwCam,c.y-55,'+1 🛡️','#9ad8ff');} beep(880,0.08,'square',0.05,1400); } function hwUpdWave(now,dt){ const V=hwW,L=V.cx+50,R=V.cx+W-50,d=hwInputDir(); if(d){hwPx=cl(hwPx+d*0.26*dt,L,R);hwDir=d;hwWalkT+=dt/16.7;hwMoving=true;} for(const p of ptrs.values())if(inR(p,HB_K)){hwWThrow();break;} // przytrzymany 🍬 RZUCAJ = seria if(now-V.t0>1200&&V.q.length&&now>V.next&&V.ens.length<V.maxOn){ // potwory wychodzą grupkami — trzeba pilnować obu stron for(let b=Math.min(V.burst,V.maxOn-V.ens.length,V.q.length);b>0;b--)hwSpawn(V.q.shift(),now); V.next=now+Math.max(900,2200-90*V.g)+Math.random()*500;} for(let i=V.ens.length-1;i>=0;i--){const e=V.ens[i],D=HW_EN[e.k],sp=D.sp*V.spM,dx=hwPx-e.x,ad=Math.abs(dx); e.ph+=dt*0.01; if(e.kbv){e.x+=e.kbv*dt;e.kbv*=Math.pow(0.86,dt/16.7);if(Math.abs(e.kbv)<0.02)e.kbv=0;} const touch=()=>{if(Math.abs(hwPx-e.x)<D.w+18){hwWHit(D.hit);e.kbv=-(Math.sign(hwPx-e.x)||1)*0.6;}}; if(e.k==='bat'){ // krąży, a z bliska nurkuje łukiem przez mrówkę if(e.sw){const p=(now-e.sw.t0)/e.sw.T; if(p>=1){e.sw=null;e.next=now+1300+Math.random()*900;} else{e.x=e.sw.x0+(e.sw.x1-e.sw.x0)*p;e.y=e.sw.y0+(450-e.sw.y0)*Math.sin(p*Math.PI); if(!e.sw.hit&&e.y>420&&Math.abs(e.x-hwPx)<34){e.sw.hit=true;hwWHit(D.hit);}}} else{e.dir=Math.sign(dx)||e.dir;if(ad>110)e.x+=e.dir*sp*dt;e.y=e.by+Math.sin(e.ph*0.6)*22; if(ad<260&&now>e.next&&e.x>L-20&&e.x<R+20){const a=Math.max(70,ad); e.sw={t0:now,T:1050/V.spM,x0:e.x,y0:e.y,x1:e.x+e.dir*2*a};beep(900,0.12,'sine',0.03,500);}} continue;} if(e.k==='witch'){ // lata nad mrówką i zrzuca eliksir → kałuża glutu const tx_=cl(hwPx+Math.sin(e.ph*0.22)*230,L,R);e.dir=Math.sign(tx_-e.x)||e.dir;e.x+=cl(tx_-e.x,-sp*dt,sp*dt); e.y=e.by+Math.sin(e.ph*0.5)*14; if(now>e.next&&e.x>L&&e.x<R){V.shots.push({k:'potion',x0:e.x,y0:e.y+18,tx:cl(hwPx+(Math.random()-0.5)*90,L,R),t0:now,T:900}); e.next=now+2300+Math.random()*1300;beep(500,0.15,'triangle',0.05,250);} continue;} if(e.k==='spider'&&e.drop){e.y+=0.16*dt;if(e.y>=HW_GROUND-4){e.y=HW_GROUND-4;e.drop=false;e.dir=Math.sign(dx)||1;}continue;} if(e.k==='pump'){ // skacze w stronę mrówki; ląduje na niej = trafienie if(e.hop){const p=(now-e.hop.t0)/e.hop.T; if(p>=1){e.x=e.hop.x1;e.jy=0;e.hop=null;e.next=now+(450+Math.random()*450)/V.spM;hwPart(e.x-hwCam,HW_GROUND-4,'#ff8a2a',5);touch();} else{e.x=e.hop.x0+(e.hop.x1-e.hop.x0)*p;e.jy=Math.sin(p*Math.PI)*80;}} else if(!e.kbv&&now>e.next){e.dir=Math.sign(dx)||e.dir;e.hop={t0:now,T:560,x0:e.x,x1:e.x+e.dir*Math.min(130,Math.max(20,ad))}; beep(260,0.08,'triangle',0.04,420);} else touch(); continue;} // chodzące: zombie, szkielet, duch, pająk na ziemi e.dir=Math.sign(dx)||e.dir; if(e.k==='skel'&&ad>170&&ad<W&&now>e.next){e.stop=now+520;e.next=now+2600+Math.random()*1600; V.shots.push({k:'bone',x0:e.x,y0:HW_GROUND-90,tx:cl(hwPx,L,R),t0:now+380,T:1000,arc:150});} if(now>e.stop&&!e.kbv&&ad>8)e.x+=e.dir*Math.min(sp*dt,ad-8); if(e.k!=='ghost'||hwGhostVis(e,now))touch(); } for(let i=V.shots.length-1;i>=0;i--){const s=V.shots[i];if(now<s.t0)continue;const p=(now-s.t0)/s.T; if(s.k==='puddle'){if(Math.abs(s.x-hwPx)<s.r){s.stand+=dt;if(s.stand>450){hwWHit('🧪 Fuj, glut!');V.shots.splice(i,1);continue;}} if(p>=1)V.shots.splice(i,1);continue;} if(p<1)continue; if(Math.abs(s.tx-hwPx)<36)hwWHit(s.k==='bone'?'🦴 Bęc!':'🧪 Plusk!'); hwPart(s.tx-hwCam,HW_GROUND-6,s.k==='bone'?'#ece6d4':'#7dff6b',8); if(s.k==='potion')V.shots.push({k:'puddle',x:s.tx,r:50,t0:now,T:2800,stand:0}); V.shots.splice(i,1);} for(let i=V.mine.length-1;i>=0;i--){const m=V.mine[i],alive=V.ens.indexOf(m.e)>=0; if(alive){const c=hwEnC(m.e);m.tx=c.x;m.ty=c.y;} if(now-m.t0<m.T)continue;V.mine.splice(i,1); let e=alive?m.e:null; if(!e)for(const o of V.ens){const c=hwEnC(o);if(Math.hypot(c.x-m.tx,c.y-m.ty)<60){e=o;break;}} // cel już padł — trafia sąsiada if(!e){hwPart(m.tx-hwCam,m.ty,m.col,4);continue;} if(e.k==='ghost'&&!hwGhostVis(e,now)){hwFloat(e.x-hwCam,400,'👻 przeleciało!','#c9b0ff');continue;} hwWDmg(e,now);} if(V.pips<=0){hwWaveLose();return;} if(!V.q.length&&!V.ens.length&&now-V.t0>1500)hwWaveWin(); } function hwWaveWin(){ const V=hwW,G=V.G,reward=Math.round((6+4*V.g)*hwMul()*candyMul()); G.done=true;hwAddCandy(reward);hwStreak=Math.min(4,hwStreak+1);sndBig(); hwFloat(hwPx-hwCam,360,'+'+reward+' 🍬','#ffd24a'); for(let k=0;k<4;k++)hwPart(hwPx-hwCam+(k-1.5)*30,420,HW_CANDY_COLS[k],10); hwBubble={txt:'🏆 Fala '+G.n+' pokonana ('+V.kills+' potworów)! +'+reward+' 🍬. Brama otwarta — pukaj do kolejnych domów'+ (G.n===HW_GPS?'. Na końcu ulicy czeka 👹 BOSS!':'. Za 4 domy następna, mocniejsza fala!'),col:'#2a4a1a',bd:'#7dff6b'}; hwW=null;hwPhase='react';hwT=0; } function hwWaveLose(){ const G=hwW.G;hwHearts--;hwStreak=0;sndBad();hwFloat(hwPx-hwCam,400,'-1 ❤️','#ff5a5a'); hwW=null;hwPx=G.x-170;hwPhase='react';hwT=0; hwBubble={txt:'Potwory cię przegoniły! Straciłeś 1 ❤️. Brama dalej zamknięta — podejdź, kiedy będziesz gotowy.',col:'#4a1a1a',bd:'#ff6a5a'}; } function hwGoHome(){if(hwCandy>0)msg('🏠 Wracasz z '+hwCandy+' 🍬 — są już w worku!');gs='menu';} // 📱 przyciski dotykowe na ulicy: ◀ ▶ (trzymaj), 🚪 PUKAJ, w walce 🍬 RZUCAJ const HB_L={x:14,y:H-118,w:104,h:104}, HB_R={x:W-118,y:H-118,w:104,h:104}, HB_K={x:W/2-130,y:H-100,w:260,h:76}; const inR=(p,R)=>isOR(p.x,p.y,R.x,R.y,R.w,R.h); function hwHoldDir(){let d=0;for(const p of ptrs.values()){if(inR(p,HB_L))d-=1;else if(inR(p,HB_R))d+=1;}return Math.sign(d);} function hwInputDir(){let d=0; if(keys['ArrowLeft']||keys['a']||keys['A'])d-=1; if(keys['ArrowRight']||keys['d']||keys['D'])d+=1; return hwHoldDir()||d;} function updHW(){ hwT++; if(!hwOpenNow()&&hwPhase!=='over'&&hwPhase!=='midnight'){hwPhase='midnight';hwBubble=null;hwF=null;hwW=null;sndBig();} hwMoving=false; // krok liczony z czasu, nie z klatek — na słabszym telefonie mrówka idzie tak samo szybko const now=performance.now(),dt=Math.min(50,now-(hwLastT||now));hwLastT=now; if(hwPhase==='walk'){ let d=hwInputDir(),auto=false; if(d){hwTarget=null;hwAuto=-1;} else if(hwTarget!==null){d=Math.sign(hwTarget-hwPx);auto=true;} if(d){let step=0.22*dt;if(auto)step=Math.min(step,Math.abs(hwTarget-hwPx)); hwPx=Math.max(60,hwPx+d*step);hwDir=d;hwWalkT+=dt/16.7;hwMoving=true;} if(auto&&Math.abs(hwTarget-hwPx)<0.5){hwPx=hwTarget;hwTarget=null; if(hwAuto>=0){const a=hwAuto;hwAuto=-1;if(!hwHouses[a].done&&Math.abs(hwPx-hwHouses[a].x)<60)hwKnockAt(a);}} hwStreet=hwStreetOf(hwKAt(hwPx)); hwGenMore(); for(const G of hwGates)if(!G.done&&hwPx>=G.x-50&&hwPx<G.x+80){hwWaveStart(G);break;} // brama → fala } else if(hwPhase==='knock'){ if(hwT%14===0&&hwT<45)sndKnock(); if(hwT>52){hwPhase='greet';hwT=0; const h=hwHouses[hwIdx]; hwBubble={txt:h.t==='boss'?h.boss.hi:hwPick(HW_RES[h.t].hi),col:'#1a1430',bd:hwRes(h).col};} } else if(hwPhase==='chase')hwUpdChase(); else if(hwPhase==='boss')hwUpdBoss(now,dt); else if(hwPhase==='wave')hwUpdWave(now,dt); // kamera: w walce stoi na zamczysku, poza walką płynnie podąża za mrówką const camT=(hwPhase==='boss'&&hwF)?hwF.h.x-W/2:(hwPhase==='wave'&&hwW)?hwW.cx:Math.max(0,hwPx-W/2); hwCam+=(camT-hwCam)*Math.min(1,dt*0.012); if(hwHearts<=0&&hwPhase!=='over'&&hwPhase!=='midnight'){hwPhase='over';hwBubble=null;hwF=null;hwW=null;} for(let i=hwFloats.length-1;i>=0;i--){const f=hwFloats[i];f.y-=0.5;if(--f.l<=0)hwFloats.splice(i,1);} for(let i=hwParts.length-1;i>=0;i--){const p=hwParts[i];p.x+=p.vx;p.y+=p.vy;p.vy+=0.12;if(--p.l<=0)hwParts.splice(i,1);} } // ── RYSOWANIE ULICY ─────────────────────────────────────────────── // 🎃 dynia-lampion (y = ziemia) function hwPumpkin(x,y,s,face){ const r=14*s,cy=y-r*0.85; if(face){ctx.save();ctx.globalAlpha=0.16;ctx.fillStyle='#ffb04a';ctx.beginPath();ctx.arc(x,cy,r*2.1,0,7);ctx.fill();ctx.restore();} ctx.fillStyle='#d8641a';ctx.beginPath();ctx.ellipse(x,cy,r*1.2,r*0.85,0,0,7);ctx.fill(); ctx.strokeStyle='#8a3a08';ctx.lineWidth=1.4; ctx.beginPath();ctx.ellipse(x,cy,r*0.45,r*0.85,0,0,7);ctx.stroke(); ctx.beginPath();ctx.ellipse(x,cy,r*1.2,r*0.85,0,0,7);ctx.stroke(); ctx.fillStyle='#3a6a1a';ctx.fillRect(x-1.6*s,cy-r*0.85-5*s,3.2*s,6*s); if(!face)return; const fl=0.7+0.3*Math.sin(frame*0.21+x*0.7); ctx.fillStyle='rgba(255,'+(190+((fl*50)|0))+',70,'+fl.toFixed(2)+')'; [-1,1].forEach(sd=>{ctx.beginPath();ctx.moveTo(x+sd*r*0.62,cy-r*0.05);ctx.lineTo(x+sd*r*0.26,cy-r*0.05);ctx.lineTo(x+sd*r*0.44,cy-r*0.42);ctx.fill();}); ctx.beginPath();ctx.moveTo(x-r*0.7,cy+r*0.2); for(let k=0;k<=6;k++)ctx.lineTo(x-r*0.7+k*r*0.233,cy+r*(k%2?0.32:0.2)); ctx.lineTo(x+r*0.55,cy+r*0.52);ctx.lineTo(x-r*0.55,cy+r*0.52);ctx.closePath();ctx.fill(); } function hwBatShape(x,y,s,flap){ ctx.save();ctx.translate(x,y);ctx.scale(s,s);ctx.fillStyle='#0c0810'; ctx.beginPath();ctx.ellipse(0,0,4,6,0,0,7);ctx.fill(); ctx.beginPath();ctx.moveTo(-2,-2);ctx.quadraticCurveTo(-12,-12-flap,-20,-2);ctx.lineTo(-15,0);ctx.lineTo(-11,4);ctx.lineTo(-6,1);ctx.closePath();ctx.fill(); ctx.beginPath();ctx.moveTo(2,-2);ctx.quadraticCurveTo(12,-12-flap,20,-2);ctx.lineTo(15,0);ctx.lineTo(11,4);ctx.lineTo(6,1);ctx.closePath();ctx.fill(); ctx.beginPath();ctx.moveTo(-3,-5);ctx.lineTo(-2,-9);ctx.lineTo(0,-6);ctx.lineTo(2,-9);ctx.lineTo(3,-5);ctx.fill(); ctx.fillStyle='#ff4a3a';ctx.fillRect(-2,-4,1.4,1.4);ctx.fillRect(0.8,-4,1.4,1.4); ctx.restore(); } function hwGhostShape(x,y,s,t,a){ ctx.save();ctx.translate(x,y+Math.sin(t)*4);ctx.scale(s,s); ctx.globalAlpha=a==null?0.9:a;ctx.fillStyle='#f4f0ff'; ctx.beginPath();ctx.arc(0,-10,12,Math.PI,0);ctx.lineTo(12,10); for(let k=0;k<=4;k++)ctx.lineTo(12-k*6,10+(k%2?-4:2)+Math.sin(t*2+k)*1.5); ctx.closePath();ctx.fill(); ctx.fillStyle='#1a1428';ctx.beginPath();ctx.ellipse(-4,-10,2.2,3.2,0,0,7);ctx.ellipse(4,-10,2.2,3.2,0,0,7);ctx.fill(); ctx.beginPath();ctx.ellipse(0,-2,2.5,3,0,0,7);ctx.fill(); ctx.restore(); } function hwWin(wx,wy,ww,wh,lit){ if(lit){ctx.save();ctx.globalAlpha=0.18;ctx.fillStyle='#ffb04a';ctx.fillRect(wx-6,wy-6,ww+12,wh+12);ctx.restore();} rr(wx,wy,ww,wh,3,lit?'#ffd98a':'#161226',lit?'#c07a2a':'#2a2038',2); ctx.strokeStyle=lit?'rgba(140,80,20,0.7)':'rgba(60,50,80,0.8)';ctx.lineWidth=2; ctx.beginPath();ctx.moveTo(wx+ww/2,wy);ctx.lineTo(wx+ww/2,wy+wh);ctx.moveTo(wx,wy+wh/2);ctx.lineTo(wx+ww,wy+wh/2);ctx.stroke(); } function drawHouse(h,i){ if(h.t==='boss')return drawBossHouse(h); const x=h.x-hwCam, R=HW_RES[h.t], S=h.s; if(x<-220||x>W+220)return; const w=S.w,hh=S.two?270:190,y=420-hh,lit=(h.t==='babcia'||h.t==='mrowki'||h.t==='dynia'||h.t==='wiedzma'); // komin (za dachem) if(S.chimney)rr(x+w*0.2,y-56,18,46,2,'#2a1e24','#140c12',2); // ściany z deskami rr(x-w/2,y,w,hh,5,S.wall,'#120c18',2); ctx.strokeStyle='rgba(255,255,255,0.05)';ctx.lineWidth=1.5; for(let yy=y+14;yy<420;yy+=16){ctx.beginPath();ctx.moveTo(x-w/2+3,yy);ctx.lineTo(x+w/2-3,yy);ctx.stroke();} // dach z dachówkami const ov=14,ap=62; ctx.beginPath();ctx.moveTo(x-w/2-ov,y);ctx.lineTo(x,y-ap);ctx.lineTo(x+w/2+ov,y);ctx.closePath(); ctx.fillStyle=S.roof;ctx.fill();ctx.strokeStyle='#120a10';ctx.lineWidth=2;ctx.stroke(); ctx.strokeStyle='rgba(0,0,0,0.25)';ctx.lineWidth=1.5; for(let k=1;k<=3;k++){const yy=y-k*15,hw=(w/2+ov)*(1-k*15/ap);ctx.beginPath();ctx.moveTo(x-hw,yy);ctx.lineTo(x+hw,yy);ctx.stroke();} // lampki na dachu if(S.lights){const pts=[];const A=[x-w/2-ov,y],B=[x,y-ap],C=[x+w/2+ov,y]; for(let k=0;k<=8;k++)pts.push([A[0]+(B[0]-A[0])*k/8,A[1]+(B[1]-A[1])*k/8]); for(let k=1;k<=8;k++)pts.push([B[0]+(C[0]-B[0])*k/8,B[1]+(C[1]-B[1])*k/8]); const LC=['#ff6a2a','#b06bff','#7dff6b','#ffd24a']; pts.forEach((p,k)=>{const on=Math.sin(frame*0.08+k*1.3)>-0.3;ctx.fillStyle=on?LC[k%4]:'#2a2030'; ctx.beginPath();ctx.arc(p[0],p[1]+3,2.6,0,7);ctx.fill();});} if(S.bat)hwBatShape(x-w*0.18,y-ap*0.62,0.9,Math.sin(frame*0.25+i)*3); // pajęczyna w rogu if(S.web){ctx.strokeStyle='rgba(220,220,240,0.45)';ctx.lineWidth=1;const cx=x-w/2+2,cy=y+2; for(let k=0;k<=4;k++){const a=k/4*Math.PI/2;ctx.beginPath();ctx.moveTo(cx,cy);ctx.lineTo(cx+Math.cos(a)*28,cy+Math.sin(a)*28);ctx.stroke();} [10,18,26].forEach(rd=>{ctx.beginPath();ctx.arc(cx,cy,rd,0.05,Math.PI/2-0.05);ctx.stroke();});} // piętro: okna albo balkon z drzwiami if(S.two){ rr(x-w/2-4,226,w+8,6,2,'#1a1220',null); if(S.balcony){ hwWin(x-w/2+12,172,30,32,lit);hwWin(x+w/2-42,172,30,32,lit); rr(x-15,168,30,58,3,lit?'#ffd98a':'#161226','#2a1a10',2); rr(x-42,222,84,7,2,'#2a1a22','#120a10',1.5); ctx.strokeStyle='#2a1a22';ctx.lineWidth=2.5; ctx.beginPath();ctx.moveTo(x-42,202);ctx.lineTo(x+42,202);ctx.stroke(); for(let k=0;k<=8;k++){ctx.beginPath();ctx.moveTo(x-40+k*10,202);ctx.lineTo(x-40+k*10,222);ctx.stroke();} hwPumpkin(x+28,201,0.55,true); } else {hwWin(x-w/2+16,170,40,38,lit);hwWin(x+w/2-56,170,40,38,lit);} if(S.ghost)hwGhostShape(x-w/2-8,S.balcony?186:150,1,frame*0.05+i); } // parter hwWin(x-w/2+16,258,40,38,lit);hwWin(x+w/2-56,258,40,38,lit); // drzwi + schodek + lampka przy drzwiach rr(x-32,416,64,6,2,'#2a2030',null); rr(x-26,322,52,98,4,S.door,'#140c06',2); if(h.open>0){rr(x-24,324,48-h.open*0.2,94,3,'#0a0710',null); ctx.font='40px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(R.ic,x,370);} else{ctx.fillStyle='#c9a04a';ctx.beginPath();ctx.arc(x+14,372,3.5,0,7);ctx.fill();} ctx.save();ctx.globalAlpha=0.25;ctx.fillStyle='#ffc070';ctx.beginPath();ctx.arc(x+38,334,12,0,7);ctx.fill();ctx.restore(); rr(x+34,328,8,12,2,'#ffd98a','#5a3a18',1.5); // nagrobek i dynie przed domem if(S.tomb){const tx0=x-w/2+18;rr(tx0-11,392,22,28,[10,10,2,2],'#6a6a7a','#34344a',1.5);tx('RIP',tx0,404,7,'#2a2a3a','center',true);} S.pk.forEach((p,k)=>hwPumpkin(x+p.dx,421,p.s,k===0||lit)); // wskazówka mieszkańca nad domem + numer/status if(R.prop){ctx.font='22px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(R.prop,x,y-24);} if(h.done){ctx.font='22px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('✅',x,306);} else tx('#'+(i+1),x,312,11,'rgba(220,200,240,0.45)','center'); } // 👹 dom bossa: zamczysko z dwiema wieżami, świecące okna, szyld z imieniem, dynie przy wejściu function drawBossHouse(h){ const x=h.x-hwCam,B=h.boss; if(x<-260||x>W+260)return; const w=196,hh=240,y=420-hh,fl=0.75+0.25*Math.sin(frame*0.13+h.x); ctx.save();const g=ctx.createRadialGradient(x,y+60,20,x,y+60,210); g.addColorStop(0,B.col+'40');g.addColorStop(1,'rgba(0,0,0,0)');ctx.fillStyle=g;ctx.fillRect(x-230,y-140,460,400);ctx.restore(); [-1,1].forEach(s=>{const tw=x+s*(w/2-6)-18; rr(tw,y-34,36,hh+34,3,'#22183a','#0e0a18',2); ctx.beginPath();ctx.moveTo(tw-7,y-34);ctx.lineTo(tw+18,y-96);ctx.lineTo(tw+43,y-34);ctx.closePath(); ctx.fillStyle='#3a1a2a';ctx.fill();ctx.strokeStyle='#120810';ctx.lineWidth=2;ctx.stroke(); ctx.save();ctx.globalAlpha=fl;rr(tw+11,y-6,14,22,7,'#ff5a3a',null);ctx.restore();}); rr(x-w/2,y,w,hh,6,'#2e1f44','#120c1e',2); ctx.beginPath();ctx.moveTo(x-w/2-16,y);ctx.lineTo(x,y-84);ctx.lineTo(x+w/2+16,y);ctx.closePath(); ctx.fillStyle='#4a1a2a';ctx.fill();ctx.strokeStyle='#160810';ctx.lineWidth=2;ctx.stroke(); ctx.save();ctx.globalAlpha=fl; for(let k=-1;k<=1;k++)rr(x+k*56-15,y+26,30,38,12,'#ff7a2a','#ffb04a',1.5); ctx.restore(); hwPumpkin(x,y-30,1.3,true); rr(x-70,y+80,140,26,7,'#120a1c',B.col,2);tx('👹 '+B.n,x,y+93,11,B.col,'center',true); // drzwi z łukiem ctx.beginPath();ctx.moveTo(x-34,y+hh);ctx.lineTo(x-34,y+150);ctx.arc(x,y+150,34,Math.PI,0);ctx.lineTo(x+34,y+hh);ctx.closePath(); ctx.fillStyle=h.open>0?'#07050c':'#3a1f12';ctx.fill();ctx.strokeStyle='#1a0c06';ctx.lineWidth=2.5;ctx.stroke(); if(h.open>0&&!h.done&&hwPhase!=='boss'){ctx.save();ctx.translate(x,y+176);ctx.scale(0.42,0.42); hwDrawBossChar(0,0,B,{});ctx.restore();} else if(!h.open){ctx.fillStyle='#d4a84a';ctx.beginPath();ctx.arc(x+20,y+190,4,0,7);ctx.fill();} [[-62,1.1],[-84,0.7],[62,1.1],[86,0.8]].forEach(([dx,s])=>hwPumpkin(x+dx,421,s,true)); if(h.done){ctx.font='28px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('✅',x,y+128);} } // 👹 postać bossa: płaszcz z postrzępionym dołem, ręce, GŁOWA-DYNIA ze świecącą buzią + korona/kaptur+kosa/kapelusz+miotła/skrzydła. // st: {hurt, wind (zamach do rzutu), angry, shield} function hwDrawBossChar(x,y,B,st){ const t=frame*0.06; ctx.save();ctx.translate(x,y);ctx.lineJoin='round';ctx.lineCap='round'; if(B.hat==='wings'){const fl=Math.sin(frame*0.2)*0.25; [-1,1].forEach(s=>{ctx.save();ctx.scale(s,1);ctx.rotate(fl); ctx.beginPath();ctx.moveTo(14,6);ctx.quadraticCurveTo(70,-70,128,-14);ctx.lineTo(108,6);ctx.lineTo(92,-6);ctx.lineTo(78,18); ctx.lineTo(62,4);ctx.lineTo(44,28);ctx.closePath();ctx.fillStyle='#1a0a1e';ctx.fill();ctx.strokeStyle='#5a1a3a';ctx.lineWidth=2;ctx.stroke();ctx.restore();});} if(B.hat==='hood'){ctx.save();ctx.translate(-62,6);ctx.rotate(-0.12+(st.wind?0.5:0)); ctx.strokeStyle='#5a3a1a';ctx.lineWidth=5;ctx.beginPath();ctx.moveTo(0,100);ctx.lineTo(0,-86);ctx.stroke(); ctx.beginPath();ctx.moveTo(0,-86);ctx.quadraticCurveTo(62,-100,84,-52);ctx.quadraticCurveTo(52,-78,0,-70);ctx.closePath(); ctx.fillStyle='#cfd6e0';ctx.fill();ctx.strokeStyle='#6a7080';ctx.lineWidth=1.5;ctx.stroke();ctx.restore();} if(B.hat==='witch'){ctx.save();ctx.translate(-50,40);ctx.rotate(0.5); ctx.strokeStyle='#6a4a22';ctx.lineWidth=5;ctx.beginPath();ctx.moveTo(0,-80);ctx.lineTo(0,60);ctx.stroke(); ctx.fillStyle='#c8a050';ctx.beginPath();ctx.moveTo(-6,56);ctx.lineTo(6,56);ctx.lineTo(16,96);ctx.lineTo(-16,96);ctx.closePath();ctx.fill(); ctx.strokeStyle='#8a6a2a';ctx.lineWidth=1.2;for(let k=-12;k<=12;k+=6){ctx.beginPath();ctx.moveTo(k*0.4,60);ctx.lineTo(k,95);ctx.stroke();} ctx.restore();} // płaszcz ctx.beginPath();ctx.moveTo(-26,0);ctx.lineTo(26,0);ctx.quadraticCurveTo(46,56,58,108); for(let k=0;k<=8;k++)ctx.lineTo(58-k*14.5,108+(k%2?14:0)+Math.sin(t*1.6+k)*3); ctx.quadraticCurveTo(-46,56,-26,0);ctx.closePath(); ctx.fillStyle=B.cloak;ctx.fill();ctx.strokeStyle=B.trim;ctx.lineWidth=3;ctx.stroke(); ctx.strokeStyle='rgba(0,0,0,0.3)';ctx.lineWidth=2; [-18,0,18].forEach(dx=>{ctx.beginPath();ctx.moveTo(dx*0.5,10);ctx.lineTo(dx*1.6,104);ctx.stroke();}); ctx.fillStyle=B.trim;ctx.beginPath();ctx.arc(0,12,6,0,7);ctx.fill(); // ręce: lewa trzyma worek cukierków, prawa rzuca (zamach do tyłu i nad głowę) const arm=(s,a,hold)=>{ctx.save();ctx.translate(s*22,8);ctx.rotate(a); ctx.strokeStyle=B.cloak;ctx.lineWidth=14;ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(0,40);ctx.stroke(); ctx.strokeStyle=B.trim;ctx.lineWidth=2;ctx.beginPath();ctx.moveTo(-7,38);ctx.lineTo(7,38);ctx.stroke(); ctx.fillStyle=B.hand;ctx.beginPath();ctx.arc(0,46,7,0,7);ctx.fill(); if(hold==='bag'){ctx.fillStyle='#7a4a1a';ctx.beginPath();ctx.ellipse(0,62,14,13,0,0,7);ctx.fill(); ctx.strokeStyle='#3a1a08';ctx.lineWidth=1.5;ctx.stroke(); ['#ff4a8a','#5adcff','#ffe14a'].forEach((c,k)=>{ctx.fillStyle=c;ctx.beginPath();ctx.arc(-6+k*6,50,3.4,0,7);ctx.fill();});} if(hold==='candy')hwCandyShape(0,56,'#ff4a8a',t*3,1.1); ctx.restore();}; arm(-1,0.45+Math.sin(t)*0.08,'bag'); arm(1,st.wind?-2.6:-0.5+Math.sin(t*1.3)*0.15,st.wind?'candy':null); // kaptur Kostuchy za dynią if(B.hat==='hood'){ctx.beginPath();ctx.moveTo(-40,4);ctx.quadraticCurveTo(-48,-74,0,-80);ctx.quadraticCurveTo(48,-74,40,4);ctx.closePath(); ctx.fillStyle='#0c0a10';ctx.fill();ctx.strokeStyle=B.trim;ctx.lineWidth=2;ctx.stroke();} // głowa-dynia ze świecącą buzią const hy=-30; ctx.save();ctx.globalAlpha=0.22;ctx.fillStyle=st.angry?'#ff3a2a':'#ffb04a';ctx.beginPath();ctx.arc(0,hy,56,0,7);ctx.fill();ctx.restore(); ctx.fillStyle='#e8701a';ctx.beginPath();ctx.ellipse(0,hy,40,33,0,0,7);ctx.fill(); ctx.strokeStyle='#9a4208';ctx.lineWidth=2; [13,27].forEach(rx=>{ctx.beginPath();ctx.ellipse(0,hy,rx,33,0,0,7);ctx.stroke();}); ctx.beginPath();ctx.ellipse(0,hy,40,33,0,0,7);ctx.stroke(); ctx.fillStyle='#3a6a1a';ctx.beginPath();ctx.moveTo(-4,hy-32);ctx.quadraticCurveTo(-2,hy-44,8,hy-46);ctx.lineTo(6,hy-40);ctx.lineTo(4,hy-31);ctx.closePath();ctx.fill(); const glow=st.angry?'#ff4a2a':'#ffe14a';ctx.fillStyle=glow; [-1,1].forEach(s=>{ctx.beginPath(); if(st.angry){ctx.moveTo(s*24,hy-16);ctx.lineTo(s*6,hy-8);ctx.lineTo(s*20,hy-2);} else{ctx.moveTo(s*22,hy-4);ctx.lineTo(s*8,hy-4);ctx.lineTo(s*15,hy-18);} ctx.closePath();ctx.fill();}); ctx.beginPath();ctx.moveTo(-24,hy+6); for(let k=0;k<=8;k++)ctx.lineTo(-24+k*6,hy+6+(k%2?6:0)); ctx.quadraticCurveTo(0,hy+28,-24,hy+6);ctx.closePath();ctx.fill(); if(st.hurt){ctx.save();ctx.globalAlpha=0.6;ctx.fillStyle='#fff';ctx.beginPath();ctx.ellipse(0,hy,41,34,0,0,7);ctx.fill();ctx.restore();} // nakrycie głowy if(B.hat==='crown'){ctx.fillStyle='#ffd24a';ctx.strokeStyle='#a87a10';ctx.lineWidth=1.5; ctx.beginPath();ctx.moveTo(-22,hy-28);ctx.lineTo(-24,hy-52);ctx.lineTo(-12,hy-40);ctx.lineTo(0,hy-58);ctx.lineTo(12,hy-40);ctx.lineTo(24,hy-52);ctx.lineTo(22,hy-28);ctx.closePath();ctx.fill();ctx.stroke(); ['#ff4a4a','#5adcff','#7dff6b'].forEach((c,k)=>{ctx.fillStyle=c;ctx.beginPath();ctx.arc(-12+k*12,hy-34,3,0,7);ctx.fill();});} if(B.hat==='witch'){ctx.fillStyle='#2a1440';ctx.strokeStyle='#120a20';ctx.lineWidth=2; ctx.beginPath();ctx.ellipse(0,hy-28,48,9,-0.08,0,7);ctx.fill();ctx.stroke(); ctx.beginPath();ctx.moveTo(-26,hy-30);ctx.lineTo(22,hy-30);ctx.quadraticCurveTo(14,hy-70,30,hy-96);ctx.quadraticCurveTo(-6,hy-80,-26,hy-30);ctx.closePath();ctx.fill();ctx.stroke(); rr(-25,hy-42,48,8,2,B.trim,null);} if(B.hat==='wings'){ctx.fillStyle='#c0203a';ctx.beginPath();ctx.moveTo(-34,-4);ctx.lineTo(-48,-30);ctx.lineTo(-20,-8);ctx.closePath();ctx.fill(); ctx.beginPath();ctx.moveTo(34,-4);ctx.lineTo(48,-30);ctx.lineTo(20,-8);ctx.closePath();ctx.fill();} if(st.shield){const a=0.35+0.15*Math.sin(frame*0.3); ctx.save();ctx.globalAlpha=a;ctx.fillStyle='#5ab0ff';ctx.beginPath();ctx.arc(0,20,98,0,7);ctx.fill();ctx.restore(); ctx.strokeStyle='#bfe4ff';ctx.lineWidth=3;ctx.beginPath();ctx.arc(0,20,98,0,7);ctx.stroke();} ctx.restore(); } // 🍬 cukierek w papierku function hwCandyShape(x,y,col,rot,s){ ctx.save();ctx.translate(x,y);ctx.rotate(rot);ctx.scale(s||1,s||1); ctx.fillStyle=col;ctx.beginPath();ctx.moveTo(-8,0);ctx.lineTo(-15,-6);ctx.lineTo(-15,6);ctx.closePath();ctx.fill(); ctx.beginPath();ctx.moveTo(8,0);ctx.lineTo(15,-6);ctx.lineTo(15,6);ctx.closePath();ctx.fill(); ctx.beginPath();ctx.ellipse(0,0,9,6.5,0,0,7);ctx.fill(); ctx.strokeStyle='rgba(255,255,255,0.75)';ctx.lineWidth=1.6;ctx.beginPath();ctx.moveTo(-4,-5);ctx.lineTo(1,5);ctx.moveTo(2,-5);ctx.lineTo(6,4);ctx.stroke(); ctx.restore(); } // 🏮 latarnie między domami (klimat + widać, że się idzie) function drawLamps(){ for(let k=0;k+1<hwHouses.length;k+=2){const j=k%HW_PER; if(j%HW_WAVE===HW_WAVE-1&&j<HW_PER-1)continue; // tu stoi brama fali const lx=(hwHouses[k].x+hwHouses[k+1].x)/2-hwCam;if(lx<-40)continue;if(lx>W+40)break; ctx.fillStyle='#3a2e4a';ctx.fillRect(lx-3,300,6,120); ctx.save();const g=ctx.createRadialGradient(lx,296,2,lx,296,46);g.addColorStop(0,'rgba(255,190,90,0.55)');g.addColorStop(1,'rgba(255,190,90,0)'); ctx.fillStyle=g;ctx.fillRect(lx-50,246,100,100);ctx.restore(); rr(lx-8,284,16,22,4,'#ffcf7a','#5a3a18',2); } } // 🐜 mrówka gracza — z boku: głowa z okiem i czułkami, tułów, przewężenie, duży odwłok, 6 nóg w chodzie trójpodporowym; // przednią nogą niesie dyniowe wiaderko na cukierki function drawHwAnt(x,y,dir,wt,moving){ const ph=wt*0.32, bob=moving?-Math.abs(Math.sin(ph))*2.2:Math.sin(frame*0.06)*0.8; const BODY='#a8321e',FAR='#5a160c',LEGC='#3c0f08',OL='#2a0804'; ctx.save();ctx.translate(x,y); ctx.fillStyle='rgba(0,0,0,0.35)';ctx.beginPath();ctx.ellipse(-2,31,52,6,0,0,7);ctx.fill(); ctx.scale(dir*1.15,1.15); ctx.lineCap='round';ctx.lineJoin='round'; const leg=(hx,spread,p,col,lw)=>{ const sw=moving?Math.sin(p)*9:0, lift=moving?Math.max(0,Math.cos(p))*6:0; const fx=hx+spread+sw, fy=27-lift, kx=hx+(spread+sw)*0.45+(spread>=0?7:-7), ky=-3+bob-lift*0.4; ctx.strokeStyle=col;ctx.lineWidth=lw; ctx.beginPath();ctx.moveTo(hx,5+bob);ctx.lineTo(kx,ky);ctx.lineTo(fx,fy);ctx.stroke(); }; // dalsze nogi (za ciałem) [[7,16],[0,1],[-8,-17]].forEach((l,i)=>leg(l[0]-2,l[1]-2,ph+(i%2?0:Math.PI),FAR,3)); // odwłok ctx.save();ctx.translate(-31,-5+bob);ctx.rotate(-0.35); ctx.beginPath();ctx.ellipse(0,0,22,16,0,0,7);ctx.fillStyle=BODY;ctx.fill();ctx.strokeStyle=OL;ctx.lineWidth=2.4;ctx.stroke(); ctx.strokeStyle='rgba(40,8,4,0.55)';ctx.lineWidth=2; [-7,2,11].forEach(sx=>{ctx.beginPath();ctx.ellipse(sx,0,4,15,0,-1.2,1.2);ctx.stroke();}); ctx.fillStyle='rgba(255,210,170,0.35)';ctx.beginPath();ctx.ellipse(-4,-8,9,4,-0.2,0,7);ctx.fill(); ctx.restore(); // przewężenie + tułów ctx.beginPath();ctx.ellipse(-11,1+bob,5,4.5,0,0,7);ctx.fillStyle=BODY;ctx.fill();ctx.strokeStyle=OL;ctx.lineWidth=2;ctx.stroke(); ctx.save();ctx.translate(1,-1+bob);ctx.rotate(-0.25); ctx.beginPath();ctx.ellipse(0,0,12,8.5,0,0,7);ctx.fillStyle=BODY;ctx.fill();ctx.strokeStyle=OL;ctx.lineWidth=2.2;ctx.stroke(); ctx.fillStyle='rgba(255,210,170,0.3)';ctx.beginPath();ctx.ellipse(-2,-4,6,2.5,0,0,7);ctx.fill(); ctx.restore(); // czułki (lekko falują) const aw=Math.sin(frame*0.12)*2; ctx.strokeStyle=OL;ctx.lineWidth=2.2; ctx.beginPath();ctx.moveTo(18,-24+bob);ctx.lineTo(19,-43+bob);ctx.lineTo(32,-54+bob+aw);ctx.stroke(); ctx.beginPath();ctx.moveTo(23,-23+bob);ctx.lineTo(28,-41+bob);ctx.lineTo(42,-47+bob-aw);ctx.stroke(); ctx.fillStyle=BODY;[[32,-54+aw],[42,-47-aw]].forEach(([ax,ay])=>{ctx.beginPath();ctx.arc(ax,ay+bob,3.2,0,7);ctx.fill();ctx.stroke();}); // głowa ctx.beginPath();ctx.arc(21,-13+bob,13,0,7);ctx.fillStyle=BODY;ctx.fill();ctx.strokeStyle=OL;ctx.lineWidth=2.4;ctx.stroke(); ctx.fillStyle='rgba(255,210,170,0.3)';ctx.beginPath();ctx.ellipse(16,-20+bob,5,3,-0.5,0,7);ctx.fill(); ctx.beginPath();ctx.ellipse(25,-17+bob,5.2,6.2,0,0,7);ctx.fillStyle='#fff';ctx.fill();ctx.strokeStyle=OL;ctx.lineWidth=1.4;ctx.stroke(); ctx.beginPath();ctx.ellipse(26.6,-16.4+bob,2.8,3.5,0,0,7);ctx.fillStyle='#111';ctx.fill(); ctx.beginPath();ctx.arc(27.6,-18.2+bob,1.1,0,7);ctx.fillStyle='#fff';ctx.fill(); ctx.fillStyle='rgba(255,120,140,0.45)';ctx.beginPath();ctx.arc(28,-8+bob,3,0,7);ctx.fill(); ctx.strokeStyle=OL;ctx.lineWidth=1.6;ctx.beginPath();ctx.arc(28,-10+bob,4.5,0.35,1.5);ctx.stroke(); // żuwaczki ctx.lineWidth=2.2;ctx.beginPath();ctx.moveTo(32,-7+bob);ctx.quadraticCurveTo(38,-6+bob,36,-1+bob);ctx.stroke(); // bliższe nogi (przed ciałem) — przednia trzyma wiaderko [[0,1],[-8,-17]].forEach((l,i)=>leg(l[0],l[1],ph+(i%2?0:Math.PI),LEGC,3.4)); ctx.strokeStyle=LEGC;ctx.lineWidth=3.4; ctx.beginPath();ctx.moveTo(8,5+bob);ctx.lineTo(22,6+bob);ctx.lineTo(33,3+bob);ctx.stroke(); // dyniowe wiaderko const bx=38,by=15+bob+(moving?Math.sin(ph)*1.5:0); ctx.strokeStyle='#2a1a0a';ctx.lineWidth=1.8;ctx.beginPath();ctx.arc(bx,by-2,9,Math.PI*1.05,-0.05);ctx.stroke(); ctx.beginPath();ctx.ellipse(bx,by+4,10,9,0,0,7);ctx.fillStyle='#ff8a1a';ctx.fill();ctx.strokeStyle='#8a3a08';ctx.lineWidth=1.6;ctx.stroke(); ctx.beginPath();ctx.ellipse(bx,by+4,4,9,0,0,7);ctx.stroke(); ctx.fillStyle='#2a1406'; ctx.beginPath();ctx.moveTo(bx-6,by+1);ctx.lineTo(bx-3,by+4);ctx.lineTo(bx-6,by+4);ctx.fill(); ctx.beginPath();ctx.moveTo(bx+6,by+1);ctx.lineTo(bx+3,by+4);ctx.lineTo(bx+6,by+4);ctx.fill(); ctx.beginPath();ctx.moveTo(bx-5,by+7);ctx.lineTo(bx+5,by+7);ctx.lineTo(bx,by+10);ctx.fill(); ['#ff4a8a','#5adcff','#ffe14a'].forEach((c,k)=>{ctx.fillStyle=c;ctx.beginPath();ctx.arc(bx-4+k*4,by-4,2.2,0,7);ctx.fill();}); // ozdoby z eventu const hat=have('korona')?'👑':(have('czapka')?'🎃':''); if(hat){ctx.font='17px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(hat,20,-31+bob);} ctx.restore(); } function drawHWStreet(){ const now=performance.now(),F=(hwPhase==='boss')?hwF:null,Wv=(hwPhase==='wave')?hwW:null; ctx.save(); if((F&&now<F.shake)||(Wv&&now<Wv.shake))ctx.translate((Math.random()-0.5)*9,(Math.random()-0.5)*6); // niebo + księżyc const g=ctx.createLinearGradient(0,0,0,H);g.addColorStop(0,'#0d0820');g.addColorStop(1,'#241030'); ctx.fillStyle=g;ctx.fillRect(-10,-10,W+20,H+20); ctx.save();ctx.shadowColor='#ffe6a0';ctx.shadowBlur=40;ctx.fillStyle='#ffeec0'; ctx.beginPath();ctx.arc(W-120,90,38,0,7);ctx.fill();ctx.restore(); for(let i=0;i<40;i++){const sx=(i*211+37)%W,sy=(i*97)%200; ctx.globalAlpha=0.3+0.3*Math.sin(frame*0.02+i);ctx.fillStyle='#fff';ctx.fillRect(sx,sy,2,2);} ctx.globalAlpha=1; // domy hwHouses.forEach(drawHouse); drawLamps(); // chodnik ctx.fillStyle='#1a1428';ctx.fillRect(-10,420,W+20,H-410); ctx.strokeStyle='#2a2038';ctx.lineWidth=2; for(let x=-(hwCam%60);x<W;x+=60){ctx.beginPath();ctx.moveTo(x,420);ctx.lineTo(x,H);ctx.stroke();} hwDrawGates(); if(F)hwDrawFightBack(now); if(Wv)hwDrawWaveBack(now); // mrówka gracza (miga po trafieniu) const inv=(F&&now<F.inv)||(Wv&&now<Wv.inv); if(!(inv&&((now/90)|0)%2))drawHwAnt(hwPx-hwCam,462,hwDir,hwWalkT,hwMoving); if(F)hwDrawFightFront(now); if(Wv)hwDrawWaveFront(now); // cząstki/floaty for(const p of hwParts){ctx.globalAlpha=cl(p.l/40,0,1);ctx.fillStyle=p.col;ctx.fillRect(p.x-2,p.y-2,4,4);}ctx.globalAlpha=1; for(const f of hwFloats){ctx.globalAlpha=cl(f.l/50,0,1);tx(f.t,f.x,f.y,15,f.col,'center',true);}ctx.globalAlpha=1; ctx.restore(); // chodzenie: podpowiedź, 🚪 PUKAJ, ◀ ▶ if(hwPhase==='walk'){const i=hwNearHouse(); if(i>=0){const h=hwHouses[i],hx=h.x-hwCam; ctx.save();ctx.globalAlpha=0.7+0.3*Math.sin(frame*0.15); tx('❗',hx,h.t==='boss'?64:hwHouseTop(h)-18,28,'#ffd24a','center',true);ctx.restore(); const kb=isOR(mouse.x,mouse.y,HB_K.x,HB_K.y,HB_K.w,HB_K.h),pulse=1+0.04*Math.sin(frame*0.2); ctx.save();ctx.translate(W/2,HB_K.y+HB_K.h/2);ctx.scale(pulse,pulse); rr(-HB_K.w/2,-HB_K.h/2,HB_K.w,HB_K.h,18,kb?'#a85a10':'#7a3a08','#ffd24a',3); tx(h.t==='boss'?'👹 PUKAJ!':'🚪 PUKAJ!',0,0,28,'#fff','center',true);ctx.restore();} else{const G=hwGates.find(G=>!G.done&&G.x>hwPx&&G.x-hwPx<330); tx(G?'🧟 Za bramą czekają potwory — podejdź, żeby walczyć!':'◀ ▶ idź do domów — albo dotknij domu',W/2,H-62,15,G?'#9aff7a':'#8a7a9a','center',true);} hwDrawArrows(); } if(hwPhase==='knock')tx('puk… puk… puk…',W/2,250,20,'#ffd24a','center',true); // dymek if(hwBubble&&(hwPhase==='greet'||hwPhase==='react')){ const bw=620,bx=W/2-bw/2,by=90; const lines=hwWrap(hwBubble.txt,bw-40); const bh=30+lines.length*24; ctx.save();ctx.globalAlpha=0.96;rr(bx,by,bw,bh,14,hwBubble.col,hwBubble.bd,2.5);ctx.restore(); ctx.beginPath();ctx.moveTo(W/2-14,by+bh);ctx.lineTo(W/2+14,by+bh);ctx.lineTo(W/2,by+bh+18);ctx.closePath(); ctx.fillStyle=hwBubble.col;ctx.fill(); lines.forEach((ln,i)=>tx(ln,W/2,by+26+i*24,15,'#fff','center',false)); if(hwIdx>=0){const R=hwRes(hwHouses[hwIdx]);tx(R.ic+' '+R.n,bx+14,by-12,13,R.col,'left',true);} } // przyciski wyboru (u bossa: walka albo odejście) if(hwPhase==='greet'){ const y=H-92,boss=hwHouses[hwIdx].t==='boss'; const t1=isOR(mouse.x,mouse.y,W/2-320,y,300,64), t2=isOR(mouse.x,mouse.y,W/2+20,y,300,64); rr(W/2-320,y,300,64,14,boss?(t1?'#a82a2a':'#7a1a1a'):(t1?'#2a7d2a':'#1a5a1a'),boss?'#ff6a5a':'#7dff6b',2.5); tx(boss?'⚔️ WALCZ!':'🍬 CUKIEREK',W/2-170,y+32,24,'#fff','center',true); rr(W/2+20,y,300,64,14,boss?(t2?'#3a3a5a':'#22223a'):(t2?'#a85a10':'#7a3a08'),boss?'#8a8ab0':'#ff9a3a',2.5); tx(boss?'🏃 Nie teraz':'🎃 PSIKUS',W/2+170,y+32,24,'#fff','center',true); } if(hwPhase==='react'){ const y=H-84,hb=isOR(mouse.x,mouse.y,W/2-110,y,220,54); rr(W/2-110,y,220,54,12,hb?'#3a3a5a':'#22223a','#8a8ab0',2); tx('Dalej ▶',W/2,y+27,20,'#fff','center',true); } if(hwPhase==='chase'){ ctx.save();ctx.globalAlpha=0.55;ctx.fillStyle='#000';ctx.fillRect(0,0,W,H);ctx.restore(); tx('🏃 UCIEKAJ! Klikaj!',W/2,180,34,'#ff6a5a','center',true); const bw=520,bx=W/2-bw/2; rr(bx,240,bw,26,10,'#2a1010','#ff6a5a',2); ctx.fillStyle='#ff5a3c';ctx.fillRect(bx+3,243,(bw-6)*cl(hwT/150,0,1),20); rr(bx,286,bw,22,8,'#101a10','#7dff6b',2); ctx.fillStyle='#7dff6b';ctx.fillRect(bx+3,289,(bw-6)*cl(hwChase/hwChaseNeed,0,1),16); const rb=isOR(mouse.x,mouse.y,W/2-160,340,320,80); rr(W/2-160,340,320,80,16,rb?'#2a7d2a':'#1a5a1a','#7dff6b',3); tx('🏃 BIEGNIJ!',W/2,380,30,'#fff','center',true); tx('(albo naciskaj spację)',W/2,436,13,'#9ab','center'); } if(F)hwDrawFightUI(now); if(Wv)hwDrawWaveUI(now); hwHUD(); if(hwPhase==='over')hwOver(); if(hwPhase==='midnight')hwMidnight(); } function hwDrawArrows(){ const hd=hwHoldDir(); [[HB_L,'◀',-1],[HB_R,'▶',1]].forEach(([R,s,dd])=>{const on=hd===dd; ctx.save();ctx.globalAlpha=on?0.95:0.7; rr(R.x,R.y,R.w,R.h,R.w/2,on?'#5a3a7a':'#2a1a3a','#c9a0ff',3);ctx.restore(); tx(s,R.x+R.w/2,R.y+R.h/2+2,46,'#fff','center',true);}); } // pozycja lecącej rzeczy bossa w chwili now (współrzędne świata) function hwEntPos(e,now){ const p=cl((now-e.t0)/e.T,0,1); if(e.k==='rain')return{x:e.tx,y:e.y0+(HW_GROUND-e.y0)*p*p,p}; if(e.k==='bat')return{x:e.x0+(e.tx-e.x0)*p,y:e.y0+(HW_GROUND-14-e.y0)*p*p+Math.sin(p*Math.PI*4)*12,p}; return{x:e.x0+(e.tx-e.x0)*p,y:e.y0+(HW_GROUND-e.y0)*p-Math.sin(p*Math.PI)*e.arc,p}; } // pod mrówką: ostrzeżenia gdzie spadnie, kałuże glutu; potem sam boss function hwDrawFightBack(now){ const F=hwF; for(const e of F.ents){ if(e.k==='puddle'){const a=cl((e.t0+e.T-now)/600,0,1);ctx.save();ctx.globalAlpha=0.75*a; ctx.fillStyle='#4ad04a';ctx.beginPath();ctx.ellipse(e.x-hwCam,HW_GROUND+14,e.r,11,0,0,7);ctx.fill(); ctx.fillStyle='#9aff7a';for(let k=0;k<3;k++){ctx.beginPath();ctx.arc(e.x-hwCam-30+k*30,HW_GROUND+10-((frame*0.5+k*7)%10),2.5,0,7);ctx.fill();} ctx.restore();continue;} if(e.k==='ghost'||now<e.t0-250)continue; const p=cl((now-e.t0)/e.T,0,1),r=e.k==='bomb'?72:30; ctx.save();ctx.globalAlpha=0.15+0.4*p;ctx.strokeStyle='#ff4a3a';ctx.fillStyle='rgba(255,60,40,0.25)';ctx.lineWidth=2; ctx.beginPath();ctx.ellipse(e.tx-hwCam,HW_GROUND+14,r,9,0,0,7);ctx.fill();ctx.stroke();ctx.restore(); } hwDrawBossChar(F.bx-hwCam,F.by,F.B,{hurt:now<F.flash,wind:!!F.windAtk,angry:F.angry,shield:now<F.shUntil}); } // nad mrówką: to, co leci od bossa, i cukierki mrówki function hwDrawFightFront(now){ const F=hwF; for(const e of F.ents){ if(e.k==='puddle'||now<e.t0)continue; if(e.k==='ghost'){hwGhostShape(e.x-hwCam,446,1.7,frame*0.08);continue;} const q=hwEntPos(e,now),x=q.x-hwCam; if(e.k==='bomb')hwPumpkin(x,q.y+12,1.15,true); else if(e.k==='potion'){ctx.save();ctx.translate(x,q.y);ctx.rotate(q.p*9); ctx.fillStyle='#4ad04a';ctx.beginPath();ctx.arc(0,3,9,0,7);ctx.fill();ctx.fillStyle='#c8e8ff';ctx.fillRect(-3,-12,6,8); ctx.fillStyle='#7a4a1a';ctx.fillRect(-4,-15,8,4);ctx.restore();} else if(e.k==='bat')hwBatShape(x,q.y,1.7,Math.sin(frame*0.6)*5); else hwCandyShape(x,q.y,e.col,e.rot+q.p*12,1.25); } for(const m of F.mine){const p=cl((now-m.t0)/m.T,0,1); hwCandyShape(m.x0+(F.bx-m.x0)*p-hwCam,m.y0+(F.by-30-m.y0)*p-Math.sin(p*Math.PI)*70,m.col,p*14,1.1);} } function hwDrawFightUI(now){ const F=hwF,B=F.B; ctx.save();ctx.globalAlpha=0.9;rr(W/2-280,46,560,66,12,'#120a1c',B.col,2);ctx.restore(); tx('👹 '+B.n+' · ulica '+F.h.st+(F.angry?' 😡':''),W/2,60,15,B.col,'center',true); rr(W/2-260,72,520,18,7,'#2a1010','#ff6a5a',1.5); ctx.fillStyle=F.angry?'#ff3a2a':'#ff7a3a';ctx.fillRect(W/2-258,74,516*Math.max(0,F.hp/F.max),14); tx(F.hp+' / '+F.max,W/2,81,11,'#fff','center',true); tx('Twoja tarcza:',W/2-58,101,12,'#ffd9a0','right',true); for(let k=0;k<5;k++){ctx.fillStyle=k<F.pips?'#ffd24a':'#3a2a2a';ctx.beginPath();ctx.arc(W/2-42+k*20,101,6.5,0,7);ctx.fill(); ctx.strokeStyle='#8a6a2a';ctx.lineWidth=1.2;ctx.stroke();} if(now<F.shUntil)tx('🛡️ boss ma tarczę — przeczekaj!',W/2+160,101,12,'#9ad8ff','center',true); if(now-F.t0<3500)tx('◀ ▶ uciekaj przed tym, co rzuca boss · 🍬 RZUCAJ w niego!',W/2,130,15,'#fff','center',true); hwDrawArrows(); const rb=isOR(mouse.x,mouse.y,HB_K.x,HB_K.y,HB_K.w,HB_K.h); rr(HB_K.x,HB_K.y,HB_K.w,HB_K.h,18,now<F.cool?'#5a2a08':(rb?'#a85a10':'#7a3a08'),'#ffd24a',3); tx('🍬 RZUCAJ!',W/2,HB_K.y+HB_K.h/2,28,'#fff','center',true); } // ── 🧟 FALA: potwory (stopy na y, patrzą w stronę dir) ────────────── function hwZombie(x,y,dir,t){ const sw=Math.sin(t*0.9),SK='#8ac76a',SKD='#4a7a3a'; ctx.save();ctx.translate(x,y);ctx.scale(dir*1.15,1.15);ctx.lineCap='round';ctx.lineJoin='round'; // dalsza noga i ręka (w cieniu) ctx.strokeStyle='#1e2638';ctx.lineWidth=8;ctx.beginPath();ctx.moveTo(-2,-34);ctx.lineTo(-2-sw*9,-5);ctx.stroke(); ctx.strokeStyle=SKD;ctx.lineWidth=6;ctx.beginPath();ctx.moveTo(-2,-62);ctx.lineTo(24,-60+sw*3);ctx.stroke(); // podarta koszula z łatą ctx.fillStyle='#4a6a8a';ctx.beginPath();ctx.moveTo(-12,-67);ctx.lineTo(10,-67);ctx.lineTo(12,-36);ctx.lineTo(7,-31);ctx.lineTo(3,-36); ctx.lineTo(-2,-30);ctx.lineTo(-7,-35);ctx.lineTo(-13,-32);ctx.closePath();ctx.fill();ctx.strokeStyle='#22303e';ctx.lineWidth=1.5;ctx.stroke(); ctx.fillStyle='#8a5a3a';ctx.fillRect(-8,-57,7,7); // bliższa noga, buty ctx.strokeStyle='#2a3450';ctx.lineWidth=8;ctx.beginPath();ctx.moveTo(3,-34);ctx.lineTo(3+sw*9,-5);ctx.stroke(); ctx.fillStyle='#1a1410';ctx.beginPath();ctx.ellipse(1-sw*9,-3,7,4,0,0,7);ctx.fill();ctx.beginPath();ctx.ellipse(6+sw*9,-3,7,4,0,0,7);ctx.fill(); // bliższa ręka wyciągnięta do przodu ctx.strokeStyle=SK;ctx.lineWidth=6;ctx.beginPath();ctx.moveTo(4,-61);ctx.lineTo(30,-57-sw*3);ctx.stroke(); ctx.fillStyle=SK;ctx.beginPath();ctx.arc(31,-57-sw*3,4,0,7);ctx.fill(); // głowa, potargane włosy ctx.beginPath();ctx.ellipse(3,-79,12,13,0.1,0,7);ctx.fill();ctx.strokeStyle=SKD;ctx.lineWidth=1.5;ctx.stroke(); ctx.fillStyle='#2a2a1a';ctx.beginPath();ctx.moveTo(-9,-85);ctx.lineTo(-4,-94);ctx.lineTo(1,-88);ctx.lineTo(6,-95);ctx.lineTo(10,-87); ctx.lineTo(14,-83);ctx.quadraticCurveTo(3,-91,-9,-85);ctx.fill(); // jedno oko duże, drugie małe; zszyte usta ctx.fillStyle='#fff';ctx.beginPath();ctx.arc(9,-80,4,0,7);ctx.fill();ctx.beginPath();ctx.arc(1,-81,2.6,0,7);ctx.fill(); ctx.fillStyle='#c02020';ctx.beginPath();ctx.arc(10,-80,1.8,0,7);ctx.fill();ctx.beginPath();ctx.arc(1.5,-81,1.2,0,7);ctx.fill(); ctx.strokeStyle='#2a3a1a';ctx.lineWidth=1.6;ctx.beginPath();ctx.moveTo(1,-71);ctx.lineTo(12,-72);ctx.stroke(); for(let k=0;k<3;k++){ctx.beginPath();ctx.moveTo(3+k*4,-74);ctx.lineTo(3+k*4,-69);ctx.stroke();} ctx.restore(); } function hwBone(x,y,rot,s){ ctx.save();ctx.translate(x,y);ctx.rotate(rot);ctx.scale(s,s);ctx.fillStyle='#ece6d4';ctx.strokeStyle='#6a6252';ctx.lineWidth=1; ctx.fillRect(-10,-2.5,20,5); [[-10,-3],[-10,3],[10,-3],[10,3]].forEach(([a,b])=>{ctx.beginPath();ctx.arc(a,b,3.6,0,7);ctx.fill();}); ctx.restore(); } function hwSkel(x,y,dir,t,wind){ const sw=Math.sin(t*1.2),B='#ece6d4'; ctx.save();ctx.translate(x,y);ctx.scale(dir*1.15,1.15);ctx.lineCap='round';ctx.lineJoin='round';ctx.strokeStyle=B; ctx.lineWidth=4;ctx.beginPath();ctx.moveTo(0,-34);ctx.lineTo(-3-sw*8,-18);ctx.lineTo(-2-sw*10,-3); ctx.moveTo(0,-34);ctx.lineTo(3+sw*8,-18);ctx.lineTo(4+sw*10,-3);ctx.stroke(); ctx.fillStyle=B;ctx.beginPath();ctx.ellipse(0,-36,8,4,0,0,7);ctx.fill(); ctx.lineWidth=3;ctx.beginPath();ctx.moveTo(0,-36);ctx.lineTo(0,-67);ctx.stroke(); ctx.lineWidth=2.5;for(let k=0;k<4;k++){const yy=-63+k*6,w=10-k;ctx.beginPath();ctx.moveTo(-w,yy+2);ctx.quadraticCurveTo(0,yy-3,w,yy+2);ctx.stroke();} ctx.lineWidth=3.5;ctx.beginPath();ctx.moveTo(0,-65);ctx.lineTo(-10,-51);ctx.lineTo(-8,-39);ctx.stroke(); // ręka z kością: w zamachu nad głową const ex=wind?-4:10,ey=wind?-80:-58,hx=wind?-8:18,hy=wind?-95:-50; ctx.beginPath();ctx.moveTo(0,-65);ctx.lineTo(ex,ey);ctx.lineTo(hx,hy);ctx.stroke(); hwBone(hx,hy,wind?0.3:1.2,0.8); // czaszka ze świecącymi oczodołami ctx.fillStyle=B;ctx.beginPath();ctx.arc(2,-80,11,0,7);ctx.fill();ctx.fillRect(-3,-75,12,9); ctx.fillStyle='#14101c';ctx.beginPath();ctx.ellipse(-1,-81,3.2,3.8,0,0,7);ctx.fill();ctx.beginPath();ctx.ellipse(8,-81,3.2,3.8,0,0,7);ctx.fill(); ctx.fillStyle='#ff4a3a';ctx.fillRect(-1.6,-82,2,2);ctx.fillRect(7.4,-82,2,2); ctx.fillStyle='#14101c';ctx.beginPath();ctx.moveTo(3.5,-77);ctx.lineTo(1.5,-73.5);ctx.lineTo(5.5,-73.5);ctx.fill(); ctx.strokeStyle='#14101c';ctx.lineWidth=1;for(let k=0;k<4;k++){ctx.beginPath();ctx.moveTo(-1+k*3,-70);ctx.lineTo(-1+k*3,-67);ctx.stroke();} ctx.restore(); } function hwPumpMon(x,y,t,air){ const r=14*1.7,cy=y-8-r*0.85,l=air?6:Math.sin(t*2)*3; ctx.strokeStyle='#2a3a10';ctx.lineWidth=4;ctx.lineCap='round'; ctx.beginPath();ctx.moveTo(x-9,y-12);ctx.lineTo(x-13-l,y);ctx.moveTo(x+9,y-12);ctx.lineTo(x+13+l,y);ctx.stroke(); ctx.beginPath();ctx.moveTo(x-r*1.1,cy+2);ctx.quadraticCurveTo(x-r*1.6,cy-8-l*2,x-r*1.5,cy-18); ctx.moveTo(x+r*1.1,cy+2);ctx.quadraticCurveTo(x+r*1.6,cy-8-l*2,x+r*1.5,cy-18);ctx.stroke(); // ręce-pnącza hwPumpkin(x,y-8,1.7,true); ctx.strokeStyle='#4a1a04';ctx.lineWidth=3; ctx.beginPath();ctx.moveTo(x-r*0.72,cy-r*0.62);ctx.lineTo(x-r*0.2,cy-r*0.46);ctx.moveTo(x+r*0.72,cy-r*0.62);ctx.lineTo(x+r*0.2,cy-r*0.46);ctx.stroke(); } function hwSpider(x,y,dir,t){ ctx.save();ctx.translate(x,y);ctx.scale(dir*1.2,1.2);ctx.strokeStyle='#120a10';ctx.lineWidth=3;ctx.lineCap='round';ctx.lineJoin='round'; for(let k=0;k<4;k++){const a=Math.sin(t*1.6+k*1.3)*4; [-1,1].forEach(sd=>{ctx.beginPath();ctx.moveTo(sd*3,-16);ctx.lineTo(sd*(12+k*4),-28-k+a*sd);ctx.lineTo(sd*(18+k*5),0);ctx.stroke();});} ctx.fillStyle='#1a0e16';ctx.beginPath();ctx.ellipse(-6,-17,15,12,0,0,7);ctx.fill(); ctx.beginPath();ctx.ellipse(10,-15,8,7,0,0,7);ctx.fill(); ctx.fillStyle='#c0203a';ctx.beginPath();ctx.moveTo(-10,-24);ctx.lineTo(-2,-24);ctx.lineTo(-6,-17);ctx.closePath();ctx.fill(); ctx.beginPath();ctx.moveTo(-10,-10);ctx.lineTo(-2,-10);ctx.lineTo(-6,-17);ctx.closePath();ctx.fill(); ctx.fillStyle='#ff3a3a';[[12,-18],[16,-17],[13,-14],[17,-13]].forEach(([a,b])=>{ctx.beginPath();ctx.arc(a,b,1.6,0,7);ctx.fill();}); ctx.restore(); } function hwWitch(x,y,dir,t){ ctx.save();ctx.translate(x,y);ctx.scale(dir,1);ctx.lineCap='round';ctx.lineJoin='round'; ctx.fillStyle='#2a0a3a';ctx.beginPath();ctx.moveTo(-2,-24);ctx.quadraticCurveTo(-32,-14+Math.sin(t*2)*6,-42,-4+Math.sin(t*2.4)*4); ctx.lineTo(-6,4);ctx.closePath();ctx.fill(); // peleryna na wietrze ctx.strokeStyle='#7a4a1a';ctx.lineWidth=4;ctx.beginPath();ctx.moveTo(-40,8);ctx.lineTo(36,0);ctx.stroke(); ctx.fillStyle='#c8a04a';ctx.beginPath();ctx.moveTo(-36,8);ctx.lineTo(-60,-3);ctx.lineTo(-64,9);ctx.lineTo(-60,21);ctx.closePath();ctx.fill(); ctx.strokeStyle='#8a6a2a';ctx.lineWidth=1.2;for(let k=0;k<3;k++){ctx.beginPath();ctx.moveTo(-38,7);ctx.lineTo(-61,1+k*8);ctx.stroke();} ctx.fillStyle='#5a1a7a';ctx.beginPath();ctx.moveTo(-12,5);ctx.lineTo(-2,-25);ctx.lineTo(10,-25);ctx.lineTo(16,5);ctx.closePath();ctx.fill(); ctx.strokeStyle='#14101c';ctx.lineWidth=4;ctx.beginPath();ctx.moveTo(10,2);ctx.lineTo(16,14);ctx.stroke(); ctx.fillStyle='#14101c';ctx.beginPath();ctx.ellipse(19,15,6,3,0,0,7);ctx.fill(); ctx.strokeStyle='#7ad04a';ctx.lineWidth=3.5;ctx.beginPath();ctx.moveTo(6,-18);ctx.lineTo(20,-6);ctx.lineTo(24,1);ctx.stroke(); ctx.fillStyle='#ff8a2a';ctx.beginPath();ctx.moveTo(-1,-38);ctx.quadraticCurveTo(-12,-30,-8,-18);ctx.lineTo(-2,-26);ctx.closePath();ctx.fill(); ctx.fillStyle='#7ad04a';ctx.beginPath();ctx.arc(6,-33,9,0,7);ctx.fill(); ctx.beginPath();ctx.moveTo(13,-35);ctx.lineTo(22,-30);ctx.lineTo(13,-28);ctx.closePath();ctx.fill(); ctx.fillStyle='#14101c';ctx.beginPath();ctx.arc(10,-36,1.8,0,7);ctx.fill(); ctx.strokeStyle='#14101c';ctx.lineWidth=1.4;ctx.beginPath();ctx.moveTo(7,-28);ctx.lineTo(12,-27);ctx.stroke(); ctx.fillStyle='#14101c';ctx.beginPath();ctx.ellipse(5,-40,16,4,-0.08,0,7);ctx.fill(); ctx.beginPath();ctx.moveTo(-5,-41);ctx.lineTo(-10,-58);ctx.lineTo(-20,-66);ctx.lineTo(-6,-60);ctx.lineTo(14,-41);ctx.closePath();ctx.fill(); ctx.fillStyle='#b06bff';ctx.fillRect(-4,-46,17,3.5); ctx.restore(); } function hwDrawEnemy(e,now){ const x=e.x-hwCam;if(x<-90||x>W+90)return; const fly=e.k==='bat'||e.k==='witch'||e.drop; ctx.save();ctx.globalAlpha=fly?0.16:0.32;ctx.fillStyle='#000';ctx.beginPath();ctx.ellipse(x,HW_GROUND-2,fly?14:22,5,0,0,7);ctx.fill();ctx.restore(); const draw=()=>{const t=e.ph; if(e.k==='zombie')hwZombie(x,HW_GROUND,e.dir,t); else if(e.k==='skel')hwSkel(x,HW_GROUND,e.dir,t,now<e.stop); else if(e.k==='pump')hwPumpMon(x,HW_GROUND-e.jy,t,!!e.hop); else if(e.k==='bat')hwBatShape(x,e.y,1.9,Math.sin(frame*0.6)*5); else if(e.k==='ghost')hwGhostShape(x,440,1.8,t*0.8,hwGhostA(e,now)); else if(e.k==='spider'){if(e.drop){ctx.strokeStyle='rgba(220,220,240,0.6)';ctx.lineWidth=1;ctx.beginPath();ctx.moveTo(x,42);ctx.lineTo(x,e.y-22);ctx.stroke();} hwSpider(x,e.y,e.dir,e.drop?0:t*1.6);} else if(e.k==='witch')hwWitch(x,e.y,e.dir,t);}; draw(); if(now<e.flash){ctx.save();ctx.globalCompositeOperation='lighter';ctx.globalAlpha=0.7;draw();ctx.restore();} // błysk trafienia if(e.hp<e.max){const c=hwEnC(e),top=c.y-{zombie:64,skel:64,witch:80,ghost:52,pump:40,bat:30,spider:40}[e.k],bw=36; rr(x-bw/2,top,bw,6,3,'#2a1010',null);ctx.fillStyle='#ff5a3a';ctx.fillRect(x-bw/2+1,top+1,(bw-2)*e.hp/e.max,4);} } // 🚧 brama fali: kamienne słupy z dyniami, tabliczka; zamknięta = kraty, mgła i oczy w ciemności function hwDrawGates(){ for(const G of hwGates){const x=G.x-hwCam;if(x<-130||x>W+130)continue; const act=hwPhase==='wave'&&hwW&&hwW.G===G; if(!G.done){ctx.save(); for(let k=0;k<5;k++){ctx.globalAlpha=(act?0.22:0.14)+0.07*Math.sin(frame*0.05+k);ctx.fillStyle=k%2?'#8a4aff':'#4aff8a'; ctx.beginPath();ctx.ellipse(x+Math.sin(frame*0.03+k*1.7)*26,360+k*24,56+k*9,20,0,0,7);ctx.fill();} ctx.restore();} if(!G.done&&!act){ ctx.strokeStyle='#1a1424';ctx.lineWidth=3; for(let k=-3;k<=3;k++){const bx=x+k*12;ctx.beginPath();ctx.moveTo(bx,338);ctx.lineTo(bx,426);ctx.stroke(); ctx.fillStyle='#1a1424';ctx.beginPath();ctx.moveTo(bx-4,340);ctx.lineTo(bx,330);ctx.lineTo(bx+4,340);ctx.fill();} ctx.beginPath();ctx.moveTo(x-40,356);ctx.lineTo(x+40,356);ctx.moveTo(x-40,408);ctx.lineTo(x+40,408);ctx.stroke(); ctx.save();ctx.globalAlpha=0.6+0.4*Math.sin(frame*0.07);ctx.fillStyle='#ff3a3a'; // oczy za kratą [[-22,380],[14,372],[24,396]].forEach(([dx,y],i)=>{if(((frame>>5)+i)%4){ctx.fillRect(x+dx-5,y,3,3);ctx.fillRect(x+dx+2,y,3,3);}});ctx.restore();} else [-1,1].forEach(s=>{ctx.strokeStyle='#1a1424';ctx.lineWidth=3; // otwarte skrzydła bramy przy słupach for(let k=0;k<3;k++){const bx=x+s*(40-k*7);ctx.beginPath();ctx.moveTo(bx,340+k*3);ctx.lineTo(bx,424);ctx.stroke();}}); [-1,1].forEach(s=>{const px=x+s*52; rr(px-12,320,24,106,3,'#3a3448','#16121e',2);rr(px-16,312,32,12,3,'#4a4458','#16121e',2); ctx.strokeStyle='rgba(20,16,28,0.6)';ctx.lineWidth=1.5;for(let k=0;k<3;k++){ctx.beginPath();ctx.moveTo(px-12,348+k*26);ctx.lineTo(px+12,348+k*26);ctx.stroke();} hwPumpkin(px,312,0.8,true);}); ctx.strokeStyle='#14101c';ctx.lineWidth=4;ctx.beginPath();ctx.moveTo(x-52,330);ctx.quadraticCurveTo(x,292,x+52,330);ctx.stroke(); rr(x-48,272,96,26,6,G.done?'#14301a':'#2a0a14',G.done?'#7dff6b':'#ff5a5a',2); tx((G.done?'✅':'🧟')+' FALA '+G.n,x,285,13,G.done?'#9aff7a':'#ffb0a0','center',true); } } function hwShotPos(s,now){const p=cl((now-s.t0)/s.T,0,1); if(s.k==='potion')return{x:s.x0+(s.tx-s.x0)*p,y:s.y0+(HW_GROUND-s.y0)*p*p,p}; return{x:s.x0+(s.tx-s.x0)*p,y:s.y0+(HW_GROUND-s.y0)*p-Math.sin(p*Math.PI)*s.arc,p};} // pod mrówką: kałuże, ostrzeżenia, chodzące potwory function hwDrawWaveBack(now){ const V=hwW; for(const s of V.shots){ if(s.k==='puddle'){const a=cl((s.t0+s.T-now)/600,0,1);ctx.save();ctx.globalAlpha=0.75*a; ctx.fillStyle='#4ad04a';ctx.beginPath();ctx.ellipse(s.x-hwCam,HW_GROUND+14,s.r,11,0,0,7);ctx.fill();ctx.restore();continue;} if(now<s.t0-250)continue;const p=cl((now-s.t0)/s.T,0,1); ctx.save();ctx.globalAlpha=0.15+0.4*p;ctx.strokeStyle='#ff4a3a';ctx.fillStyle='rgba(255,60,40,0.25)';ctx.lineWidth=2; ctx.beginPath();ctx.ellipse(s.tx-hwCam,HW_GROUND+14,32,9,0,0,7);ctx.fill();ctx.stroke();ctx.restore();} for(const e of V.ens)if(e.k!=='bat'&&e.k!=='witch')hwDrawEnemy(e,now); } // nad mrówką: latające potwory, kości i eliksiry, cukierki mrówki function hwDrawWaveFront(now){ const V=hwW; for(const e of V.ens)if(e.k==='bat'||e.k==='witch')hwDrawEnemy(e,now); for(const s of V.shots){if(s.k==='puddle'||now<s.t0)continue;const q=hwShotPos(s,now),x=q.x-hwCam; if(s.k==='bone')hwBone(x,q.y,q.p*14,1.2); else{ctx.save();ctx.translate(x,q.y);ctx.rotate(q.p*9);ctx.fillStyle='#4ad04a';ctx.beginPath();ctx.arc(0,3,9,0,7);ctx.fill(); ctx.fillStyle='#c8e8ff';ctx.fillRect(-3,-12,6,8);ctx.fillStyle='#7a4a1a';ctx.fillRect(-4,-15,8,4);ctx.restore();}} for(const m of V.mine){const p=cl((now-m.t0)/m.T,0,1); hwCandyShape(m.x0+(m.tx-m.x0)*p-hwCam,m.y0+(m.ty-m.y0)*p-Math.sin(p*Math.PI)*50,m.col,p*14,1.1);} } function hwDrawWaveUI(now){ const V=hwW,left=V.q.length+V.ens.length,el=now-V.t0; ctx.save();ctx.globalAlpha=0.9;rr(W/2-280,46,560,66,12,'#120a1c','#7ac74f',2);ctx.restore(); tx('🧟 FALA '+V.G.n+'/'+HW_GPS+' · ulica '+V.G.st+' · zostało potworów: '+left,W/2,60,15,'#9aff7a','center',true); rr(W/2-260,72,520,18,7,'#102010','#7dff6b',1.5); ctx.fillStyle='#5ad04a';ctx.fillRect(W/2-258,74,516*(V.kills/V.total),14); tx(V.kills+' / '+V.total,W/2,81,11,'#fff','center',true); tx('Twoja tarcza:',W/2-58,101,12,'#ffd9a0','right',true); for(let k=0;k<5;k++){ctx.fillStyle=k<V.pips?'#ffd24a':'#3a2a2a';ctx.beginPath();ctx.arc(W/2-42+k*20,101,6.5,0,7);ctx.fill(); ctx.strokeStyle='#8a6a2a';ctx.lineWidth=1.2;ctx.stroke();} if(el<1800){ctx.save();const s=1+0.12*Math.sin(el*0.012);ctx.translate(W/2,215);ctx.scale(s,s);ctx.shadowColor='#7dff6b';ctx.shadowBlur=24; tx('🧟 FALA '+V.G.n+'!',0,0,54,'#9aff7a','center',true);ctx.restore(); tx(V.g===1?'Pokonaj potwory, żeby otworzyć bramę!':(V.fresh.length?'Nowe: '+V.fresh.map(k=>HW_EN[k].nm).join(', '):'Jeszcze mocniejsze potwory!'), W/2,265,17,'#fff','center',true);} else if(el<6000)tx('Dotknij potwora albo trzymaj 🍬 RZUCAJ · ◀ ▶ uciekaj!',W/2,130,15,'#fff','center',true); hwDrawArrows(); const rb=isOR(mouse.x,mouse.y,HB_K.x,HB_K.y,HB_K.w,HB_K.h); rr(HB_K.x,HB_K.y,HB_K.w,HB_K.h,18,now<V.cool?'#5a2a08':(rb?'#a85a10':'#7a3a08'),'#ffd24a',3); tx('🍬 RZUCAJ!',W/2,HB_K.y+HB_K.h/2,28,'#fff','center',true); } function hwWrap(txt,maxW){ ctx.font="15px 'Segoe UI'"; const words=(''+txt).split(' ');const out=[];let cur=''; for(const w of words){const t=cur?cur+' '+w:w; if(ctx.measureText(t).width>maxW&&cur){out.push(cur);cur=w;}else cur=t;} if(cur)out.push(cur);return out; } function hwDomy(n){return n===1?'dom':(n%10>=2&&n%10<=4&&(n%100<12||n%100>14))?'domy':'domów';} function hwHUD(){ ctx.save();ctx.globalAlpha=0.86;rr(0,0,W,42,0,'#120a1c',null);ctx.restore(); tx('🍬 '+hwCandy,14,21,20,'#ffd24a','left',true); let hs='';for(let i=0;i<3;i++)hs+=(i<hwHearts?'❤️':'🖤'); tx(hs,112,21,17,'#fff','left'); const k=hwKAt(hwPx),toB=(HW_PER-1)-(k%HW_PER),bh=hwHouses[k-(k%HW_PER)+HW_PER-1]; const G=hwGates.find(G=>!G.done&&G.st===hwStreet&&G.x>hwPx-80);let info; if(hwPhase==='wave'&&hwW)info='🧟 FALA '+hwW.G.n+'!'; else if(G){const c=hwHouses.filter(h=>h.x>hwPx+40&&h.x<G.x).length;info='🧟 fala '+G.n+(c?' za '+c+' '+hwDomy(c):' za bramą!');} else info=toB?'👹 boss za '+toB+' '+hwDomy(toB):(bh&&bh.done?'✅ ulica zaliczona':'👹 BOSS!'); tx('Ulica '+hwStreet+' · '+info,205,21,14,'#c9b0d0','left',true); if(hwStreak>0)tx('🔥×'+[1,1.2,1.4,1.6,2.0][Math.min(4,hwStreak)].toFixed(1),435,21,14,'#ff8a3a','left',true); if(hasBat())tx('🦇 ×2',505,21,14,'#b06bff','left',true); const m=hwMinsTo(24); tx('🕛 do północy '+hwFmtMins(m),W-108,21,13,m<30?'#ff6a5a':'#9a8ab0','right',true); const eb=isOR(mouse.x,mouse.y,W-96,8,86,26); rr(W-96,8,86,26,7,eb?'#3a2018':'#241410','#8a5a40',1.5);tx('◀ Menu',W-53,21,12,'#ffd9a0','center',true); } function hwEndScreen(title,col,l1,l2){ ctx.save();ctx.globalAlpha=0.88;ctx.fillStyle='#000';ctx.fillRect(0,0,W,H);ctx.restore(); tx(title,W/2,170,40,col,'center',true); tx(l1,W/2,232,18,'#fff','center'); tx(l2,W/2,268,15,'#c9b0d0','center'); tx('🍬 '+hwCandy,W/2,316,32,'#ffd24a','center',true); const b=isOR(mouse.x,mouse.y,W/2-140,380,280,66); rr(W/2-140,380,280,66,14,b?'#3a2a5a':'#22183a','#a86bd0',2.5); tx('◀ Do menu',W/2,413,20,'#fff','center',true); } function hwOver(){hwEndScreen('🏃 Uciekłeś do domu!','#ff9a5a','Odwaga się skończyła — mama mówi, że i tak jesteś bohaterem.','Wszystkie cukierki z tej nocy są bezpieczne w worku:');} function hwMidnight(){hwEndScreen('🕛 Północ!','#ffd24a','Światła gasną, ulica zasypia. Wróć jutro od 16:00.','Zebrane tej nocy (już w worku):');} function handleHWStreet(mx,my){ if(hwPhase==='over'||hwPhase==='midnight'){if(isOR(mx,my,W/2-140,380,280,66))gs='menu';return;} if(isOR(mx,my,W-96,8,86,26)){hwGoHome();return;} if(hwPhase==='chase'){hwChaseTap();return;} const onArrow=inR({x:mx,y:my},HB_L)||inR({x:mx,y:my},HB_R); // trzymanie ◀ ▶ obsługuje updHW if(hwPhase==='boss'){if(!onArrow)hwThrow();return;} if(hwPhase==='wave'){if(!onArrow){if(isOR(mx,my,HB_K.x,HB_K.y,HB_K.w,HB_K.h))hwWThrow();else hwWThrow(mx,my);}return;} if(hwPhase==='greet'){ const y=H-92,boss=hwHouses[hwIdx].t==='boss'; if(isOR(mx,my,W/2-320,y,300,64)){if(boss)hwBossStart();else hwChoose('treat');return;} if(isOR(mx,my,W/2+20,y,300,64)){if(boss)hwToWalk();else hwChoose('trick');return;} return;} if(hwPhase==='react'){const y=H-84; if(hwT>30&&isOR(mx,my,W/2-110,y,220,54))hwToWalk(); // pół sekundy przerwy: szybkie stukanie w bossa nie przeklika wyniku return;} if(hwPhase==='walk'){ if(onArrow)return; const near=hwNearHouse(); if(near>=0&&isOR(mx,my,HB_K.x,HB_K.y,HB_K.w,HB_K.h)){hwKnockAt(near);return;} // dotknięcie domu → mrówka sama do niego idzie i puka; dotknięcie chodnika → idzie w to miejsce for(let i=0;i<hwHouses.length;i++){const h=hwHouses[i],x=h.x-hwCam,hw=h.t==='boss'?125:(h.s.w/2+20),top=hwHouseTop(h); if(!h.done&&isOR(mx,my,x-hw,top,hw*2,420-top)){if(Math.abs(hwPx-h.x)<60)hwKnockAt(i);else{hwTarget=h.x;hwAuto=i;}return;}} if(my>50){hwTarget=Math.max(60,mx+hwCam);hwAuto=-1;} } } // ══════════════════════════════════════════════════════════════════ // 📦 SKRZYNIE + ANIMACJA // ══════════════════════════════════════════════════════════════════ let openAnim=null; // {crate,item,t,phase} function rollCrate(cr){ // system LITOŚCI: co 8. Trumna bez mit/kosmos → gwarantowana Kosa (lub Nietoperz) if(cr.id==='c3'||cr.id==='c4'){pity++; const _need=cr.id==='c4'?5:8; if(pity>=_need){pity=0;hwSave();return have('kosa')?'nietoperz':'kosa';}} let r=Math.random()*100; for(const [id,ch] of cr.drops){r-=ch;if(r<=0)return id;} return cr.drops[0][0]; } function openCrate(cr){ if(candy<cr.cost){msg('❌ Za mało cukierków — potrzeba '+cr.cost+' 🍬');return;} candy-=cr.cost; const id=rollCrate(cr), it=ITEMS[id]; let dupCandy=0; if(id.indexOf('candy')===0){ // paczka cukierków const amt=id==='candy100'?100:id==='candy250'?250:id==='candy1500'?1500:600; candy+=amt; } else if(have(id)&&it.kind!=='zapas'){ // duplikat → cukierki dupCandy=RAR[it.rar].dup; candy+=dupCandy; give(id,1); } else give(id,1); if(id==='kosa')equipScythe(true); // Kosa od razu gotowa do gry z kolegami hwSave(); openAnim={crate:cr,item:id,dup:dupCandy,t:0}; sndBig(); } function drawCrates(){ bgHW(); tx('📦 SKRZYNIE HALLOWEEN',W/2,52,34,'#ffd24a','center',true); tx('Limitowane — tylko na czas eventu. Duplikaty zamieniają się w cukierki.',W/2,86,13,'#c9a0d0','center'); tx('🍬 '+candy,W/2,116,22,'#ffd24a','center',true); CRATES.forEach((cr,i)=>{ const {x,y,w:cw,h:ch}=crateRect(i); const can=candy>=cr.cost, hov=isOR(mouse.x,mouse.y,x,y,cw,ch); ctx.save();if(hov&&can){ctx.shadowColor=cr.col;ctx.shadowBlur=20;} rr(x,y,cw,ch,16,can?'rgba(30,16,40,0.96)':'rgba(20,14,26,0.9)',can?cr.col:'#3a2a3a',can?2.4:1.4); ctx.restore(); ctx.save();ctx.font='62px serif';ctx.textAlign='center';ctx.textBaseline='middle'; ctx.shadowColor=cr.col;ctx.shadowBlur=16;ctx.fillText(cr.ic,x+cw/2,y+70+Math.sin(frame*0.05+i)*3);ctx.restore(); tx('poz. '+(i+1),x+cw/2,y+118,12,'#9a8ab0','center'); const nm=hwWrap(cr.n,cw-30); nm.forEach((ln,k)=>tx(ln,x+cw/2,y+142+k*20,15,can?'#fff':'#7a6a8a','center',true)); // top dropy let yy=y+195; tx('Najlepsze losy:',x+cw/2,yy-14,10,'#8a7a9a','center'); cr.drops.filter(d=>['epicki','legend','mit','kosmos'].indexOf(ITEMS[d[0]].rar)>=0) .slice(0,4).forEach(d=>{const it=ITEMS[d[0]]; tx(it.ic+' '+it.n,x+14,yy,10.5,RAR[it.rar].c,'left'); tx(d[1]+'%',x+cw-14,yy,10.5,'#c9b0d0','right');yy+=16;}); rr(x+16,y+ch-52,cw-32,38,10,can?'#7a3a08':'#2a2028',can?'#ff9a3a':'#4a3a4a',2); tx(can?('OTWÓRZ · '+cr.cost+' 🍬'):(cr.cost+' 🍬'),x+cw/2,y+ch-33,15,can?'#fff':'#7a6a8a','center',true); }); {const p=CRATES[2]; tx('⚰️ Litość: co 8. Trumna bez trafienia daje PEWNĄ Kosę (masz '+pity+'/8)',W/2,H-72,12,'#ff8a6a','center');} backBtn(); if(openAnim)drawOpen(); } function drawOpen(){ const a=openAnim, it=ITEMS[a.item], rc=RAR[it.rar].c; a.t++; ctx.save();ctx.globalAlpha=0.9;ctx.fillStyle='#000';ctx.fillRect(0,0,W,H);ctx.restore(); const cx=W/2, cy=H/2-20; if(a.t<50){ // faza 1: trzęsienie const sh=Math.sin(a.t*0.9)*(a.t/6); ctx.save();ctx.translate(cx+sh,cy);ctx.font='110px serif';ctx.textAlign='center';ctx.textBaseline='middle'; ctx.shadowColor=a.crate.col;ctx.shadowBlur=20+a.t;ctx.fillText(a.crate.ic,0,0);ctx.restore(); tx('otwieranie…',cx,cy+110,18,'#c9a0d0','center'); } else if(a.t<70){ // faza 2: błysk const p=(a.t-50)/20; ctx.save();ctx.globalAlpha=1-p*0.3; const g=ctx.createRadialGradient(cx,cy,10,cx,cy,300*p+40); g.addColorStop(0,'#fff');g.addColorStop(0.4,rc);g.addColorStop(1,'rgba(0,0,0,0)'); ctx.fillStyle=g;ctx.fillRect(0,0,W,H);ctx.restore(); } else { // faza 3: ujawnienie const p=cl((a.t-70)/16,0,1); ctx.save();ctx.translate(cx,cy);ctx.scale(0.6+p*0.4,0.6+p*0.4);ctx.globalAlpha=p; ctx.shadowColor=rc;ctx.shadowBlur=34; rr(-190,-130,380,260,20,'#150c22',rc,3); ctx.restore(); ctx.save();ctx.globalAlpha=p;ctx.font='84px serif';ctx.textAlign='center';ctx.textBaseline='middle'; ctx.shadowColor=rc;ctx.shadowBlur=26;ctx.fillText(it.ic,cx,cy-42);ctx.restore(); ctx.globalAlpha=1; tx(RAR[it.rar].n.toUpperCase(),cx,cy+22,15,rc,'center',true); tx(it.n,cx,cy+52,21,'#fff','center',true); hwWrap(it.d,340).forEach((ln,i)=>tx(ln,cx,cy+82+i*18,12,'#c9b0d0','center')); if(a.dup>0)tx('duplikat → +'+a.dup+' 🍬',cx,cy+128,14,'#ffd24a','center',true); if(a.item==='kosa')tx('⚔️ Załadowana do „Gra z Kolegami"!',cx,cy+150,13,'#ff6a5a','center',true); const b=isOR(mouse.x,mouse.y,cx-110,cy+170,220,50); rr(cx-110,cy+170,220,50,12,b?'#3a2a5a':'#22183a',rc,2); tx('OK ▶',cx,cy+195,19,'#fff','center',true); if(a.t%4===0&&a.t<200)hwPart(cx+(Math.random()-0.5)*300,cy+120,rc,1); } for(const p of hwParts){ctx.globalAlpha=cl(p.l/40,0,1);ctx.fillStyle=p.col;ctx.fillRect(p.x-2,p.y-2,4,4);} ctx.globalAlpha=1; for(let i=hwParts.length-1;i>=0;i--){const p=hwParts[i];p.x+=p.vx;p.y+=p.vy;p.vy+=0.1;if(--p.l<=0)hwParts.splice(i,1);} } function handleCrates(mx,my){ if(openAnim){ if(openAnim.t>70&&isOR(mx,my,W/2-110,H/2-20+170,220,50))openAnim=null; return; } if(backHit(mx,my))return; CRATES.forEach((cr,i)=>{const R=crateRect(i); if(isOR(mx,my,R.x,R.y,R.w,R.h))openCrate(cr);}); } // ten sam prostokąt do rysowania i klikania (wcześniej klik liczył 3 skrzynie po 270 px, a rysowane były 4 węższe) function crateRect(i){const n=CRATES.length,gap=16,cw=Math.min(270,(W-(n+1)*gap)/n); return{x:(W-(n*cw+(n-1)*gap))/2+i*(cw+gap),y:150,w:cw,h:340};} // ══════════════════════════════════════════════════════════════════ // 🛒 SKLEP // ══════════════════════════════════════════════════════════════════ function shopRect(i){const cw=270,gap=18,c=i%3,r=(i/3|0);return{x:(W-(3*cw+2*gap))/2+c*(cw+gap),y:170+r*175,w:cw,h:158};} function drawShop(){ bgHW(); tx('🛒 SKLEP HALLOWEEN',W/2,52,34,'#ffd24a','center',true); tx('LIMITOWANE — znika po evencie. Skiny kupujesz pewnie, bez losowania.',W/2,86,13,'#c9a0d0','center'); tx('🍬 '+candy,W/2,116,22,'#ffd24a','center',true); SHOP.forEach(([id,price],i)=>{ const it=ITEMS[id],R=shopRect(i),rc=RAR[it.rar].c; const mine=have(id), can=!mine&&candy>=price, hov=isOR(mouse.x,mouse.y,R.x,R.y,R.w,R.h); ctx.save();if(hov&&can){ctx.shadowColor=rc;ctx.shadowBlur=16;} rr(R.x,R.y,R.w,R.h,14,mine?'rgba(20,40,20,0.95)':'rgba(28,16,38,0.95)',mine?'#7dff6b':(can?rc:'#3a2a3a'),2); ctx.restore(); ctx.save();ctx.font='40px serif';ctx.textAlign='left';ctx.textBaseline='middle'; ctx.shadowColor=rc;ctx.shadowBlur=10;ctx.fillText(it.ic,R.x+16,R.y+40);ctx.restore(); tx(it.n,R.x+68,R.y+30,14,'#fff','left',true); tx(RAR[it.rar].n,R.x+68,R.y+50,11,rc,'left',true); hwWrap(it.d,R.w-30).slice(0,2).forEach((ln,k)=>tx(ln,R.x+14,R.y+78+k*16,10.5,'#c9b0d0','left')); rr(R.x+14,R.y+R.h-40,R.w-28,30,8,mine?'#1a4a1a':(can?'#7a3a08':'#2a2028'),mine?'#7dff6b':(can?'#ff9a3a':'#4a3a4a'),1.8); tx(mine?'✅ MASZ':(price+' 🍬'),R.x+R.w/2,R.y+R.h-25,13,mine?'#bfffb0':(can?'#fff':'#7a6a8a'),'center',true); }); backBtn(); } function handleShop(mx,my){ if(backHit(mx,my))return; SHOP.forEach(([id,price],i)=>{const R=shopRect(i); if(isOR(mx,my,R.x,R.y,R.w,R.h)){ if(have(id)){msg('✅ Już to masz!');return;} if(candy<price){msg('❌ Brakuje '+(price-candy)+' 🍬');return;} candy-=price;give(id,1); if(id==='kosa')equipScythe(true); if(ITEMS[id].kind==='skin'){try{const s=JSON.parse(localStorage.getItem('md_hwSkins')||'[]'); if(s.indexOf(id)<0){s.push(id);localStorage.setItem('md_hwSkins',JSON.stringify(s));}}catch(e){}} hwSave();sndBig();msg('🎉 Kupiono: '+ITEMS[id].n+'!'); }}); } // ══════════════════════════════════════════════════════════════════ // MENU + WSPÓLNE // ══════════════════════════════════════════════════════════════════ let msgT=0,msgTxt=''; function msg(t){msgTxt=t;msgT=180;} function bgHW(){ const g=ctx.createLinearGradient(0,0,0,H);g.addColorStop(0,'#150a22');g.addColorStop(1,'#0a0610'); ctx.fillStyle=g;ctx.fillRect(0,0,W,H); for(let i=0;i<30;i++){const sx=(i*173+41)%W,sy=(i*89+frame*0.15)%H; ctx.globalAlpha=0.18;ctx.font='16px serif';ctx.textAlign='center'; ctx.fillText(['🎃','🦇','👻','🕸️'][i%4],sx,sy);} ctx.globalAlpha=1; } function backBtn(){const b=isOR(mouse.x,mouse.y,16,H-52,150,36); rr(16,H-52,150,36,10,b?'#3a2018':'#241410','#8a5a40',1.8);tx('◀ Wróć',91,H-34,15,'#ffd9a0','center',true);} function backHit(mx,my){if(isOR(mx,my,16,H-52,150,36)){gs='menu';return true;}return false;} function drawMenu(){ bgHW(); ctx.save();ctx.shadowColor='#ff8a2a';ctx.shadowBlur=26; tx('🎃 MRÓWCZE HALLOWEEN 🎃',W/2,74,42,'#ffb04a','center',true);ctx.restore(); tx('EVENT LIMITOWANY — skiny, skrzynie i Kosa tylko teraz!',W/2,116,15,'#c9a0d0','center'); tx('🍬 '+candy+' cukierków 💰 '+getCoins()+' monet',W/2,150,19,'#ffd24a','center',true); const open=hwOpenNow(); const B=[ ['street','🎃 CUKIEREK ALBO PSIKUS',open?'Co 4 domy fala potworów, na końcu ulicy BOSS · do północy '+hwFmtMins(hwMinsTo(24)) :'🌙 Ulica otwarta 16:00–24:00 — otwiera się za '+hwFmtMins(hwMinsTo(HW_OPEN_H)),open?'#ff8a2a':'#5a4a6a'], ['crates','📦 SKRZYNIE','4 skrzynie · Kosa, Nietoperz, rzadkości','#a86bd0'], ['shop','🛒 SKLEP','Limitowane skiny za cukierki','#7dff6b'], ]; B.forEach((b,i)=>{const bw=700,x=W/2-bw/2,y=200+i*96,bh=80; const hov=isOR(mouse.x,mouse.y,x,y,bw,bh); ctx.save();if(hov){ctx.shadowColor=b[3];ctx.shadowBlur=18;} rr(x,y,bw,bh,16,hov?'rgba(40,22,52,0.96)':'rgba(26,14,34,0.92)',b[3],2.4);ctx.restore(); tx(b[1],x+28,y+30,24,'#fff','left',true); tx(b[2],x+28,y+58,13,'#c9b0d0','left');}); // posiadane let ow=Object.keys(owned).filter(k=>owned[k]>0); tx('Twoja kolekcja: '+(ow.length?ow.map(k=>ITEMS[k]?ITEMS[k].ic:'').join(' '):'jeszcze pusto — otwórz skrzynię!'),W/2,510,15,'#c9b0d0','center'); if(have('kosa'))tx('⚰️ KOSA aktywna w „Gra z Kolegami" — ×2 obrażenia + oślepienie',W/2,540,13,'#ff6a5a','center',true); if(hasBat())tx('🦇 Nietoperz: ×2 cukierki i monety',W/2,562,13,'#b06bff','center',true); const hb=isOR(mouse.x,mouse.y,W/2-150,H-50,300,34); rr(W/2-150,H-50,300,34,10,hb?'#2a2018':'#1a130c','#8a7550',1.8); tx('◀ Wróć do Mrówczego Dungeonu',W/2,H-33,13,'#d8c8a0','center',true); } function handleMenu(mx,my){ if(isOR(mx,my,W/2-150,H-50,300,34)){try{window.parent.gameClose();}catch(e){}return;} const B=['street','crates','shop']; B.forEach((id,i)=>{const bw=700,x=W/2-bw/2,y=200+i*96; if(isOR(mx,my,x,y,bw,80)){ if(id==='street')hwStart(); else gs=id; }}); } // ── PĘTLA ───────────────────────────────────────────────────────── function update(){ frame++; if(msgT>0)msgT--; while(keyq.length){const k=keyq.shift(); if(k==='Escape'){if(gs==='street')hwGoHome();else gs='menu';} if(gs==='street'){ if(k===' '){ if(hwPhase==='walk')hwKnock(); else if(hwPhase==='chase')hwChaseTap(); else if(hwPhase==='boss')hwThrow(); else if(hwPhase==='wave')hwWThrow(); else if(hwPhase==='react'&&hwT>30)hwToWalk(); } }} while(clicks.length){const c=clicks.shift(); if(gs==='menu')handleMenu(c.x,c.y); else if(gs==='street')handleHWStreet(c.x,c.y); else if(gs==='crates')handleCrates(c.x,c.y); else if(gs==='shop')handleShop(c.x,c.y);} if(gs==='street')updHW(); if(gs==='street'&&hwIdx>=0&&hwPhase!=='walk'){const h=hwHouses[hwIdx];if(h.open<40)h.open+=3;} } function draw(){ if(gs==='menu')drawMenu(); else if(gs==='street')drawHWStreet(); else if(gs==='crates')drawCrates(); else if(gs==='shop')drawShop(); if(msgT>0){ctx.save();ctx.globalAlpha=0.95; const mw=Math.min(700,msgTxt.length*9+40); rr(W/2-mw/2,H-104,mw,34,10,'#1a1030','#ff9a3a',2);ctx.restore(); tx(msgTxt,W/2,H-87,14,'#ffd9a0','center',true);} } function loop(){update();draw();requestAnimationFrame(loop);} hwLoad(); requestAnimationFrame(loop); </script> </body> </html>
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>🛒 Mrówczy Rynek</title> <style> *{box-sizing:border-box;-webkit-tap-highlight-color:transparent} html,body{margin:0;height:100%} body{background:radial-gradient(circle at 50% -10%,#1a1428,#0a0810 60%);color:#e8e0f0; font:14px/1.4 "Segoe UI",system-ui,sans-serif;overflow-x:hidden;padding-bottom:70px} .wrap{max-width:660px;margin:0 auto;padding:10px} h1{margin:6px 0 2px;text-align:center;font-size:24px;color:#ffd24a;text-shadow:0 0 18px #a066ff66} .sub{text-align:center;color:#9a86c0;font-size:11px;margin-bottom:8px} .res{position:sticky;top:0;z-index:20;display:flex;gap:8px;justify-content:center;flex-wrap:wrap; background:rgba(12,8,18,.95);padding:8px;border:1.5px solid #4a3a6e;border-radius:12px;margin-bottom:10px;backdrop-filter:blur(4px)} .chip{background:#1c1430;border:1px solid #4a3a6e;border-radius:10px;padding:6px 12px;font-weight:700;font-size:15px} .chip small{display:block;font-weight:400;font-size:9px;color:#9a86c0} .c-coin{color:#ffd24a}.c-bam{color:#5ad040}.c-gem{color:#7fd0ff} .tabs{display:flex;gap:6px;justify-content:center;flex-wrap:wrap;margin:6px 0} .tab{background:#1c1430;border:1px solid #4a3a6e;padding:8px 16px;border-radius:10px;font-weight:700;font-size:13px;cursor:pointer} .tab.on{background:#6a3aa0;border-color:#c088ff;box-shadow:0 0 12px #a066ff55} .cats{display:flex;gap:5px;justify-content:center;flex-wrap:wrap;margin:8px 0 4px} .cat{background:#160f26;border:1px solid #3a2e56;padding:5px 11px;border-radius:9px;font-size:12px;cursor:pointer} .cat.on{background:#2a6a9a;border-color:#7fd0ff} .sortbar{display:flex;gap:6px;justify-content:center;margin:4px 0 10px;font-size:12px} .sortbar button{padding:5px 10px;background:#160f26;border:1px solid #3a2e56;border-radius:8px;color:#cdbce8;font:inherit;cursor:pointer} .sortbar button.on{background:#2a6a9a;border-color:#7fd0ff;color:#fff} .grid{display:grid;grid-template-columns:1fr 1fr;gap:8px} @media(max-width:520px){.grid{grid-template-columns:1fr}} .card{background:#150f24;border:1px solid #3a2e56;border-radius:12px;padding:10px;display:flex;gap:10px;align-items:center} .card .ci{font-size:30px;filter:drop-shadow(0 2px 2px #000a);min-width:34px;text-align:center} .card .cb{flex:1;min-width:0} .card .cn{font-weight:700;font-size:14px} .card .cd{font-size:10.5px;color:#a99bc8;margin:2px 0 6px} .card .own{font-size:10px;color:#ffd24a;font-weight:700} button{font:inherit;cursor:pointer;border:none;border-radius:9px;padding:8px 12px;font-weight:700;color:#fff;background:#2a2040;transition:transform .05s,filter .1s} button:hover{filter:brightness(1.15)}button:active{transform:translateY(1px)} button:disabled{opacity:.4;cursor:not-allowed;filter:none} .b-buy{background:linear-gradient(#3a8a2a,#256018)}.b-sell{background:linear-gradient(#c89a1e,#8a6a10)} .b-list{background:linear-gradient(#6a3aa0,#402060)} .empty{text-align:center;color:#8a7ab0;padding:20px;font-size:13px} .deal{position:relative} .deal .tag{position:absolute;top:-7px;right:8px;font-size:9px;font-weight:800;padding:2px 7px;border-radius:8px} .tag.cheap{background:#2a7a2a;color:#bfffbf}.tag.pricey{background:#7a2a2a;color:#ffbfbf} .seller{font-size:9.5px;color:#8a7ab0} .msg{position:fixed;left:50%;bottom:14px;transform:translateX(-50%);background:#1c1430;border:1.5px solid #c088ff;padding:10px 18px;border-radius:12px;font-weight:700;z-index:50;box-shadow:0 6px 24px #000a;opacity:0;transition:opacity .2s;pointer-events:none;max-width:90vw;text-align:center} .msg.show{opacity:1} .back{position:fixed;top:10px;left:10px;z-index:30;background:#241630;border:1px solid #5a3a7a;font-size:12px;padding:7px 12px;border-radius:9px} .foot{text-align:center;color:#6a5a80;font-size:10px;margin:16px 0 6px} .wallet-note{text-align:center;color:#7fd0ff;font-size:10px;margin-bottom:6px} </style> <script> /* 🔒 Utrudnienie podglądu kodu — ZNIECHĘCA przypadkowego podglądacza (w HTML 100% ochrony kodu nie ma) */ (function(){ document.addEventListener('contextmenu',function(e){e.preventDefault();}); document.addEventListener('keydown',function(e){var k=(e.key||'').toLowerCase(); if(e.key==='F12'||(e.ctrlKey&&e.shiftKey&&(k==='i'||k==='j'||k==='c'))||(e.ctrlKey&&k==='u')){e.preventDefault();return false;}}); })(); </script> </head> <body> <button class="back" onclick="parent.gameClose()">← Menu główne</button> <div class="wrap"> <h1>🛒 Mrówczy Rynek</h1> <div class="sub">Wspólna kasa ze wszystkich gier • kupuj bronie, zbroje, mury, apteczki</div> <div class="res"> <div class="chip c-coin" id="rCoin">💰 0<small>monety (wspólne)</small></div> <div class="chip c-bam" id="rBam">🎋 0<small>bambusy</small></div> <div class="chip c-gem" id="rGem">💎 0<small>klejnoty</small></div> </div> <div class="wallet-note">💡 To ta sama kasa co w Mrówczym Dungeonie — zarabiasz w grze, wydajesz tutaj.</div> <div class="tabs" id="tabs"></div> <div class="cats" id="cats"></div> <div class="sortbar" id="sortbar"></div> <div class="grid" id="list"></div> <div class="foot">Kupione rzeczy lądują w 🎒 Plecaku. Będą używane w trybie Arena 1v1 (wkrótce).</div> </div> <div class="msg" id="msg"></div> <script> "use strict"; // ═══════════ KATALOG ═══════════ // cat: bron | zbroja | budowla | apteczka | bambus | skrzynka // cost = monety, bam = bambusy (opcjonalnie). ord = im wyższe, tym "nowsze". const ITEMS=[ // 🔫 BRONIE — od najsłabszej do najlepszej (można łączyć w kowadle w Arenie) {id:'pistol', n:'Pistolet', ic:'🔫', cat:'bron', cost:500, ord:0, desc:'Podstawowa broń — pojedyncze strzały'}, {id:'rifle', n:'Karabin', ic:'🎯', cat:'bron', cost:1500, ord:1, desc:'Szybkostrzelny — grad kul'}, {id:'freeze', n:'Zamrażacz', ic:'❄️', cat:'bron', cost:4000, ord:2, desc:'Co 3. trafienie mrozi wroga na 10 s'}, {id:'poison', n:'Truciciel', ic:'☠️', cat:'bron', cost:9000, ord:3, desc:'Zatruwa — wróg traci HP przez czas'}, {id:'rpg', n:'RPG', ic:'🚀', cat:'bron', cost:20000, ord:4, desc:'Rakieta — wybuch obszarowy'}, {id:'minigun',n:'Minigun', ic:'🔥', cat:'bron', cost:50000, ord:5, desc:'Lawina pocisków — kosi wszystko'}, // 🛡️ ZBROJE (można zaklinać: unik itd.) {id:'arm1', n:'Lekka Zbroja', ic:'🥋', cat:'zbroja', cost:800, ord:0, desc:'-10% obrażeń, lekka i szybka'}, {id:'arm2', n:'Kolczuga', ic:'🛡️', cat:'zbroja', cost:2500, ord:1, desc:'-22% obrażeń'}, {id:'arm3', n:'Pełna Płyta', ic:'⚙️', cat:'zbroja', cost:7000, ord:2, desc:'-35% obrażeń, ciężka'}, // 🧱 BUDOWLE — do Areny 1v1 {id:'wall', n:'Mur', ic:'🧱', cat:'budowla', cost:100, ord:0, desc:'Postaw ścianę — blokuje kule'}, {id:'wall2', n:'Wzmocniony Mur',ic:'🧱', cat:'budowla', cost:400, ord:1, desc:'Mur, który wytrzymuje więcej'}, {id:'bush', n:'Krzak', ic:'🌿', cat:'budowla', cost:150, ord:2, desc:'Schowaj się — przeciwnik Cię nie widzi'}, // ❤️ APTECZKI {id:'med1', n:'Mała Apteczka', ic:'❤️', cat:'apteczka', cost:200, ord:0, desc:'+30 HP w walce'}, {id:'med2', n:'Duża Apteczka', ic:'💊', cat:'apteczka', cost:600, ord:1, desc:'+80 HP w walce'}, // 🎋 SUROWCE {id:'bamboo',n:'Bambus', ic:'🎋', cat:'bambus', cost:60, ord:0, desc:'Surowiec — sprzedawaj drożej na giełdzie', giveBam:1}, // 🆕 WIĘCEJ PRZEDMIOTÓW {id:'shotgun',n:'Obrzyn', ic:'🔫', cat:'bron', cost:3000, ord:6, desc:'Rozrzut śrutu — morderczy z bliska'}, {id:'nade', n:'Granatnik', ic:'💣', cat:'bron', cost:15000, ord:7, desc:'Wystrzeliwuje granaty — obszarowo'}, {id:'arm4', n:'Tarcza Mocy', ic:'🔰', cat:'zbroja', cost:15000, ord:3, desc:'-45% obrażeń + powolna regeneracja'}, {id:'turret', n:'Wieżyczka', ic:'🔩', cat:'budowla', cost:2000, ord:3, desc:'Automatyczna wieża strzela do wroga'}, {id:'mine', n:'Mina', ic:'💥', cat:'budowla', cost:300, ord:4, desc:'Wybucha, gdy wróg nadepnie'}, {id:'boost', n:'Zastrzyk Siły',ic:'💉',cat:'apteczka', cost:900, ord:2, desc:'+50% obrażeń na krótko'}, // 📦 SKRZYNKI {id:'crate1',n:'Skrzynka Wojenna',ic:'📦',cat:'skrzynka', cost:1500, ord:0, desc:'Losowa broń/zbroja/kasa', tier:1}, {id:'crate2',n:'Skrzynka Elitarna',ic:'💠',cat:'skrzynka', cost:8000, ord:1, desc:'Lepsze losowanie — rzadkie rzeczy', tier:2}, ]; const CATS=[['bron','🔫 Bronie'],['zbroja','🛡️ Zbroje'],['budowla','🧱 Budowle'],['apteczka','❤️ Apteczki'],['bambus','🎋 Bambus'],['skrzynka','📦 Skrzynki']]; const NICKS=['mrówkagejming','xXProKopaczXx','mrufka123','BossMrówka','anarchia_gg','ziomek_bambus','KrólowaMatka','SzybkiBóbr','ognisty_lis','ktoś_z_lasu','turbo_mrówka','mrówkagejming']; // ═══════════ WSPÓLNA KASA (te same klucze co gra główna!) ═══════════ function getCoins(){return parseInt(localStorage.getItem('md_coins_saved')||'0')||0;} function setCoins(v){try{localStorage.setItem('md_coins_saved',Math.max(0,Math.floor(v)));}catch(e){}} function getGems(){return parseInt(localStorage.getItem('md_gems')||'0')||0;} function getBam(){return parseInt(localStorage.getItem('rynek_bambus')||'0')||0;} function setBam(v){try{localStorage.setItem('rynek_bambus',Math.max(0,Math.floor(v)));}catch(e){}} function loadBag(){try{return JSON.parse(localStorage.getItem('rynek_plecak')||'{}')||{};}catch(e){return {};}} function saveBag(b){try{localStorage.setItem('rynek_plecak',JSON.stringify(b));}catch(e){}} let bag=loadBag(); function itemById(id){return ITEMS.find(x=>x.id===id);} // ═══════════ TWOJE OFERTY — wystaw za DOWOLNĄ cenę (rynek decyduje czy ktoś kupi) ═══════════ function loadListings(){try{return JSON.parse(localStorage.getItem('rynek_listings')||'[]')||[];}catch(e){return [];}} function saveListings(){try{localStorage.setItem('rynek_listings',JSON.stringify(listings));}catch(e){}} let listings=loadListings(), _offlineSold=null; // szansa na sprzedaż w jednej "próbie": tania rzecz schodzi szybko, przepłacona prawie nigdy function sellChance(price,value){var r=price/Math.max(1,value); if(r>3)return 0; // nikt nie przepłaci >3× wartości — koniec exploita "ustaw 10 mln" return Math.max(0.008,Math.min(0.55,0.28/Math.pow(Math.max(0.5,r),2.6)));} // niższe = schodzi wolniej, w losowych momentach function listItem(id){ var it=itemById(id);if(!it||!bag[id])return; var inp=document.getElementById('price-'+id), price=inp?Math.floor(+inp.value):0; if(!price||price<1){toast('Podaj cenę większą od 0 💰');return;} bag[id]--;if(bag[id]<=0)delete bag[id];saveBag(bag); listings.push({id:id,price:price,value:it.cost});saveListings(); var r=price/it.cost; toast('📤 Wystawiono '+it.ic+' '+it.n+' za 💰'+fmt(price)+(r>1.8?' — drogo, może wisieć!':r<0.9?' — tanio, pójdzie szybko!':'')); render(); } function cancelListing(i){ var l=listings[i];if(!l)return; bag[l.id]=(bag[l.id]||0)+1;saveBag(bag); listings.splice(i,1);saveListings(); toast('↩️ Zdjęto ofertę — rzecz wróciła do plecaka');render(); } function processListings(rounds){ var sold=[]; for(var t=0;t<rounds;t++)for(var i=listings.length-1;i>=0;i--){var l=listings[i]; if(Math.random()<sellChance(l.price,l.value)){setCoins(getCoins()+l.price);var it=itemById(l.id); sold.push((it?it.ic+' '+it.n:l.id)+' → 💰'+fmt(l.price));listings.splice(i,1);}} if(sold.length){saveListings();return sold;} return null; } function offlineSells(){ var last=parseInt(localStorage.getItem('rynek_listing_ts')||'0')||0, now=Date.now(); if(last&&listings.length){var rounds=Math.min(120,Math.floor((now-last)/3000));if(rounds>0){var m=processListings(rounds);if(m&&m.length)_offlineSold=m;}} try{localStorage.setItem('rynek_listing_ts',now);}catch(e){} } // ═══════════ AKCJE ═══════════ function buy(id,priceOverride){ const it=itemById(id);const price=priceOverride!=null?priceOverride:it.cost; if(getCoins()<price){toast('❌ Za mało monet (potrzeba 💰'+fmt(price)+')');return;} setCoins(getCoins()-price); if(it.giveBam){setBam(getBam()+it.giveBam);toast('🎋 Kupiono Bambus! (masz '+getBam()+')');} else if(it.cat==='skrzynka'){openCrate(it);} else{bag[id]=(bag[id]||0)+1;saveBag(bag);toast('✅ Kupiono: '+it.ic+' '+it.n+' → do plecaka');} render(); } function sell(id){ if(!bag[id]){return;} const it=itemById(id);const refund=Math.round(it.cost*0.6); bag[id]--;if(bag[id]<=0)delete bag[id];saveBag(bag); setCoins(getCoins()+refund); toast('💰 Sprzedano '+it.ic+' '+it.n+' za 💰'+fmt(refund));render(); } function sellBamboo(n){ const have=getBam();n=Math.min(n,have);if(n<=0){toast('Nie masz bambusów 🎋');return;} const rate=90;setBam(have-n);setCoins(getCoins()+n*rate); toast('🎋 Sprzedano '+n+' bambusów za 💰'+fmt(n*rate));render(); } function openCrate(cr){ // losuj nagrodę do plecaka lub monety const pool=ITEMS.filter(x=>(x.cat==='bron'||x.cat==='zbroja')&&x.cost<=cr.cost*(cr.tier===2?6:2.5)); const roll=Math.random(); if(roll<0.45){const amt=Math.round(cr.cost*(0.7+Math.random()*1.8));setCoins(getCoins()+amt);toast('📦 Skrzynka: 💰'+fmt(amt)+' monet!');} else if(roll<0.7){const amt=Math.round((8+cr.tier*10)*(1+Math.random()*2));setBam(getBam()+amt);toast('📦 Skrzynka: 🎋 '+amt+' bambusów!');} else{const w=pool[Math.floor(Math.random()*pool.length)]||ITEMS[0];bag[w.id]=(bag[w.id]||0)+1;saveBag(bag);toast('🎉 Skrzynka: '+w.ic+' '+w.n+'!');} } // ═══════════ GIEŁDA GRACZY (rotujące oferty) ═══════════ let deals=[]; function genDeals(){ deals=[];const tradeable=ITEMS.filter(x=>x.cat!=='skrzynka'); const n=7+Math.floor(Math.random()*3); // 7–9 ofert for(let i=0;i<n;i++){ const it=tradeable[Math.floor(Math.random()*tradeable.length)]; const cheap=Math.random()<0.22; // TANIO rzadko (było 50% = za dużo okazji) const mult=cheap?(0.62+Math.random()*0.2):(0.95+Math.random()*1.25); // ceny się różnią let price=Math.max(15,Math.round(it.cost*mult)); price+=Math.round((Math.random()-0.5)*price*0.07); // jitter → nie-okrągłe: 7.8k, 8.1k... price=Math.max(15,price); const qty=it.cat==='bambus'?(5+Math.floor(Math.random()*30)):1; deals.push({it,price,qty,cheap,seller:NICKS[Math.floor(Math.random()*NICKS.length)]}); } } function buyDeal(i){ const d=deals[i];if(!d)return; const total=d.price*(d.it.cat==='bambus'?1:1); if(getCoins()<total){toast('❌ Za mało monet (💰'+fmt(total)+')');return;} setCoins(getCoins()-total); if(d.it.cat==='bambus'){setBam(getBam()+d.qty);toast('🤝 Kupiono od '+d.seller+': 🎋'+d.qty+' bambusów');} else{bag[d.it.id]=(bag[d.it.id]||0)+1;saveBag(bag);toast('🤝 Kupiono od '+d.seller+': '+d.it.ic+' '+d.it.n);} deals.splice(i,1);render(); } // ═══════════ RENDER ═══════════ let tab='sklep', cat='bron', sort='new'; function fmt(n){n=Math.floor(n);if(n>=1e9)return(n/1e9).toFixed(2)+'B';if(n>=1e6)return(n/1e6).toFixed(2)+'M';if(n>=1e3)return(n/1e3).toFixed(1)+'k';return''+n;} function renderRes(){ document.getElementById('rCoin').innerHTML='💰 '+fmt(getCoins())+'<small>monety (wspólne)</small>'; document.getElementById('rBam').innerHTML='🎋 '+fmt(getBam())+'<small>bambusy</small>'; document.getElementById('rGem').innerHTML='💎 '+fmt(getGems())+'<small>klejnoty</small>'; } function renderTabs(){ const defs=[['sklep','🛒 Sklep'],['plecak','🎒 Plecak'],['gielda','📢 Giełda graczy']]; document.getElementById('tabs').innerHTML=defs.map(([id,l])=>'<div class="tab '+(tab===id?'on':'')+'" onclick="setTab(\''+id+'\')">'+l+'</div>').join(''); } function setTab(t){tab=t;if(t==='gielda'&&!deals.length)genDeals();render();} function setCat(c){cat=c;render();} function setSort(s){sort=s;render();} function sortList(a){const r=a.slice(); if(sort==='cheap')r.sort((x,y)=>x._c-y._c);else if(sort==='exp')r.sort((x,y)=>y._c-x._c);else r.sort((x,y)=>y.ord-x.ord); return r;} function card(ic,name,desc,btnHtml,extra){ return '<div class="card '+(extra||'')+'"><div class="ci">'+ic+'</div><div class="cb"><div class="cn">'+name+'</div><div class="cd">'+desc+'</div>'+btnHtml+'</div></div>'; } function updCountdown(){const el=document.getElementById('countdown');if(!el||typeof nextDealTs==='undefined')return; const s=Math.max(0,Math.ceil((nextDealTs-Date.now())/1000)); el.textContent='🕒 Nowe oferty za '+Math.floor(s/60)+':'+String(s%60).padStart(2,'0');} function render(){ renderRes();renderTabs(); const cs=document.getElementById('cats'),sb=document.getElementById('sortbar'),list=document.getElementById('list'); cs.innerHTML='';sb.innerHTML=''; if(tab==='sklep'){ cs.innerHTML=CATS.map(([id,l])=>'<div class="cat '+(cat===id?'on':'')+'" onclick="setCat(\''+id+'\')">'+l+'</div>').join(''); if(cat!=='bambus')sb.innerHTML=[['new','Najnowsze'],['cheap','Najtańsze'],['exp','Najdroższe']].map(([s,l])=>'<button class="'+(sort===s?'on':'')+'" onclick="setSort(\''+s+'\')">'+l+'</button>').join(''); let items=ITEMS.filter(x=>x.cat===cat).map(x=>Object.assign({_c:x.cost},x)); if(cat==='bambus'){ list.innerHTML=card('🎋','Bambus','Surowiec. Kup po 💰60, sprzedaj po 💰90 na giełdzie.', '<button class="b-buy" '+(getCoins()<60?'disabled':'')+' onclick="buy(\'bamboo\')">Kup · 💰60</button>'+ ' <button class="b-sell" '+(getBam()<1?'disabled':'')+' onclick="sellBamboo(1)">Sprzedaj 1 · 💰90</button>'+ ' <button class="b-sell" '+(getBam()<10?'disabled':'')+' onclick="sellBamboo(10)">×10</button>')+ card('🎋','Masz bambusów: '+fmt(getBam()),'Bambusy zdobywasz też ze skrzynek i na farmach.',''); return; } list.innerHTML=sortList(items).map(it=>{ const own=bag[it.id]?('<span class="own">masz: '+bag[it.id]+'</span> '):''; return card(it.ic,it.n,it.desc, own+'<button class="b-buy" '+(getCoins()<it.cost?'disabled':'')+' onclick="buy(\''+it.id+'\')">Kup · 💰'+fmt(it.cost)+'</button>'); }).join(''); } else if(tab==='plecak'){ const ids=Object.keys(bag).filter(id=>bag[id]>0); if(!ids.length){list.innerHTML='<div class="empty">🎒 Plecak pusty.<br>Kup coś w Sklepie albo na Giełdzie!</div>';return;} list.innerHTML=ids.map(id=>{const it=itemById(id);if(!it)return''; return '<div class="card"><div class="ci">'+it.ic+'</div><div class="cb">'+ '<div class="cn">'+it.n+' ×'+bag[id]+'</div><div class="cd">'+it.desc+'</div>'+ '<div style="display:flex;gap:5px;flex-wrap:wrap;align-items:center">'+ '<button class="b-sell" onclick="sell(\''+id+'\')">⚡ Szybko · +💰'+fmt(Math.round(it.cost*0.6))+'</button>'+ '<input id="price-'+id+'" type="number" min="1" value="'+it.cost+'" title="Twoja cena" style="width:80px;padding:7px;border-radius:8px;border:1px solid #4a3a6e;background:#0f0a1a;color:#ffd24a;font:inherit;font-weight:700">'+ '<button class="b-list" onclick="listItem(\''+id+'\')">📤 Wystaw za swoją cenę</button>'+ '</div></div></div>'; }).join(''); } else if(tab==='gielda'){ sb.innerHTML='<span id="countdown" style="padding:6px 12px;color:#c088ff;font-weight:700;background:#160f26;border:1px solid #3a2e56;border-radius:8px">🕒 …</span>'; if(!deals.length)genDeals(); updCountdown(); let mine=''; if(listings.length){ mine='<div style="grid-column:1/-1;font-weight:700;color:#ffd24a;margin:2px 0 0">📤 Twoje oferty ('+listings.length+') — czekają na kupca:</div>'+ listings.map((l,i)=>{const it=itemById(l.id),r=l.price/l.value,ch=Math.round(sellChance(l.price,l.value)*100); const tag=r>1.6?' <span style="font-size:9px;font-weight:800;background:#7a2a2a;color:#ffbfbf;padding:1px 6px;border-radius:7px">DROGO</span>':r<0.9?' <span style="font-size:9px;font-weight:800;background:#2a7a2a;color:#bfffbf;padding:1px 6px;border-radius:7px">TANIO</span>':''; return '<div class="card"><div class="ci">'+(it?it.ic:'❓')+'</div><div class="cb">'+ '<div class="cn">'+(it?it.n:l.id)+tag+'</div><div class="cd">Twoja cena: 💰'+fmt(l.price)+' • szansa sprzedaży: '+ch+'% co próbę</div>'+ '<button class="b-sell" onclick="cancelListing('+i+')">↩️ Zdejmij</button></div></div>'; }).join('')+'<div style="grid-column:1/-1;font-weight:700;color:#c088ff;margin:6px 0 0">🛒 Oferty innych graczy:</div>'; } list.innerHTML=mine+deals.map((d,i)=>{ const q=d.it.cat==='bambus'?(' ×'+d.qty):''; return card(d.it.ic,d.it.n+q,'<span class="seller">sprzedaje: '+d.seller+'</span>', '<button class="b-list" '+(getCoins()<d.price?'disabled':'')+' onclick="buyDeal('+i+')">Kup · 💰'+fmt(d.price)+'</button>', 'deal').replace('</div></div>','</div><div class="tag '+(d.cheap?'cheap':'pricey')+'">'+(d.cheap?'TANIO':'DROGO')+'</div></div>'); }).join(''); } } let _mt=0; function toast(t){const m=document.getElementById('msg');m.textContent=t;m.classList.add('show');clearTimeout(_mt);_mt=setTimeout(()=>m.classList.remove('show'),1900);} // ═══════════ START ═══════════ const DEAL_EVERY=60000; // giełda odświeża się SAMA co 60 s (koniec free-restocku!) let nextDealTs=Date.now()+DEAL_EVERY; offlineSells(); render(); if(_offlineSold&&_offlineSold.length)setTimeout(()=>toast('💸 Sprzedano gdy Cię nie było: '+_offlineSold.slice(0,3).join(', ')+(_offlineSold.length>3?' +'+(_offlineSold.length-3):'')),500); // Twoje oferty schodzą w LOSOWYCH momentach (nie od razu) — "kupują je gracze" function saleLoop(){ const m=processListings(1); try{localStorage.setItem('rynek_listing_ts',Date.now());}catch(e){} if(m&&m.length){const who=NICKS[Math.floor(Math.random()*NICKS.length)]; toast('💸 '+who+' kupił: '+m.join(', ')); if(tab==='gielda'||tab==='plecak')render();else renderRes();} setTimeout(saleLoop,4000+Math.random()*7000); // losowy odstęp 4–11 s } setTimeout(saleLoop,3000+Math.random()*5000); // tik co 1 s: licznik giełdy + automatyczny restock + odśwież kasę setInterval(function(){ renderRes(); if(Date.now()>=nextDealTs){genDeals();nextDealTs=Date.now()+DEAL_EVERY;if(tab==='gielda')render();} else if(tab==='gielda')updCountdown(); },1000); window.addEventListener('focus',render); </script> </body> </html>
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>🔨 Kowadło</title> <style> *{box-sizing:border-box;-webkit-tap-highlight-color:transparent} html,body{margin:0;height:100%} body{background:radial-gradient(circle at 50% -10%,#241a12,#0c0906 60%);color:#f0e8dc; font:14px/1.4 "Segoe UI",system-ui,sans-serif;overflow-x:hidden;padding-bottom:70px} .wrap{max-width:660px;margin:0 auto;padding:10px} h1{margin:6px 0 2px;text-align:center;font-size:24px;color:#ffcf6a;text-shadow:0 0 18px #ff884466} .sub{text-align:center;color:#b8946a;font-size:11px;margin-bottom:8px} .res{position:sticky;top:0;z-index:20;display:flex;gap:8px;justify-content:center;flex-wrap:wrap; background:rgba(12,9,6,.95);padding:8px;border:1.5px solid #6a4a2a;border-radius:12px;margin-bottom:10px;backdrop-filter:blur(4px)} .chip{background:#241812;border:1px solid #6a4a2a;border-radius:10px;padding:6px 12px;font-weight:700;font-size:15px} .chip small{display:block;font-weight:400;font-size:9px;color:#b8946a} .c-coin{color:#ffd24a} .tabs{display:flex;gap:5px;justify-content:center;flex-wrap:wrap;margin:6px 0} .tab{background:#241812;border:1px solid #6a4a2a;padding:8px 13px;border-radius:10px;font-weight:700;font-size:12.5px;cursor:pointer} .tab.on{background:#a0641e;border-color:#ffb44a;box-shadow:0 0 12px #ff884455} .grid{display:grid;grid-template-columns:1fr 1fr;gap:8px} @media(max-width:520px){.grid{grid-template-columns:1fr}} .card{background:#1c130c;border:1px solid #4a3418;border-radius:12px;padding:10px} .card.eq{border-color:#ffb44a;box-shadow:0 0 12px #ffb44a44} .wname{font-weight:700;font-size:15px;display:flex;align-items:center;gap:7px} .wname .ic{font-size:26px} .stats{font-size:11px;color:#c8b090;margin:5px 0} .fxrow{display:flex;flex-wrap:wrap;gap:4px;margin:4px 0} .fx{font-size:10px;font-weight:700;background:#2a2012;border:1px solid #5a4020;border-radius:7px;padding:2px 7px;color:#ffd8a0} button{font:inherit;cursor:pointer;border:none;border-radius:9px;padding:8px 12px;font-weight:700;color:#fff;background:#3a2a18;transition:transform .05s,filter .1s} button:hover{filter:brightness(1.15)}button:active{transform:translateY(1px)} button:disabled{opacity:.4;cursor:not-allowed;filter:none} .b-eq{background:linear-gradient(#c89a1e,#8a6a10)}.b-forge{background:linear-gradient(#c0501e,#7a3010)} .b-buy{background:linear-gradient(#3a8a2a,#256018)}.b-slot{background:#2a2012;border:1px dashed #6a4a2a} .anvil{display:flex;gap:10px;align-items:center;justify-content:center;flex-wrap:wrap;margin:10px 0} .slot{width:120px;height:96px;border:2px dashed #6a4a2a;border-radius:12px;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#160f08;cursor:pointer;font-size:12px;color:#b8946a;text-align:center} .slot.full{border-style:solid;border-color:#ffb44a;color:#fff} .slot .ic{font-size:34px} .plus{font-size:26px;color:#ffb44a} .picker{display:grid;grid-template-columns:repeat(auto-fill,minmax(78px,1fr));gap:6px;margin-top:8px} .pick{background:#1c130c;border:1px solid #4a3418;border-radius:9px;padding:7px 3px;text-align:center;cursor:pointer;font-size:10px} .pick .ic{font-size:24px;display:block} .pick.sel{border-color:#ffb44a;background:#2a1c10} /* manekin */ .dummy{max-width:420px;margin:10px auto;background:#160f08;border:1px solid #4a3418;border-radius:14px;padding:14px;text-align:center;position:relative;overflow:hidden} .dummyIc{font-size:74px;transition:transform .08s;display:inline-block} .dummyIc.hit{transform:scale(1.12) rotate(3deg)} .dummyIc.frozen{filter:hue-rotate(150deg) brightness(1.3)} .hpbar{height:14px;background:#3a1010;border-radius:8px;overflow:hidden;margin:8px auto;max-width:300px;border:1px solid #6a2020} .hpbar i{display:block;height:100%;background:linear-gradient(90deg,#e74c3c,#ff8a5a);transition:width .12s} .dmgFx{position:absolute;font-weight:800;font-size:20px;color:#ffd24a;pointer-events:none;animation:dmgUp .7s ease-out forwards;text-shadow:0 2px 4px #000} @keyframes dmgUp{to{transform:translateY(-40px);opacity:0}} .kills{color:#ffcf6a;font-weight:700} .msg{position:fixed;left:50%;bottom:14px;transform:translateX(-50%);background:#241812;border:1.5px solid #ffb44a;padding:10px 18px;border-radius:12px;font-weight:700;z-index:50;box-shadow:0 6px 24px #000a;opacity:0;transition:opacity .2s;pointer-events:none;max-width:90vw;text-align:center} .msg.show{opacity:1} .back{position:fixed;top:10px;left:10px;z-index:30;background:#2a1a10;border:1px solid #6a4a2a;font-size:12px;padding:7px 12px;border-radius:9px} .hint{text-align:center;color:#8a7050;font-size:10.5px;margin:8px 0} </style> <script> /* 🔒 Utrudnienie podglądu kodu — ZNIECHĘCA przypadkowego podglądacza (w HTML 100% ochrony kodu nie ma) */ (function(){ document.addEventListener('contextmenu',function(e){e.preventDefault();}); document.addEventListener('keydown',function(e){var k=(e.key||'').toLowerCase(); if(e.key==='F12'||(e.ctrlKey&&e.shiftKey&&(k==='i'||k==='j'||k==='c'))||(e.ctrlKey&&k==='u')){e.preventDefault();return false;}}); })(); </script> </head> <body> <button class="back" onclick="parent.gameClose()">← Menu główne</button> <div class="wrap"> <h1>🔨 Kowadło Mrówek</h1> <div class="sub">Łącz bronie, dodawaj efekty, zaklinaj zbroję — do walki 1v1 i „Gra z Kolegami"</div> <div class="res"><div class="chip c-coin" id="rCoin">💰 0<small>monety (wspólne z grą)</small></div></div> <div class="tabs" id="tabs"></div> <div id="view"></div> </div> <div class="msg" id="msg"></div> <script> "use strict"; // ═══════ BAZOWE BRONIE ═══════ rate = klatki między strzałami (mniej = szybciej) const BASE=[ {id:'pistol', n:'Pistolet', ic:'🔫', dmg:12, rate:28, fx:[]}, {id:'rifle', n:'Karabin', ic:'🎯', dmg:8, rate:10, fx:[]}, {id:'freeze', n:'Zamrażacz',ic:'❄️', dmg:10, rate:24, fx:['freeze']}, {id:'poison', n:'Truciciel',ic:'☠️', dmg:9, rate:26, fx:['poison']}, {id:'rpg', n:'RPG', ic:'🚀', dmg:55, rate:64, fx:['boom']}, {id:'minigun',n:'Minigun', ic:'🔥', dmg:6, rate:4, fx:[]}, ]; const FX={ freeze:{n:'Mróz', ic:'❄️', d:'Co 3. trafienie mrozi wroga na chwilę', cost:4000}, poison:{n:'Trucizna', ic:'☠️', d:'Zatruwa — wróg traci HP przez czas', cost:5000}, boom: {n:'Wybuch', ic:'💥', d:'+60% obrażeń (obszarowo)', cost:8000}, chain: {n:'Łańcuch', ic:'⚡', d:'+30% obrażeń, przeskok na wrogów', cost:9000}, vamp: {n:'Wampiryzm', ic:'🩸', d:'Leczy 20% zadanych obrażeń', cost:7000}, gold: {n:'Złoto', ic:'💰', d:'+monety za zabójstwo', cost:6000}, }; const ARMOR=[ {id:'a1',n:'Lekka Zbroja',ic:'🥋',red:0.10}, {id:'a2',n:'Kolczuga', ic:'🛡️',red:0.22}, {id:'a3',n:'Pełna Płyta', ic:'⚙️',red:0.35}, ]; const ENCH={ unik: {n:'Unik', ic:'💨', d:'Co 4. trafienie w Ciebie chybia', cost:6000}, kolce: {n:'Kolce', ic:'🌵', d:'Odbija 25% obrażeń napastnikowi', cost:5000}, regen: {n:'Regeneracja', ic:'💚', d:'Powoli leczysz się w walce', cost:5000}, tarcza:{n:'Tarcza', ic:'🔰', d:'Pochłania pierwsze trafienie', cost:7000}, }; // ═══════ WSPÓLNA KASA + ZAPIS ═══════ function getCoins(){return parseInt(localStorage.getItem('md_coins_saved')||'0')||0;} function setCoins(v){try{localStorage.setItem('md_coins_saved',Math.max(0,Math.floor(v)));}catch(e){}} let SV={crafted:[],eqW:'pistol',wfx:{},armor:'a1',ench:[],kills:0,uid:1}; function load(){try{const d=JSON.parse(localStorage.getItem('kowadlo_save'));if(d&&typeof d==='object')SV=Object.assign(SV,d);}catch(e){} if(!Array.isArray(SV.crafted))SV.crafted=[];if(!SV.wfx)SV.wfx={};if(!Array.isArray(SV.ench))SV.ench=[];} function save(){try{localStorage.setItem('kowadlo_save',JSON.stringify(SV));}catch(e){}publishWeapon();} // 🗡️→⚔️ Udostępnia WYPOSAŻONĄ broń reszcie gry (1v1 i „Gra z Kolegami" w index.html czytają md_mpWeapon) function publishWeapon(){try{const w=eqWeapon(); localStorage.setItem('md_mpWeapon',JSON.stringify({n:w.n,ic:w.ic,dmg:w.dmg,rate:w.rate,fx:w.fx})); const a=armorById(SV.armor); // 🛡️→⚔️ zbroja + zaklęcia też idą do walki (Arena czyta md_mpArmor) localStorage.setItem('md_mpArmor',JSON.stringify({n:a.n,red:a.red,ench:(SV.ench||[]).slice()}));}catch(e){}} function allWeapons(){return BASE.concat(SV.crafted);} function weaponById(id){return allWeapons().find(w=>w.id===id)||BASE[0];} function eqWeapon(){const w=weaponById(SV.eqW);const extra=SV.wfx[w.id]||[]; return Object.assign({},w,{fx:w.fx.concat(extra.filter(f=>w.fx.indexOf(f)<0))});} function armorById(id){return ARMOR.find(a=>a.id===id)||ARMOR[0];} // ═══════ KOWADŁO — łączenie ═══════ function forge(aId,bId){ const a=weaponById(aId),b=weaponById(bId); const fx=a.fx.concat(b.fx).filter((f,i,arr)=>arr.indexOf(f)===i); const w={id:'w'+(SV.uid++), n:mergeName(a,b), ic:a.dmg>=b.dmg?a.ic:b.ic, dmg:Math.round(Math.max(a.dmg,b.dmg)+Math.min(a.dmg,b.dmg)*0.6), rate:Math.max(3,Math.round(Math.min(a.rate,b.rate)*0.9)), fx:fx, forged:true}; SV.crafted.push(w);SV.eqW=w.id;save(); return w; } function mergeName(a,b){ const short=n=>n.split(' ')[0]; return short(a.n)+'-'+short(b.n); } // ═══════ RENDER ═══════ let tab='bronie'; function fmt(n){n=Math.floor(n);if(n>=1e6)return(n/1e6).toFixed(2)+'M';if(n>=1e3)return(n/1e3).toFixed(1)+'k';return''+n;} function fxTags(list){return list.length?('<div class="fxrow">'+list.map(f=>'<span class="fx">'+(FX[f]?FX[f].ic+' '+FX[f].n:f)+'</span>').join('')+'</div>'):'<div class="stats">brak efektów</div>';} function wStats(w){const dps=(w.dmg*(60/w.rate)).toFixed(0);return '💥 '+w.dmg+' dmg • ⚡ '+(60/w.rate).toFixed(1)+'/s • ~'+dps+' DPS';} function renderRes(){document.getElementById('rCoin').innerHTML='💰 '+fmt(getCoins())+'<small>monety (wspólne z grą)</small>';} function renderTabs(){const d=[['bronie','🗡️ Bronie'],['kowadlo','🔨 Kowadło'],['efekty','✨ Efekty'],['zbroja','🛡️ Zbroja']]; document.getElementById('tabs').innerHTML=d.map(([id,l])=>'<div class="tab '+(tab===id?'on':'')+'" onclick="setTab(\''+id+'\')">'+l+'</div>').join('');} function setTab(t){tab=t;render();} function render(){ renderRes();renderTabs();const v=document.getElementById('view'); if(tab==='bronie'){ v.innerHTML='<div class="hint">Kliknij „Wyposaż", aby ustawić aktywną broń (użyjesz jej w 1v1 i „Gra z Kolegami"). Bazowe + wykute w Kowadle.</div><div class="grid">'+ allWeapons().map(w=>{const eq=SV.eqW===w.id,full=eqFxFor(w); return '<div class="card'+(eq?' eq':'')+'"><div class="wname"><span class="ic">'+w.ic+'</span>'+w.n+(w.forged?' 🔨':'')+'</div>'+ '<div class="stats">'+wStats(w)+'</div>'+fxTags(full)+ '<button class="'+(eq?'b-forge':'b-eq')+'" onclick="equip(\''+w.id+'\')">'+(eq?'✅ Wyposażona':'Wyposaż')+'</button></div>'; }).join('')+'</div>'; } else if(tab==='kowadlo'){ v.innerHTML='<div class="hint">Wybierz dwie bronie i wykuj JEDNĄ, która łączy ich obrażenia i WSZYSTKIE efekty. Np. RPG + Zamrażacz = wybuch, który mrozi.</div>'+ '<div class="anvil"><div class="slot'+(forgeA?' full':'')+'" onclick="clearSlot(\'A\')">'+(forgeA?('<span class="ic">'+weaponById(forgeA).ic+'</span>'+weaponById(forgeA).n):'Slot A<br>(wybierz niżej)')+'</div>'+ '<div class="plus">➕</div>'+ '<div class="slot'+(forgeB?' full':'')+'" onclick="clearSlot(\'B\')">'+(forgeB?('<span class="ic">'+weaponById(forgeB).ic+'</span>'+weaponById(forgeB).n):'Slot B<br>(wybierz niżej)')+'</div></div>'+ '<div style="text-align:center"><button class="b-forge" '+(forgeA&&forgeB?'':'disabled')+' onclick="doForge()" style="font-size:15px;padding:10px 26px">🔨 WYKUJ</button>'+ (forgeA&&forgeB?('<div class="stats" style="margin-top:6px">Wynik: 💥'+forgePreview().dmg+' dmg • '+forgePreview().fx.map(f=>FX[f]?FX[f].ic:'').join('')+'</div>'):'')+'</div>'+ '<div class="hint" style="margin-top:10px">Twoje bronie — kliknij, by wstawić do slotu:</div>'+ '<div class="picker">'+allWeapons().map(w=>'<div class="pick'+(forgeA===w.id||forgeB===w.id?' sel':'')+'" onclick="pick(\''+w.id+'\')"><span class="ic">'+w.ic+'</span>'+w.n+'</div>').join('')+'</div>'; } else if(tab==='efekty'){ const w=weaponById(SV.eqW);const has=eqFxFor(w); v.innerHTML='<div class="hint">Kupujesz efekt → doczepia się do WYPOSAŻONEJ broni ('+w.ic+' '+w.n+'). Efekty działają w walce 1v1 i „Gra z Kolegami".</div><div class="grid">'+ Object.keys(FX).map(id=>{const f=FX[id],owned=has.indexOf(id)>=0,can=getCoins()>=f.cost&&!owned; return '<div class="card"><div class="wname"><span class="ic">'+f.ic+'</span>'+f.n+'</div><div class="stats">'+f.d+'</div>'+ '<button class="'+(owned?'b-forge':'b-buy')+'" '+(can?'':'disabled')+' onclick="buyFx(\''+id+'\')">'+(owned?'✅ Ma tę broń':'Dodaj · 💰'+fmt(f.cost))+'</button></div>'; }).join('')+'</div>'; } else if(tab==='zbroja'){ v.innerHTML='<div class="hint">Wybierz zbroję i dodaj zaklęcia. Redukują lub odbijają obrażenia.</div><div class="grid">'+ ARMOR.map(a=>{const eq=SV.armor===a.id;return '<div class="card'+(eq?' eq':'')+'"><div class="wname"><span class="ic">'+a.ic+'</span>'+a.n+'</div><div class="stats">-'+Math.round(a.red*100)+'% obrażeń</div><button class="'+(eq?'b-forge':'b-eq')+'" onclick="equipArmor(\''+a.id+'\')">'+(eq?'✅ Noszona':'Załóż')+'</button></div>';}).join('')+'</div>'+ '<div class="hint" style="margin-top:10px">✨ Zaklęcia (doczepiają się do zbroi):</div><div class="grid">'+ Object.keys(ENCH).map(id=>{const e=ENCH[id],owned=SV.ench.indexOf(id)>=0,can=getCoins()>=e.cost&&!owned; return '<div class="card"><div class="wname"><span class="ic">'+e.ic+'</span>'+e.n+'</div><div class="stats">'+e.d+'</div><button class="'+(owned?'b-forge':'b-buy')+'" '+(can?'':'disabled')+' onclick="buyEnch(\''+id+'\')">'+(owned?'✅ Aktywne':'Zaklnij · 💰'+fmt(e.cost))+'</button></div>';}).join('')+'</div>'; } } function eqFxFor(w){return w.fx.concat((SV.wfx[w.id]||[]).filter(f=>w.fx.indexOf(f)<0));} // akcje function equip(id){SV.eqW=id;save();render();toast('🗡️ Wyposażono: '+weaponById(id).n);} function equipArmor(id){SV.armor=id;save();render();toast('🛡️ Założono: '+armorById(id).n);} function buyFx(id){const w=weaponById(SV.eqW),f=FX[id];if((SV.wfx[w.id]||[]).indexOf(id)>=0||w.fx.indexOf(id)>=0)return; if(getCoins()<f.cost){toast('❌ Za mało monet (💰'+fmt(f.cost)+')');return;} setCoins(getCoins()-f.cost);SV.wfx[w.id]=(SV.wfx[w.id]||[]).concat(id);save();render();toast('✨ '+f.ic+' '+f.n+' → '+w.n);} function buyEnch(id){const e=ENCH[id];if(SV.ench.indexOf(id)>=0)return;if(getCoins()<e.cost){toast('❌ Za mało monet (💰'+fmt(e.cost)+')');return;} setCoins(getCoins()-e.cost);SV.ench.push(id);save();render();toast('✨ Zaklęcie: '+e.ic+' '+e.n);} // kowadło sloty let forgeA=null,forgeB=null; function pick(id){if(!forgeA)forgeA=id;else if(!forgeB){if(id===forgeA){toast('Wybierz DRUGĄ broń');return;}forgeB=id;}else{forgeA=id;forgeB=null;}render();} function clearSlot(s){if(s==='A'){forgeA=forgeB;forgeB=null;}else forgeB=null;render();} function forgePreview(){const a=weaponById(forgeA),b=weaponById(forgeB);return {dmg:Math.round(Math.max(a.dmg,b.dmg)+Math.min(a.dmg,b.dmg)*0.6),fx:a.fx.concat(b.fx).filter((f,i,arr)=>arr.indexOf(f)===i)};} function doForge(){if(!forgeA||!forgeB)return;const w=forge(forgeA,forgeB);forgeA=null;forgeB=null;render();toast('🔨 Wykuto: '+w.ic+' '+w.n+'! (wyposażona)');} // (Manekin usunięty — bronie mają służyć do walki 1v1 i w „Gra z Kolegami", nie do bicia manekina) // ═══════ EFEKTY UI ═══════ let _mt=0;function toast(t){const m=document.getElementById('msg');m.textContent=t;m.classList.add('show');clearTimeout(_mt);_mt=setTimeout(()=>m.classList.remove('show'),1800);} // ═══════ START ═══════ load();publishWeapon();render();setInterval(renderRes,1500);window.addEventListener('focus',renderRes); </script> </body> </html>
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>🐜 Mrówcze Farmy</title> <style> *{box-sizing:border-box;-webkit-tap-highlight-color:transparent} html,body{margin:0;height:100%} body{background:radial-gradient(circle at 50% -10%,#12240f,#0a0e06 60%);color:#e8f0d8; font:14px/1.4 "Segoe UI",system-ui,sans-serif;overflow-x:hidden;padding-bottom:80px} .wrap{max-width:640px;margin:0 auto;padding:10px} h1{margin:6px 0 2px;text-align:center;font-size:24px;color:#ffe08a;text-shadow:0 0 18px #5ad04066} .sub{text-align:center;color:#8aa060;font-size:11px;margin-bottom:8px} /* pasek zasobów */ .res{position:sticky;top:0;z-index:20;display:flex;gap:8px;justify-content:center;flex-wrap:wrap; background:rgba(8,14,6,.94);padding:8px;border:1.5px solid #3a5a1e;border-radius:12px;margin-bottom:10px; backdrop-filter:blur(4px)} .chip{background:#16240d;border:1px solid #3a5a1e;border-radius:10px;padding:6px 12px;font-weight:700;font-size:15px} .chip small{display:block;font-weight:400;font-size:9px;color:#8aa060} .c-coin{color:#ffd24a} .c-min{color:#7fd0ff} .c-gem{color:#ff8ad0} /* pasek akcji */ .bar{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;margin:8px 0} button{font:inherit;cursor:pointer;border:none;border-radius:10px;padding:9px 12px;font-weight:700;color:#fff; background:#2a3a16;transition:transform .05s,filter .1s} button:hover{filter:brightness(1.15)} button:active{transform:translateY(1px)} button:disabled{opacity:.4;cursor:not-allowed;filter:none} .b-gold{background:linear-gradient(#c89a1e,#8a6a10)} .b-green{background:linear-gradient(#3a8a2a,#256018)} .b-blue{background:linear-gradient(#2a6a9a,#164060)} .b-pink{background:linear-gradient(#a03a7a,#602050)} /* siatka farmy */ #farm{display:grid;gap:7px;margin:6px auto;justify-content:center} .plot{position:relative;aspect-ratio:1;background:linear-gradient(#2a1e10,#1a1206);border:2px solid #3a2a16; border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:30px;cursor:pointer; overflow:hidden;user-select:none;min-width:52px} .plot.empty{border-style:dashed;border-color:#4a3a20;color:#5a4a2a;font-size:20px} .plot .ic{transition:transform .25s;filter:drop-shadow(0 2px 2px #000a)} .plot.ripe{border-color:#ffd24a;box-shadow:0 0 14px #ffd24a88;animation:bob .8s ease-in-out infinite} @keyframes bob{50%{transform:translateY(-3px)}} .plot .bar-g{position:absolute;left:4px;right:4px;bottom:4px;height:4px;background:#0006;border-radius:3px;overflow:hidden} .plot .bar-g i{display:block;height:100%;background:linear-gradient(90deg,#5ad040,#ffd24a);width:0%} .plot .badge{position:absolute;top:2px;right:4px;font-size:11px;font-weight:700;color:#ffd24a;text-shadow:0 1px 2px #000} .plot .mini{position:absolute;bottom:2px;left:3px;font-size:12px} .plot .fx{position:absolute;font-size:14px;font-weight:700;color:#ffd24a;pointer-events:none; animation:fly .8s ease-out forwards;text-shadow:0 1px 3px #000} @keyframes fly{to{transform:translateY(-26px);opacity:0}} /* karty sklepu */ .tabs{display:flex;gap:6px;justify-content:center;flex-wrap:wrap;margin:12px 0 8px} .tab{background:#16240d;border:1px solid #3a5a1e;padding:8px 14px;border-radius:10px;font-weight:700;font-size:13px} .tab.on{background:#3a8a2a;border-color:#5ad040;box-shadow:0 0 12px #5ad04055} .grid{display:grid;grid-template-columns:1fr 1fr;gap:8px} .card{background:#14200c;border:1px solid #33501c;border-radius:12px;padding:10px;display:flex;gap:10px;align-items:center} .card .ci{font-size:30px;filter:drop-shadow(0 2px 2px #000a)} .card .cb{flex:1;min-width:0} .card .cn{font-weight:700;font-size:14px} .card .cd{font-size:10.5px;color:#9ab070;margin:2px 0 6px} .card .cost{font-size:12px;font-weight:700} .sortbar{display:flex;gap:6px;justify-content:center;margin:2px 0 10px;font-size:12px} .sortbar button{padding:5px 10px;background:#16240d;border:1px solid #3a5a1e;font-size:12px} .sortbar button.on{background:#2a6a9a;border-color:#7fd0ff} .msg{position:fixed;left:50%;bottom:16px;transform:translateX(-50%);background:#16240d;border:1.5px solid #5ad040; padding:10px 18px;border-radius:12px;font-weight:700;z-index:50;box-shadow:0 6px 24px #000a;opacity:0;transition:opacity .2s;pointer-events:none;max-width:90vw;text-align:center} .msg.show{opacity:1} .foot{text-align:center;color:#6a805a;font-size:10px;margin:18px 0 6px} .back{position:fixed;top:10px;left:10px;z-index:30;background:#2a1a10;border:1px solid #6a4a2a;font-size:12px;padding:7px 12px} /* skrzynka - animacja otwarcia */ .crateOpen{position:fixed;inset:0;background:#000c;display:none;align-items:center;justify-content:center;z-index:60;flex-direction:column;gap:14px} .crateOpen.show{display:flex} .crateBox{font-size:90px;animation:shake .5s ease-in-out infinite} @keyframes shake{25%{transform:rotate(-8deg)}75%{transform:rotate(8deg)}} .crateReward{font-size:22px;font-weight:800;color:#ffe08a;text-align:center;text-shadow:0 0 18px #ffd24a} </style> <script> /* 🔒 Utrudnienie podglądu kodu — ZNIECHĘCA przypadkowego podglądacza (w HTML 100% ochrony kodu nie ma) */ (function(){ document.addEventListener('contextmenu',function(e){e.preventDefault();}); document.addEventListener('keydown',function(e){var k=(e.key||'').toLowerCase(); if(e.key==='F12'||(e.ctrlKey&&e.shiftKey&&(k==='i'||k==='j'||k==='c'))||(e.ctrlKey&&k==='u')){e.preventDefault();return false;}}); })(); </script> </head> <body> <button class="back" onclick="parent.gameClose()">← Menu główne</button> <div class="wrap"> <h1>🐜 Mrówcze Farmy</h1> <div class="sub">Sadź, hoduj, zatrudniaj minionki — buduj imperium jak na anarchii</div> <div class="res"> <div class="chip c-coin" id="rCoin">💰 0<small>monety</small></div> <div class="chip c-min" id="rMin">💎 0<small>minerały</small></div> <div class="chip c-gem" id="rGem">⭐ 0<small>gwiazdki</small></div> </div> <div class="bar"> <button class="b-green" onclick="collectAll()">🧺 Zbierz wszystko</button> <button class="b-gold" id="expandBtn" onclick="expandFarm()">➕ Powiększ farmę</button> <button class="b-blue" id="machineBtn" onclick="buyMachine()">🤖 Maszyna</button> </div> <div id="farm"></div> <div class="sub" id="farmInfo"></div> <div class="tabs" id="tabs"></div> <div class="sortbar" id="sortbar"></div> <div class="grid" id="shop"></div> <div class="foot">Postęp zapisuje się sam. Minionki i maszyna pracują też, gdy Cię nie ma 💤</div> </div> <div class="crateOpen" id="crateOpen" onclick="this.classList.remove('show')"> <div class="crateBox" id="crateBox">📦</div> <div class="crateReward" id="crateReward"></div> <div style="color:#8aa060;font-size:12px">(kliknij, aby zamknąć)</div> </div> <div class="msg" id="msg"></div> <script> "use strict"; // ═══════════════ DANE ═══════════════ // Uprawy/zwierzęta — każda rośnie w swoim tempie (slow=powoli, fast=szybko) i płaci monety. // growS = ile sekund rośnie, pay = ile monet za zbiór, min = ile minerałów przy zbiorze. const CROPS=[ {id:'grzyb', n:'Grzybek', ic:'🍄', cost:15, growS:4, pay:4, min:0, ord:0}, {id:'mrowka',n:'Mrówka Robotnica',ic:'🐜',cost:60, growS:7, pay:14, min:0, ord:1}, {id:'gasienica',n:'Gąsienica', ic:'🐛', cost:200, growS:11, pay:40, min:0, ord:2}, {id:'zuk', n:'Żuk Górnik', ic:'🐞', cost:650, growS:16, pay:110, min:2, ord:3}, {id:'pszczola',n:'Pszczoła', ic:'🐝', cost:2200, growS:22, pay:340, min:1, ord:4}, {id:'motyl', n:'Motyl', ic:'🦋', cost:7000, growS:30, pay:1000, min:0, ord:5}, {id:'pajak', n:'Pająk Skarbnik',ic:'🕷️',cost:24000,growS:42, pay:3200, min:6, ord:6}, {id:'krolowa',n:'Królowa', ic:'👑', cost:90000, growS:60, pay:12000,min:10,ord:7}, // 🌾 FARMY ZWIERZĄT — zbiór daje monety I przedmiot do ekwipunku (🎒) {id:'bambus',n:'Farma Bambusa',ic:'🎋', cost:40, growS:3, pay:6, min:0, ord:8, drop:'bambus'}, {id:'kura', n:'Farma Kur', ic:'🐔', cost:130, growS:8, pay:22, min:0, ord:9, drop:'jajko'}, {id:'swinia',n:'Farma Świń', ic:'🐷', cost:800, growS:14, pay:130, min:0, ord:10, drop:'boczek'}, {id:'krowa', n:'Farma Krów', ic:'🐄', cost:2600, growS:20, pay:380, min:0, ord:11, drop:'wolowina'}, {id:'owca', n:'Farma Owiec', ic:'🐑', cost:8000, growS:28, pay:1100, min:0, ord:12, drop:'welna'}, {id:'zombie',n:'Farma Zombie', ic:'🧟', cost:30000, growS:40, pay:3600, min:3, ord:13, drop:'kosc'}, ]; // 🎒 PRZEDMIOTY — spadają z Farm Zwierząt przy zbiorze, lądują w ekwipunku; sprzedajesz za monety const ITEMS=[ {id:'bambus', ic:'🎋', n:'Bambus', sell:4}, {id:'jajko', ic:'🥚', n:'Jajko', sell:10}, {id:'boczek', ic:'🥓', n:'Boczek', sell:26}, {id:'wolowina',ic:'🥩', n:'Wołowina', sell:60}, {id:'welna', ic:'🧶', n:'Wełna', sell:150}, {id:'kosc', ic:'🦴', n:'Kość', sell:420}, ]; function itemById(id){return ITEMS.find(x=>x.id===id);} // Minionki — pracują SAME: co interval sekund zbierają najlepszy dojrzały plon. // Droższa minionka = szybsza + czasem kopie minerały. const MINIONS=[ {id:'m1', n:'Minionka I', ic:'🤖', cost:120, interval:6, mineChance:0, ord:0}, {id:'m2', n:'Minionka II', ic:'🦾', cost:900, interval:4, mineChance:0.1, ord:1}, {id:'m3', n:'Robo-Mrówka', ic:'⚙️', cost:5000, interval:2.5,mineChance:0.25,ord:2}, {id:'m4', n:'Kombajn', ic:'🚜', cost:30000, interval:1.4,mineChance:0.5, ord:3}, {id:'m5', n:'Dron Zbieracz',ic:'🛸', cost:150000,interval:0.8,mineChance:0.8, ord:4}, ]; // Skrzynki — kupujesz i otwierasz na losową nagrodę (jak crate na anarchii). const CRATES=[ {id:'c1', n:'Skrzynka Zwykła', ic:'📦', cost:300, costMin:0, ord:0, tier:1}, {id:'c2', n:'Skrzynka Rzadka', ic:'🎁', cost:2500, costMin:5, ord:1, tier:2}, {id:'c3', n:'Skrzynka Legendarna',ic:'💠',cost:0, costMin:40, ord:2, tier:3}, ]; // ═══════════════ STAN ═══════════════ let S={ coin:50, min:0, gem:0, cols:2, rows:3, // rozmiar farmy (start 2x3 = 6 poletek) plots:[], // {crop:id|null, at:ts} minions:{}, // id -> ile sztuk machineLvl:0, // 0 = brak; każdy poziom = szybciej + więcej inv:{}, // 🎒 ekwipunek: itemId -> ile sztuk lastSave:Date.now(), }; function blankPlots(n){const a=[];for(let i=0;i<n;i++)a.push({crop:null,at:0});return a;} function load(){ try{const d=JSON.parse(localStorage.getItem('farmy_save')); if(d&&typeof d==='object'){S=Object.assign(S,d); if(!Array.isArray(S.plots))S.plots=blankPlots(S.cols*S.rows); if(!S.minions)S.minions={}; if(!S.inv||typeof S.inv!=='object')S.inv={};} // 🎒 ekwipunek }catch(e){} // 🔗 WSPÓLNA KASA z grą główną / rynkiem / kowadłem (ten sam klucz md_coins_saved) var _shared=parseInt(localStorage.getItem('md_coins_saved')||'0')||0; if(!S._merged){_shared+=(S.coin||0);S._merged=true;} // raz: dolej stare farmowe monety do wspólnej puli (nic nie przepada) S.coin=_shared; if(!S.plots.length)S.plots=blankPlots(S.cols*S.rows); offlineProgress(); } function save(){S.lastSave=Date.now();try{localStorage.setItem('md_coins_saved',Math.max(0,Math.floor(S.coin||0)));localStorage.setItem('farmy_save',JSON.stringify(S));}catch(e){}} function cropById(id){return CROPS.find(c=>c.id===id);} function giveDrop(c){if(c&&c.drop)S.inv[c.drop]=(S.inv[c.drop]||0)+1;} // 🎒 farma zwierząt → przedmiot do ekwipunku // ═══════════════ MECHANIKA WZROSTU ═══════════════ function growth(plot){ // 0..1 if(!plot.crop)return 0; const c=cropById(plot.crop);if(!c)return 0; return Math.min(1,(Date.now()-plot.at)/(c.growS*1000)); } function harvestPlot(i,silent){ const p=S.plots[i];if(!p.crop)return false; if(growth(p)<1)return false; const c=cropById(p.crop); S.coin+=c.pay; if(c.min)S.min+=c.min; giveDrop(c); p.at=Date.now(); // auto-sadzenie: rośnie od nowa if(!silent)flyText(i,'+'+c.pay); return true; } function collectAll(){ let got=0,n=0; S.plots.forEach((p,i)=>{if(p.crop&&growth(p)>=1){const c=cropById(p.crop);got+=c.pay;if(c.min)S.min+=c.min;giveDrop(c);p.at=Date.now();n++;}}); if(n){S.coin+=got;toast('🧺 Zebrano z '+n+' poletek: 💰'+fmt(got));save();render();} else toast('Nic jeszcze nie dojrzało 🌱'); } // ═══════════════ MINIONKI + MASZYNA (pętla) ═══════════════ function bestRipePlot(){ // indeks dojrzałego poletka o najwyższej wypłacie let bi=-1,bp=-1; S.plots.forEach((p,i)=>{if(p.crop&&growth(p)>=1){const c=cropById(p.crop);if(c.pay>bp){bp=c.pay;bi=i;}}}); return bi; } let _minTimers={}; function minionTick(dt){ MINIONS.forEach(m=>{ const cnt=S.minions[m.id]||0;if(!cnt)return; _minTimers[m.id]=(_minTimers[m.id]||0)+dt; const per=m.interval; // sekundy między zbiorami (na 1 minionkę) while(_minTimers[m.id]>=per){ _minTimers[m.id]-=per; for(let k=0;k<cnt;k++){ const i=bestRipePlot();if(i<0)break; harvestPlot(i,true); if(Math.random()<m.mineChance)S.min+=1; } } }); } let _machT=0; function machineTick(dt){ if(!S.machineLvl)return; _machT+=dt; const every=Math.max(1.2,5-S.machineLvl*0.4); // co ile sekund maszyna zgarnia WSZYSTKO if(_machT>=every){_machT=0; let got=0;S.plots.forEach(p=>{if(p.crop&&growth(p)>=1){const c=cropById(p.crop);got+=c.pay;giveDrop(c);p.at=Date.now();}}); if(got){S.coin+=got;} } } function offlineProgress(){ const dt=Math.min(8*3600,(Date.now()-(S.lastSave||Date.now()))/1000); // max 8h if(dt<2)return; // uproszczone: policz ile zbiorów zrobiłyby minionki/maszyna let earn=0; MINIONS.forEach(m=>{const cnt=S.minions[m.id]||0;if(!cnt)return; const harvests=Math.floor(dt/m.interval)*cnt; // średnia wypłata z posadzonych upraw const planted=S.plots.filter(p=>p.crop).map(p=>cropById(p.crop).pay); const avg=planted.length?planted.reduce((a,b)=>a+b,0)/planted.length:0; earn+=harvests*avg*0.5; // 0.5 = nie wszystko zawsze dojrzałe S.min+=Math.floor(harvests*m.mineChance*0.4); }); if(S.machineLvl){const every=Math.max(1.2,5-S.machineLvl*0.4); const planted=S.plots.filter(p=>p.crop).map(p=>cropById(p.crop).pay); const sum=planted.reduce((a,b)=>a+b,0); earn+=Math.floor(dt/every)*sum*0.35;} earn=Math.floor(earn); if(earn>0){S.coin+=earn;_offlineEarn=earn;} } let _offlineEarn=0; // ═══════════════ ZAKUPY ═══════════════ let selCrop=CROPS[0].id; function plantOn(i){ const p=S.plots[i]; if(p.crop){ // zajęte → zbierz jeśli dojrzałe, inaczej info if(growth(p)>=1){if(harvestPlot(i)){save();render();}} else toast('🌱 Jeszcze rośnie ('+Math.round(growth(p)*100)+'%)'); return; } const c=cropById(selCrop); if(S.coin<c.cost){toast('❌ Za mało monet na '+c.n+' (💰'+fmt(c.cost)+')');return;} S.coin-=c.cost;p.crop=c.id;p.at=Date.now(); toast('🌱 Posadzono: '+c.ic+' '+c.n);save();render(); } function buyMinion(id){ const m=MINIONS.find(x=>x.id===id);const owned=S.minions[id]||0; const cost=Math.round(m.cost*Math.pow(1.35,owned)); if(S.coin<cost){toast('❌ Za mało monet (💰'+fmt(cost)+')');return;} S.coin-=cost;S.minions[id]=owned+1; toast('🤖 Kupiono '+m.n+'! (masz '+S.minions[id]+')');save();render(); } function buyMachine(){ const cost=Math.round(500*Math.pow(2.2,S.machineLvl)); if(S.coin<cost){toast('❌ Maszyna kosztuje 💰'+fmt(cost));return;} S.coin-=cost;S.machineLvl++; toast(S.machineLvl===1?'🤖 Maszyna kupiona! Sama zbiera wszystko.':'⚙️ Maszyna ulepszona → poz. '+S.machineLvl); save();render(); } function expandFarm(){ const plots=S.cols*S.rows; const cost=Math.round(40*Math.pow(1.9,plots-6)); if(plots>=42){toast('🏆 Farma na maksa!');return;} if(S.coin<cost){toast('❌ Powiększenie kosztuje 💰'+fmt(cost));return;} S.coin-=cost; // powiększaj na przemian kolumny/rzędy, trzymając ładny kształt if(S.cols<=S.rows&&S.cols<7)S.cols++; else S.rows++; const need=S.cols*S.rows; while(S.plots.length<need)S.plots.push({crop:null,at:0}); toast('🌾 Farma powiększona → '+S.cols+'×'+S.rows+' ('+need+' poletek)!');save();render(); } function buyCrate(id){ const cr=CRATES.find(x=>x.id===id); if(S.coin<cr.cost){toast('❌ Za mało monet (💰'+fmt(cr.cost)+')');return;} if(S.min<cr.costMin){toast('❌ Za mało minerałów (💎'+cr.costMin+')');return;} S.coin-=cr.cost;S.min-=cr.costMin; openCrate(cr);save();render(); } function openCrate(cr){ // losowa nagroda zależna od tier const roll=Math.random();let rew='',icon=cr.ic; if(roll<0.5){const amt=Math.round(cr.cost*(1+cr.tier)*(0.8+Math.random()*1.6))+50*cr.tier;S.coin+=amt;rew='💰 '+fmt(amt)+' monet!';} else if(roll<0.8){const amt=Math.round((5+cr.tier*8)*(1+Math.random()*2));S.min+=amt;rew='💎 '+amt+' minerałów!';icon='💎';} else if(roll<0.95){const g=cr.tier;S.gem+=g;rew='⭐ '+g+' gwiazdka'+(g>1?'i':'')+'!';icon='⭐';} else{ // rzadka minionka gratis const m=MINIONS[Math.min(MINIONS.length-1,cr.tier)];S.minions[m.id]=(S.minions[m.id]||0)+1;rew='🎉 '+m.n+' GRATIS!';icon=m.ic;} const co=document.getElementById('crateOpen'); document.getElementById('crateBox').textContent=icon; document.getElementById('crateReward').textContent=rew; co.classList.add('show'); setTimeout(()=>{document.getElementById('crateBox').style.animation='none';},600); setTimeout(()=>{document.getElementById('crateBox').style.animation='';},650); } function sellMinerals(){ if(S.min<=0){toast('Nie masz minerałów do sprzedania 💎');return;} const rate=12;const got=S.min*rate;S.coin+=got;const n=S.min;S.min=0; toast('💱 Sprzedano '+n+' 💎 za 💰'+fmt(got));save();render(); } // 🎒 EKWIPUNEK — sprzedaż przedmiotów zebranych z farm zwierząt function invCount(){return ITEMS.reduce((a,it)=>a+(S.inv[it.id]||0),0);} function sellItem(id){const it=itemById(id);const n=S.inv[id]||0;if(n<=0){toast('Nie masz '+(it?it.n:'tego'));return;} const got=n*it.sell;S.coin+=got;S.inv[id]=0;toast('💱 Sprzedano '+n+'× '+it.ic+' za 💰'+fmt(got));save();render();} function sellAllItems(){let got=0,cnt=0;ITEMS.forEach(it=>{const n=S.inv[it.id]||0;if(n>0){got+=n*it.sell;cnt+=n;S.inv[it.id]=0;}}); if(!cnt){toast('Ekwipunek pusty 🎒');return;}S.coin+=got;toast('💱 Sprzedano '+cnt+' przedmiotów za 💰'+fmt(got));save();render();} // ═══════════════ RENDER ═══════════════ let tab='crops', sort='new'; function fmt(n){n=Math.floor(n);if(n>=1e9)return(n/1e9).toFixed(2)+'B';if(n>=1e6)return(n/1e6).toFixed(2)+'M';if(n>=1e3)return(n/1e3).toFixed(1)+'k';return''+n;} function renderRes(){ document.getElementById('rCoin').innerHTML='💰 '+fmt(S.coin)+'<small>monety</small>'; document.getElementById('rMin').innerHTML='💎 '+fmt(S.min)+'<small>minerały</small>'; document.getElementById('rGem').innerHTML='⭐ '+fmt(S.gem)+'<small>gwiazdki</small>'; } function renderFarm(){ const f=document.getElementById('farm'); f.style.gridTemplateColumns='repeat('+S.cols+',minmax(0,1fr))'; f.style.maxWidth=Math.min(620,S.cols*72)+'px'; f.innerHTML=''; S.plots.forEach((p,i)=>{ const d=document.createElement('div');d.className='plot'; if(!p.crop){d.className+=' empty';d.innerHTML='<span>+</span>';} else{ const c=cropById(p.crop),g=growth(p),ripe=g>=1; if(ripe)d.className+=' ripe'; const scale=(0.5+g*0.5).toFixed(2); // ikona ROŚNIE od 50% do 100% d.innerHTML='<span class="ic" style="transform:scale('+scale+')">'+c.ic+'</span>'+ (ripe?'<span class="badge">💰'+fmt(c.pay)+'</span>':'<div class="bar-g"><i style="width:'+Math.round(g*100)+'%"></i></div>')+ (c.min&&ripe?'<span class="mini">💎'+c.min+'</span>':''); } d.onclick=()=>plantOn(i); f.appendChild(d); }); const plots=S.cols*S.rows, exCost=Math.round(40*Math.pow(1.9,plots-6)); const eb=document.getElementById('expandBtn'); eb.textContent=plots>=42?'🏆 Farma MAX':('➕ Powiększ ('+S.cols+'×'+S.rows+') 💰'+fmt(exCost)); eb.disabled=plots<42&&S.coin<exCost; const mCost=Math.round(500*Math.pow(2.2,S.machineLvl)); const mb=document.getElementById('machineBtn'); mb.textContent=S.machineLvl?('🤖 Maszyna poz.'+S.machineLvl+' → 💰'+fmt(mCost)):('🤖 Kup Maszynę 💰'+fmt(mCost)); document.getElementById('farmInfo').textContent= (selCrop?('Sadzisz: '+cropById(selCrop).ic+' '+cropById(selCrop).n+' • '):'')+ 'Kliknij puste poletko = posadź, dojrzałe = zbierz. Minionek: '+totalMinions()+ (S.machineLvl?(' • Maszyna poz.'+S.machineLvl):''); } function totalMinions(){return Object.values(S.minions).reduce((a,b)=>a+b,0);} function renderTabs(){ const ic=invCount(); const defs=[['crops','🌱 Uprawy'],['minions','🤖 Minionki'],['inv','🎒 Ekwipunek'+(ic?' ('+fmt(ic)+')':'')],['crates','📦 Skrzynki'],['market','💱 Rynek']]; document.getElementById('tabs').innerHTML=defs.map(([id,l])=> '<div class="tab '+(tab===id?'on':'')+'" onclick="setTab(\''+id+'\')">'+l+'</div>').join(''); } function setTab(t){tab=t;render();} function setSort(s){sort=s;render();} function sortItems(items){ const a=items.slice(); if(sort==='cheap')a.sort((x,y)=>x._cost-y._cost); else if(sort==='exp')a.sort((x,y)=>y._cost-x._cost); else a.sort((x,y)=>y.ord-x.ord); // najnowszy = najwyższy ord return a; } function renderShop(){ const sb=document.getElementById('sortbar'), sh=document.getElementById('shop'); sb.innerHTML=(tab==='crates'||tab==='market'||tab==='inv')?'': ['new','Najnowsze','cheap','Najtańsze','exp','Najdroższe'].reduce((h,_,i,ar)=>i%2?h:h+ '<button class="'+(sort===ar[i]?'on':'')+'" onclick="setSort(\''+ar[i]+'\')">'+ar[i+1]+'</button>',''); let cards=''; if(tab==='crops'){ const items=CROPS.map(c=>Object.assign({_cost:c.cost},c)); cards=sortItems(items).map(c=>{ const on=selCrop===c.id; return card(c.ic,c.n+(on?' ✅':''),'⏱️'+c.growS+'s → 💰'+fmt(c.pay)+(c.min?' +💎'+c.min:'')+(c.drop?' +'+itemById(c.drop).ic:''), '💰'+fmt(c.cost),S.coin>=c.cost,'plantSelect(\''+c.id+'\')', on?'b-green':'b-gold','Sadź'); }).join(''); } else if(tab==='minions'){ const items=MINIONS.map(m=>{const owned=S.minions[m.id]||0;return Object.assign({_cost:Math.round(m.cost*Math.pow(1.35,owned)),owned},m);}); cards=sortItems(items).map(m=> card(m.ic,m.n+(m.owned?' ×'+m.owned:''),'zbiera co '+m.interval+'s'+(m.mineChance?' • 💎'+Math.round(m.mineChance*100)+'%':''), '💰'+fmt(m._cost),S.coin>=m._cost,'buyMinion(\''+m.id+'\')','b-blue','Kup')).join(''); } else if(tab==='inv'){ const owned=ITEMS.filter(it=>(S.inv[it.id]||0)>0); if(!owned.length){ cards=card('🎒','Ekwipunek pusty','Zakładaj Farmy Zwierząt (🎋🐔🐷🐄🐑🧟) — przy zbiorze przedmioty wpadają tutaj!','','','','b-green','',true); } else { cards=owned.map(it=>{const n=S.inv[it.id]||0; return card(it.ic,it.n+' ×'+fmt(n),'💰'+fmt(it.sell)+'/szt → razem 💰'+fmt(n*it.sell), '💰'+fmt(n*it.sell),true,'sellItem(\''+it.id+'\')','b-gold','Sprzedaj'); }).join(''); const totalVal=owned.reduce((a,it)=>a+(S.inv[it.id]||0)*it.sell,0); cards+=card('💱','Sprzedaj WSZYSTKO','opróżnij cały ekwipunek za monety','💰'+fmt(totalVal),true,'sellAllItems()','b-pink','Sprzedaj'); } } else if(tab==='crates'){ cards=CRATES.map(c=>{const can=S.coin>=c.cost&&S.min>=c.costMin; return card(c.ic,c.n,'losowa nagroda • tier '+c.tier, (c.cost?'💰'+fmt(c.cost):'')+(c.costMin?' 💎'+c.costMin:''),can,'buyCrate(\''+c.id+'\')','b-pink','Otwórz'); }).join(''); } else if(tab==='market'){ cards=card('💎','Sprzedaj minerały','wszystkie 💎 → monety (12 za sztukę)','masz 💎'+fmt(S.min),S.min>0,'sellMinerals()','b-gold','Sprzedaj')+ card('💡','Jak zarabiać?','Sadź drogie uprawy, kupuj minionki (farmią same), maszyna zgarnia wszystko, minerały sprzedawaj tu, a za nie otwieraj Skrzynki.','','','','b-green','',true); } sh.innerHTML=cards; } function card(ic,name,desc,cost,can,fn,cls,btn,noBtn){ return '<div class="card"><div class="ci">'+ic+'</div><div class="cb">'+ '<div class="cn">'+name+'</div><div class="cd">'+desc+'</div>'+ (noBtn?'':'<button class="'+cls+'" '+(can?'':'disabled')+' onclick="'+fn+'">'+btn+' '+(cost?'· '+cost:'')+'</button>')+ (noBtn&&cost?'<div class="cost">'+cost+'</div>':'')+ '</div></div>'; } function plantSelect(id){selCrop=id;toast('Wybrano do sadzenia: '+cropById(id).ic+' '+cropById(id).n);render();} function render(){renderRes();renderFarm();renderTabs();renderShop();} // ═══════════════ EFEKTY ═══════════════ function flyText(i,t){ const f=document.getElementById('farm');const plot=f.children[i];if(!plot)return; const s=document.createElement('span');s.className='fx';s.textContent=t; s.style.left='50%';s.style.top='30%';s.style.transform='translateX(-50%)'; plot.appendChild(s);setTimeout(()=>s.remove(),800); } let _mt=0; function toast(t){const m=document.getElementById('msg');m.textContent=t;m.classList.add('show');clearTimeout(_mt);_mt=setTimeout(()=>m.classList.remove('show'),1800);} // ═══════════════ PĘTLA ═══════════════ let _last=Date.now(); function loop(){ const now=Date.now(),dt=(now-_last)/1000;_last=now; minionTick(dt);machineTick(dt); renderRes(); // odśwież tylko wygląd poletek (paski/skala) bez pełnego przerysowania sklepu const f=document.getElementById('farm'); S.plots.forEach((p,i)=>{const el=f.children[i];if(!el)return; if(!p.crop)return; const c=cropById(p.crop),g=growth(p),ripe=g>=1; const ic=el.querySelector('.ic');if(ic)ic.style.transform='scale('+(0.5+g*0.5).toFixed(2)+')'; const isRipeNow=el.classList.contains('ripe'); if(ripe!==isRipeNow){renderFarm();return;} const bar=el.querySelector('.bar-g i');if(bar&&!ripe)bar.style.width=Math.round(g*100)+'%'; }); } // ═══════════════ START ═══════════════ load();render(); if(_offlineEarn>0)setTimeout(()=>toast('💤 Podczas nieobecności minionki zarobiły 💰'+fmt(_offlineEarn)+'!'),400); setInterval(loop,120); setInterval(save,5000); window.addEventListener('beforeunload',save); // pierwsze uruchomienie — podpowiedź if(S.plots.every(p=>!p.crop)&&totalMinions()===0)setTimeout(()=>toast('👋 Kliknij puste poletko, aby posadzić 🍄 Grzybka!'),900); </script> </body> </html>
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>🥊 Arena 1v1</title> <style> *{box-sizing:border-box}html,body{margin:0;height:100%} body{background:#0a0608;color:#f0e8dc;font:14px/1.4 "Segoe UI",system-ui,sans-serif; display:flex;flex-direction:column;align-items:center;overflow:hidden;user-select:none} h1{margin:6px 0 0;font-size:22px;color:#ffcf6a;text-shadow:0 0 16px #ff884466} canvas{border:2px solid #6a4a2a;border-radius:8px;box-shadow:0 0 30px #00000080;background:#120a10; max-width:98vw;max-height:80vh;image-rendering:auto;touch-action:none} .back{position:fixed;top:8px;left:8px;z-index:10;background:#2a1a10;border:1px solid #6a4a2a;color:#fff; font:12px "Segoe UI";padding:7px 12px;border-radius:9px;cursor:pointer} .hint{color:#9a8060;font-size:11px;margin:4px 8px;text-align:center;max-width:96vw} </style> <script> /* 🔒 Utrudnienie podglądu kodu — ZNIECHĘCA przypadkowego podglądacza (w HTML 100% ochrony kodu nie ma) */ (function(){ document.addEventListener('contextmenu',function(e){e.preventDefault();}); document.addEventListener('keydown',function(e){var k=(e.key||'').toLowerCase(); if(e.key==='F12'||(e.ctrlKey&&e.shiftKey&&(k==='i'||k==='j'||k==='c'))||(e.ctrlKey&&k==='u')){e.preventDefault();return false;}}); })(); </script> </head> <body> <button class="back" onclick="parent.gameClose()">← Menu główne</button> <h1>🥊 Arena 1v1</h1> <canvas id="c" width="820" height="560"></canvas> <div class="hint" id="hint"></div> <script> "use strict"; const C=document.getElementById('c'),X=C.getContext('2d'),W=C.width,H=C.height; const HINT=document.getElementById('hint'); // ═══════ WSPÓLNA KASA + BROŃ Z KOWADŁA ═══════ function getCoins(){return parseInt(localStorage.getItem('md_coins_saved')||'0')||0;} function addCoins(v){try{localStorage.setItem('md_coins_saved',Math.max(0,getCoins()+v));}catch(e){}} function forgedWeapon(){try{const d=JSON.parse(localStorage.getItem('md_mpWeapon')); if(d&&d.dmg>0)return {n:d.n,dmg:+d.dmg,rate:+d.rate||16,fx:d.fx||[]};}catch(e){} return {n:'Pistolet',dmg:12,rate:20,fx:[]};} function forgedArmor(){try{const d=JSON.parse(localStorage.getItem('md_mpArmor')); // 🛡️ zbroja+zaklęcia z Kowadła if(d)return {n:d.n||'Zbroja',red:+d.red||0,ench:Array.isArray(d.ench)?d.ench:[]};}catch(e){} return {n:'brak',red:0,ench:[]};} // ═══════ ARENA (podłoga; poza nią = PUSTKA, spadasz) ═══════ const FL={x:150,y:110,w:520,h:360}; // podłoga function onFloor(o){return o.x>FL.x+8&&o.x<FL.x+FL.w-8&&o.y>FL.y+8&&o.y<FL.y+FL.h-8;} // ═══════ STAN ═══════ let mode='menu', vsBot=true, keys={}, frame=0; let P1,P2,bullets=[],walls=[],bushes=[],parts=[],s1=0,s2=0,roundOver=0,winnerMsg='',matchOver=false; const WIN_ROUNDS=5; function mkPlayer(x,col,name){return {x,y:H/2,vx:0,vy:0,face:0,dmg:0,cd:0,walls:3,bushes:3,r:15,col,name, fell:false,fallT:0,wep:null,placeCd:0,hidden:false};} function startMatch(){ s1=0;s2=0;matchOver=false;newRound(); } function newRound(){ P1=mkPlayer(FL.x+70,'#5ad06a','Gracz 1'); P1.face=0; P2=mkPlayer(FL.x+FL.w-70,'#5aa0ff',vsBot?'BOT':'Gracz 2'); P2.face=Math.PI; P1.wep=forgedWeapon(); // 🗡️ Twoja wykuta broń z Kowadła P2.wep=vsBot?{n:'Karabin',dmg:9,rate:14,fx:[]}:forgedWeapon(); P1.armor=forgedArmor(); P2.armor={n:'brak',red:0,ench:[]}; // 🛡️ Twoja zbroja+zaklęcia (P1) P1.hitCount=0; P2.hitCount=0; P1.shield=P1.armor.ench.indexOf('tarcza')>=0; P2.shield=false; bullets=[];walls=[];bushes=[];parts=[];roundOver=0;winnerMsg='';mode='play'; } // ═══════ WEJŚCIE ═══════ addEventListener('keydown',e=>{keys[e.key.toLowerCase()]=true; if([' ','arrowup','arrowdown','arrowleft','arrowright'].indexOf(e.key.toLowerCase())>=0)e.preventDefault(); if(mode==='menu'){if(e.key==='1'){vsBot=true;startMatch();}if(e.key==='2'){vsBot=false;startMatch();}} else if(mode==='over'){if(e.key.toLowerCase()==='r'){mode='menu';}} }); addEventListener('keyup',e=>{keys[e.key.toLowerCase()]=false;}); // klik/tap w menu C.addEventListener('click',e=>{if(mode==='menu'){const r=C.getBoundingClientRect(),mx=(e.clientX-r.left)*(W/r.width),my=(e.clientY-r.top)*(H/r.height); if(my>250&&my<310){if(mx<W/2){vsBot=true;}else{vsBot=false;}startMatch();}} else if(mode==='over'){mode='menu';}}); // ═══════ STEROWANIE GRACZAMI ═══════ function control(p,up,dn,lf,rt,sh,wl,bu){ let ax=0,ay=0; if(keys[up])ay-=1;if(keys[dn])ay+=1;if(keys[lf])ax-=1;if(keys[rt])ax+=1; if(ax||ay){const l=Math.hypot(ax,ay);p.vx+=ax/l*0.9;p.vy+=ay/l*0.9;p.face=Math.atan2(ay,ax);} if(keys[sh])shoot(p); if(keys[wl]&&p.placeCd<=0&&p.walls>0){placeWall(p);p.walls--;p.placeCd=18;} if(keys[bu]&&p.placeCd<=0&&p.bushes>0){placeBush(p);p.bushes--;p.placeCd=18;} } function shoot(p){ if(p.cd>0)return; const w=p.wep; p.cd=Math.max(6,w.rate); const a=p.face, sp=8.5; bullets.push({x:p.x+Math.cos(a)*20,y:p.y+Math.sin(a)*20,vx:Math.cos(a)*sp,vy:Math.sin(a)*sp, owner:p,dmg:w.dmg,fx:w.fx,life:70,boom:(w.fx||[]).indexOf('boom')>=0}); p.vx-=Math.cos(a)*1.3;p.vy-=Math.sin(a)*1.3; // 🔫 ODRZUT for(let i=0;i<3;i++)parts.push({x:p.x+Math.cos(a)*18,y:p.y+Math.sin(a)*18,vx:Math.cos(a)*2+rnd(-1,1),vy:Math.sin(a)*2+rnd(-1,1),life:10,c:'#ffd24a'}); } function placeWall(p){walls.push({x:cl(p.x+Math.cos(p.face)*40,FL.x,FL.x+FL.w),y:cl(p.y+Math.sin(p.face)*40,FL.y,FL.y+FL.h),hp:60});} function placeBush(p){bushes.push({x:p.x,y:p.y,r:34});} function rnd(a,b){return a+Math.random()*(b-a);} function cl(v,a,b){return v<a?a:v>b?b:v;} // ═══════ BOT ═══════ function bot(p,foe){ if(p.fell)return; // wróć na środek jeśli blisko krawędzi const edge=Math.min(p.x-FL.x,FL.x+FL.w-p.x,p.y-FL.y,FL.y+FL.h-p.y); let tx=foe.x,ty=foe.y; if(edge<70){tx=FL.x+FL.w/2;ty=FL.y+FL.h/2;} // ratuj się od krawędzi else{ // trzymaj dystans ~180 const d=Math.hypot(foe.x-p.x,foe.y-p.y); if(d<150){tx=p.x-(foe.x-p.x);ty=p.y-(foe.y-p.y);} } const ax=tx-p.x,ay=ty-p.y,l=Math.hypot(ax,ay)||1;p.vx+=ax/l*0.7;p.vy+=ay/l*0.7; p.face=Math.atan2(foe.y-p.y,foe.x-p.x); // celuj w gracza if(frame%Math.max(10,p.wep.rate)===0 && !foe.hidden)shoot(p); if(frame%240===0&&p.walls>0){placeWall(p);p.walls--;} } // ═══════ FIZYKA + PĘTLA ═══════ function step(){ frame++; if(mode!=='play')return; if(P1.placeCd>0)P1.placeCd--; if(P2.placeCd>0)P2.placeCd--; if(P1.cd>0)P1.cd--; if(P2.cd>0)P2.cd--; if(!P1.fell)control(P1,'w','s','a','d','f','c','v'); if(!P2.fell){ if(vsBot)bot(P2,P1); else control(P2,'arrowup','arrowdown','arrowleft','arrowright','.',',','/'); } [P1,P2].forEach(p=>{ if(p.fell){p.fallT++;p.r=Math.max(0,p.r-0.4);return;} if(p.armor&&p.armor.ench.indexOf('regen')>=0&&p.dmg>0)p.dmg=Math.max(0,p.dmg-0.05); // 💚 regeneracja — % powoli spada p.vx*=0.86;p.vy*=0.86; p.x+=p.vx;p.y+=p.vy; // kolizja ze ścianami walls.forEach(wl=>{const dx=p.x-wl.x,dy=p.y-wl.y;if(Math.abs(dx)<20&&Math.abs(dy)<20){ if(Math.abs(dx)>Math.abs(dy)){p.x=wl.x+Math.sign(dx)*20;p.vx*=-0.3;}else{p.y=wl.y+Math.sign(dy)*20;p.vy*=-0.3;}}}); // ukrycie w krzaku p.hidden=bushes.some(b=>Math.hypot(p.x-b.x,p.y-b.y)<b.r); // spadł z areny? if(!onFloor(p)){p.fell=true;p.fallT=0;for(let i=0;i<16;i++)parts.push({x:p.x,y:p.y,vx:rnd(-3,3),vy:rnd(-3,3),life:26,c:p.col});} }); // pociski bullets=bullets.filter(b=>{ b.x+=b.vx;b.y+=b.vy;b.life--; if(b.life<=0)return false; // ściana blokuje for(const wl of walls){if(Math.abs(b.x-wl.x)<18&&Math.abs(b.y-wl.y)<18){wl.hp-=b.dmg;boomFx(b);return false;}} // trafienie przeciwnika const foe=b.owner===P1?P2:P1; if(!foe.fell&&Math.hypot(b.x-foe.x,b.y-foe.y)<foe.r+3){ const fx=b.fx||[], arm=foe.armor||{red:0,ench:[]}; foe.hitCount=(foe.hitCount||0)+1; if(arm.ench.indexOf('unik')>=0&&foe.hitCount%4===0){spawnTxt(foe.x,foe.y-22,'💨 UNIK');boomFx(b);return false;} // 💨 co 4. chybia if(foe.shield){foe.shield=false;spawnTxt(foe.x,foe.y-22,'🔰 TARCZA');boomFx(b);return false;} // 🔰 pochłania 1. trafienie let dmg=b.dmg;if(fx.indexOf('boom')>=0)dmg=Math.round(dmg*1.4); dmg=Math.max(1,Math.round(dmg*(1-arm.red))); // 🛡️ redukcja ze zbroi foe.dmg+=dmg; // 💥 KNOCKBACK — im wyższy % tym dalej leci (styl Smash), zbroja tłumi odrzut const kb=(1.2+foe.dmg/45)*(fx.indexOf('boom')>=0?1.5:1)*(1-arm.red*0.5); const a=Math.atan2(b.vy,b.vx); foe.vx+=Math.cos(a)*kb;foe.vy+=Math.sin(a)*kb; if(fx.indexOf('freeze')>=0){foe.vx*=0.6;foe.vy*=0.6;} // ❄️ mróz tłumi ruch if(arm.ench.indexOf('kolce')>=0&&b.owner&&!b.owner.fell){b.owner.dmg+=Math.round(dmg*0.25);spawnTxt(b.owner.x,b.owner.y-22,'🌵');} // 🌵 odbija 25% spawnHit(foe.x,foe.y,dmg);boomFx(b); return false; } return b.x>-20&&b.x<W+20&&b.y>-20&&b.y<H+20; }); walls=walls.filter(w=>w.hp>0); parts=parts.filter(p=>{p.x+=p.vx||0;p.y+=p.vy||0;return --p.life>0;}); // koniec rundy? if(roundOver===0&&(P1.fell||P2.fell)){ roundOver=1; if(P1.fell&&!P2.fell){s2++;winnerMsg=P2.name+' zrzucił '+P1.name+'!';} else if(P2.fell&&!P1.fell){s1++;winnerMsg=P1.name+' zrzucił '+P2.name+'!';} else{winnerMsg='Obaj spadli — remis!';} setTimeout(()=>{ if(s1>=WIN_ROUNDS||s2>=WIN_ROUNDS){matchOver=true;mode='over'; if(s1>s2){addCoins(200);} // 💰 nagroda dla Gracza 1 (wspólna kasa) } else newRound(); },1400); } } function boomFx(b){if(b.boom){for(let i=0;i<10;i++)parts.push({x:b.x,y:b.y,vx:rnd(-3,3),vy:rnd(-3,3),life:14,c:'#ff8800'});} else for(let i=0;i<4;i++)parts.push({x:b.x,y:b.y,vx:rnd(-2,2),vy:rnd(-2,2),life:8,c:'#ffd24a'});} let floats=[]; function spawnHit(x,y,d){floats.push({x,y,t:30,txt:d+'%'});} function spawnTxt(x,y,txt){floats.push({x,y,t:36,txt:txt});} // ═══════ RYSOWANIE ═══════ function draw(){ X.clearRect(0,0,W,H); if(mode==='menu'){drawMenu();return;} // pustka (lawa) tło X.fillStyle='#1a0808';X.fillRect(0,0,W,H); for(let i=0;i<30;i++){const t=frame*0.02+i;X.fillStyle='rgba(255,80,0,'+(0.05+0.04*Math.sin(t))+')'; X.fillRect((i*90+frame*0.4)%W,H-30+8*Math.sin(t*1.3),40,30);} // podłoga areny X.fillStyle='#2a2018';X.fillRect(FL.x,FL.y,FL.w,FL.h); X.strokeStyle='#ffb44a';X.lineWidth=3;X.strokeRect(FL.x,FL.y,FL.w,FL.h); // kafelki X.strokeStyle='rgba(255,180,74,0.08)';X.lineWidth=1; for(let gx=FL.x;gx<FL.x+FL.w;gx+=40){X.beginPath();X.moveTo(gx,FL.y);X.lineTo(gx,FL.y+FL.h);X.stroke();} for(let gy=FL.y;gy<FL.y+FL.h;gy+=40){X.beginPath();X.moveTo(FL.x,gy);X.lineTo(FL.x+FL.w,gy);X.stroke();} // krzaki bushes.forEach(b=>{X.fillStyle='rgba(40,120,40,0.55)';X.beginPath();X.arc(b.x,b.y,b.r,0,7);X.fill(); X.fillStyle='rgba(60,160,60,0.5)';for(let k=0;k<6;k++){const a=k/6*7;X.beginPath();X.arc(b.x+Math.cos(a)*b.r*0.5,b.y+Math.sin(a)*b.r*0.5,10,0,7);X.fill();}}); // ściany walls.forEach(w=>{X.fillStyle='#7a5a30';X.fillRect(w.x-18,w.y-18,36,36);X.strokeStyle='#c89a5a';X.lineWidth=2;X.strokeRect(w.x-18,w.y-18,36,36); X.fillStyle='rgba(0,0,0,0.3)';X.fillRect(w.x-18,w.y-18,36,36*(1-w.hp/60));}); // pociski bullets.forEach(b=>{X.fillStyle=b.boom?'#ff8800':'#ffe066';X.beginPath();X.arc(b.x,b.y,b.boom?5:3.5,0,7);X.fill();}); // gracze [P1,P2].forEach(p=>drawPlayer(p)); // cząstki parts.forEach(p=>{X.globalAlpha=Math.max(0,p.life/26);X.fillStyle=p.c;X.fillRect(p.x-2,p.y-2,4,4);X.globalAlpha=1;}); // floaty floats=floats.filter(f=>{f.y-=0.8;f.t--;X.globalAlpha=Math.max(0,f.t/30);X.fillStyle='#ff6060';X.font='bold 15px Segoe UI';X.textAlign='center';X.fillText(f.txt,f.x,f.y);X.globalAlpha=1;return f.t>0;}); // HUD wyniku X.fillStyle='#5ad06a';X.font='bold 22px Segoe UI';X.textAlign='left';X.fillText('🟢 '+s1,20,40); X.fillStyle='#5aa0ff';X.textAlign='right';X.fillText(s2+' 🔵',W-20,40); X.fillStyle='#b8946a';X.font='12px Segoe UI';X.textAlign='center';X.fillText('do '+WIN_ROUNDS+' zrzuceń',W/2,26); // amunicja/zapasy graczy X.font='12px Segoe UI';X.textAlign='center'; X.fillStyle='#9ad0a0';X.fillText('🧱'+P1.walls+' 🌿'+P1.bushes+' 🗡️'+(P1.wep?P1.wep.n:'')+((P1.armor&&(P1.armor.red||P1.armor.ench.length))?' 🛡️'+Math.round(P1.armor.red*100)+'%'+P1.armor.ench.map(e=>({unik:'💨',kolce:'🌵',regen:'💚',tarcza:'🔰'})[e]||'').join(''):''),W/2,H-8); if(winnerMsg){X.fillStyle='rgba(0,0,0,0.6)';X.fillRect(0,H/2-30,W,60);X.fillStyle='#ffe08a';X.font='bold 26px Segoe UI';X.textAlign='center';X.fillText(winnerMsg,W/2,H/2+8);} if(mode==='over')drawOver(); } function drawPlayer(p){ if(p.fell){X.globalAlpha=Math.max(0,1-p.fallT/40);} X.globalAlpha*= (p.hidden?0.35:1); // cień/ciało X.fillStyle=p.col;X.beginPath();X.arc(p.x,p.y,p.r,0,7);X.fill(); X.strokeStyle='#000';X.lineWidth=2;X.stroke(); // lufa X.strokeStyle='#fff';X.lineWidth=4;X.beginPath();X.moveTo(p.x,p.y);X.lineTo(p.x+Math.cos(p.face)*p.r*1.4,p.y+Math.sin(p.face)*p.r*1.4);X.stroke(); X.globalAlpha=1; // pasek % (im wyższy tym łatwiej zrzucić) const pct=Math.min(1,p.dmg/200); X.fillStyle='#000';X.fillRect(p.x-18,p.y-p.r-12,36,5); X.fillStyle=pct<0.5?'#5ad06a':pct<0.8?'#ffcc00':'#ff4040';X.fillRect(p.x-18,p.y-p.r-12,36*pct,5); X.fillStyle='#fff';X.font='bold 11px Segoe UI';X.textAlign='center';X.fillText(Math.round(p.dmg)+'%',p.x,p.y-p.r-16); } function drawMenu(){ X.fillStyle='#120a10';X.fillRect(0,0,W,H); X.fillStyle='#ffcf6a';X.font='bold 40px Segoe UI';X.textAlign='center';X.fillText('🥊 ARENA 1v1',W/2,120); X.fillStyle='#b8946a';X.font='15px Segoe UI';X.fillText('Zrzuć przeciwnika z areny! Im więcej % oberwie, tym dalej leci.',W/2,155); // przyciski X.fillStyle='#256018';X.fillRect(W/2-260,250,240,60);X.fillStyle='#103a5a';X.fillRect(W/2+20,250,240,60); X.strokeStyle='#5ad06a';X.lineWidth=2;X.strokeRect(W/2-260,250,240,60); X.strokeStyle='#5adcff';X.strokeRect(W/2+20,250,240,60); X.fillStyle='#fff';X.font='bold 20px Segoe UI'; X.fillText('🤖 vs BOT',W/2-140,286);X.fillText('👥 2 GRACZY',W/2+140,286); X.fillStyle='#9a8060';X.font='13px Segoe UI'; X.fillText('🟢 Gracz 1: WASD ruch • F strzał • C mur • V krzak',W/2,360); X.fillText('🔵 Gracz 2: strzałki ruch • .(kropka) strzał • ,(przecinek) mur • / krzak',W/2,384); X.fillText('Broń I ZBROJA (zaklęcia) z 🔨 Kowadła działają tu naprawdę. Wygrana Gracza 1 = +💰200.',W/2,420); X.fillStyle='#ffcf6a';X.fillText('Kliknij tryb albo wciśnij [1] vs BOT / [2] 2 graczy',W/2,455); } function drawOver(){ X.fillStyle='rgba(0,0,0,0.8)';X.fillRect(0,0,W,H); X.fillStyle='#ffe08a';X.font='bold 34px Segoe UI';X.textAlign='center'; const win=s1>s2?P1.name:P2.name; X.fillText('🏆 '+win+' WYGRYWA!',W/2,H/2-20); X.fillStyle='#fff';X.font='22px Segoe UI';X.fillText(s1+' : '+s2,W/2,H/2+20); if(s1>s2){X.fillStyle='#ffd24a';X.font='16px Segoe UI';X.fillText('+💰200 do wspólnej kasy!',W/2,H/2+50);} X.fillStyle='#b8946a';X.font='14px Segoe UI';X.fillText('Kliknij albo [R] — wróć do menu',W/2,H/2+90); } // pętla function loop(){step();draw();HINT.textContent = mode==='play'?'🟢 WASD+F/C/V · 🔵 strzałki+ . , / — zrzuć rywala z krawędzi!':'';requestAnimationFrame(loop);} loop(); </script> </body> </html>
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <title>🏗️ Mrowisko w Lochu — RTS z pauzą</title> <style> html,body{margin:0;height:100%;background:#0a0703;color:#c8b68a;font-family:'Segoe UI',sans-serif; display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;overflow:hidden} canvas{border:3px solid #5a4526;border-radius:6px;background:#0a0400;max-width:100vw;max-height:92vh; image-rendering:auto;touch-action:none} .tip{font-size:12px;color:#6b5a3a} </style> </head> <body> <canvas id="c" width="800" height="600"></canvas> <div class="tip">SPACJA = pauza · 1–6 = narzędzia · przeciągnij myszą = zaznacz obszar · ESC = restart</div> <script> // ── SZKIELET (to samo API co index.html: W,H,ctx,mouse,shootHeld,rr,tx,isOR,gs) ── const C=document.getElementById('c'),ctx=C.getContext('2d'); const W=C.width,H=C.height; let gs='nest'; const mouse={x:0,y:0};let shootHeld=false;const clicks=[]; function rr(x,y,w,h,r,fill,stroke,lw=2){ ctx.beginPath();ctx.roundRect(x,y,w,h,r); if(fill){ctx.fillStyle=fill;ctx.fill();} if(stroke){ctx.strokeStyle=stroke;ctx.lineWidth=lw;ctx.stroke();} } function tx(s,x,y,sz,col,al='center',bold=false){ ctx.font=`${bold?'bold ':''}${sz}px 'Segoe UI'`;ctx.fillStyle=col;ctx.textAlign=al;ctx.textBaseline='middle';ctx.fillText(s,x,y); } function isOR(mx,my,x,y,w,h){return mx>=x&&mx<=x+w&&my>=y&&my<=y+h;} function evPos(e){const r=C.getBoundingClientRect(),bw=3;return{x:(e.clientX-r.left-bw)*(W/(r.width-2*bw)),y:(e.clientY-r.top-bw)*(H/(r.height-2*bw))};} C.addEventListener('mousemove',e=>{const m=evPos(e);mouse.x=m.x;mouse.y=m.y;}); C.addEventListener('mousedown',e=>{if(e.button===0){const m=evPos(e);mouse.x=m.x;mouse.y=m.y;shootHeld=true;clicks.push(m);}}); window.addEventListener('mouseup',e=>{if(e.button===0)shootHeld=false;}); C.addEventListener('contextmenu',e=>e.preventDefault()); // 📱 dotyk: tap = klik, przeciąganie = malowanie obszaru C.addEventListener('touchstart',e=>{e.preventDefault();const t=e.changedTouches[0],p=evPos(t); mouse.x=p.x;mouse.y=p.y;shootHeld=true;clicks.push(p);},{passive:false}); C.addEventListener('touchmove',e=>{e.preventDefault();const t=e.changedTouches[0],p=evPos(t); mouse.x=p.x;mouse.y=p.y;},{passive:false}); function _endT(e){e.preventDefault();shootHeld=false;} C.addEventListener('touchend',_endT,{passive:false}); C.addEventListener('touchcancel',_endT,{passive:false}); // ══════════════════════════════════════════════════════════════════ // 🏗️ TRYB 8: MROWISKO W LOCHU — RTS z pauzą (mrówki autonomiczne) // Gracz NIE steruje mrówkami bezpośrednio: oznacza CO ma powstać // (kop / beton / komora / pułapka) i wydaje rozkazy taktyczne // (zbiórka, odwrót, wychów). Mrówki same szukają najbliższej roboty. // SPACJA = pauza — rozkazy można wydawać także na pauzie. // ══════════════════════════════════════════════════════════════════ const NT=20,NC=40,NR=24,NGH=NR*NT; // kafel 20px → siatka 800×480, pasek UI 480–600 const N_EARTH=0,N_TUN=1,N_ROCK=2,N_CRETE=3,N_AIR=4; const N_SKY=3; // wiersze 0–2 = niebo, od 3 w dół ziemia let nestG=null,nestDes=null,nestHp=null; // teren / oznaczenia gracza / postęp kucia let nestVis=null,nestPrev=null,nestStamp=0; // bufory BFS (bez alokacji co klatkę) let nestAnts=[],nestFoes=[],nestEggs=[],nestChs=[],nestTraps=[],nestCrumbs=[],nestPt=[],nestFl=[]; let nestFood=0,nestMin=0,nestWave=0,nestWaveT=0,nestPaused=false,nestSpeed=1; let nestTool='dig',nestCham='fungus',nestRaise='work',nestOrder=null,nestRally=null; let nestMsg='',nestMsgT=0,nestOver=0,nestQueen=null,nestBest=0,nestKills=0; let nestDrag=null,nestDown=false,nestDirty=true,nestFieldQ=null,nestFieldP=null,nestFieldT=0; let nestClaim=new Map(),nestT=0,nestCrumbT=0,nestEggT=0,nestWarn=0; // ── DANE ────────────────────────────────────────────────────────── const N_CHAMS=[ {id:'nursery', n:'Wylęgarnia', ic:'🥚',m:30,f:20,d:'Jaja klują się 2× szybciej, +6 miejsc'}, {id:'fungus', n:'Farma grzybów',ic:'🍄',m:20,f:15,d:'Mrówka w środku hoduje jedzenie'}, {id:'store', n:'Spiżarnia', ic:'📦',m:25,f:0, d:'+150 limitu jedzenia i minerałów'}, {id:'barracks',n:'Koszary', ic:'⚔️',m:40,f:25,d:'Żołnierze +25% obrażeń i +20 HP'}, ]; const N_FOES=[ {id:'ant', n:'Obca mrówka',ic:'🐜',hp:34, dmg:3, sp:0.62,chew:0.55,w:1}, {id:'spid', n:'Pająk', ic:'🕷️',hp:54, dmg:6, sp:0.78,chew:0.35,w:3}, {id:'beet', n:'Żuk', ic:'🪲',hp:125,dmg:8, sp:0.36,chew:1.30,w:5}, {id:'cric', n:'Świerszcz', ic:'🦗',hp:72, dmg:5, sp:0.98,chew:0.30,w:7}, {id:'scor', n:'Skorpion', ic:'🦂',hp:270,dmg:16,sp:0.50,chew:1.00,w:10,boss:true}, ]; const N_CRETE_COST=8, N_TRAP_COST=25, N_PHER_COST=15, N_EGG_COST=18; // ── 🏴 KOLONIE ──────────────────────────────────────────────────── // Gracz to kolonia 0. Rywale żyją DOKŁADNIE tak samo: mają królową, kopią, // znoszą jedzenie, wychowują żołnierzy i wydzierają teren. Różnica jest jedna — // Twoje mrówki czytają Twoje oznaczenia (nestDes), obce mają własnego kierownika. const N_COLS=[ {n:'Twoje mrowisko',ic:'👑',bd:'#8b4513',lg:'#69340e',qbd:'#e0a92b',qlg:'#c08f1e',sbd:'#a83a1c',slg:'#7d2a12',terr:'#ffd24a'}, {n:'Czerwoni', ic:'🔴',bd:'#a3241c',lg:'#6d130e',qbd:'#e0563a',qlg:'#b03a22',sbd:'#d4452a',slg:'#8a2413',terr:'#ff5a3c'}, {n:'Czarni', ic:'⚫',bd:'#33343d',lg:'#1a1b21',qbd:'#70737f',qlg:'#4a4c55',sbd:'#4a4c58',slg:'#2a2b33',terr:'#98a0bb'}, ]; let nestCols=[]; // stan kolonii w trakcie rozgrywki let nestOwn=null; // TEREN: 0 = niczyje, inaczej id kolonii + 1 let nestWin=0; // 0 = gra trwa, 1 = przegrana, 2 = dominacja // ── dostęp do zasobów kolonii ── // Gracz trzyma zasoby w nestFood/nestMin (cały UI i wejście już na tym stoi), // rywale we własnym rekordzie. Te trzy funkcje ukrywają tę różnicę. function colFood(c){return c===0?nestFood:nestCols[c].food;} function colPay(c,v){ if(c===0){if(nestFood<v)return false;nestFood-=v;return true;} if(nestCols[c].food<v)return false;nestCols[c].food-=v;return true;} function colGain(c,v){ if(c===0)nestFood=Math.min(nestCap(),nestFood+v); else nestCols[c].food=Math.min(360,nestCols[c].food+v);} function colQCh(c){return c===0?nestChs[0]:nestCols[c].qch;} function colAlive(c){return nestCols[c]&&nestCols[c].queen&&nestCols[c].queen.hp>0;} function nestTerr(){const t=[0,0,0];for(let i=0;i<nestOwn.length;i++){const o=nestOwn[i];if(o)t[o-1]++;}return t;} // kafel przechodzi na własność kolonii, która go wykopała / po nim depcze function nestOwnTile(i,c){if(i>=0&&i<nestOwn.length)nestOwn[i]=c+1;} // ── KAFLE ───────────────────────────────────────────────────────── const nestIdx=(x,y)=>y*NC+x; const nestSolid=t=>t===N_EARTH||t===N_ROCK||t===N_CRETE; const nestWalk=i=>i>=0&&i<NC*NR&&(nestG[i]===N_TUN||nestG[i]===N_AIR); const nestMaxHp=t=>t===N_EARTH?60:t===N_ROCK?230:t===N_CRETE?260:1; const nestPX=i=>(i%NC)*NT+NT/2, nestPY=i=>((i/NC)|0)*NT+NT/2; function nestAt(x,y){const cx=Math.max(0,Math.min(NC-1,(x/NT)|0)),cy=Math.max(0,Math.min(NR-1,(y/NT)|0));return cy*NC+cx;} function nestNb(i,out){ // 4 sąsiadów w granicach mapy out.length=0;const x=i%NC,y=(i/NC)|0; if(x>0)out.push(i-1);if(x<NC-1)out.push(i+1);if(y>0)out.push(i-NC);if(y<NR-1)out.push(i+NC); return out; } const _nb=[],_nb2=[]; function nestSay(m,warn){nestMsg=m;nestMsgT=200;if(warn)nestWarn=18;} function nestPart(x,y,col,n,sp=1.6){for(let k=0;k<n;k++)nestPt.push({x,y,vx:(Math.random()-0.5)*sp*2,vy:(Math.random()-0.5)*sp*2-0.4,l:18+Math.random()*18,col});} function nestFloat(x,y,t,col){nestFl.push({x,y,t,col,l:56});} // ── GENERACJA MAPY ──────────────────────────────────────────────── function nestGen(){ const N=NC*NR; nestG=new Uint8Array(N);nestDes=new Uint8Array(N);nestHp=new Float32Array(N); nestVis=new Int32Array(N);nestPrev=new Int32Array(N);nestStamp=0; for(let y=0;y<NR;y++)for(let x=0;x<NC;x++)nestG[nestIdx(x,y)]=y<N_SKY?N_AIR:N_EARTH; // 🪨 żyły skalne — kępki rosnące błądzeniem losowym (im głębiej, tym więcej) for(let s=0;s<16;s++){ let x=1+((Math.random()*(NC-2))|0), y=N_SKY+3+((Math.random()*(NR-N_SKY-4))|0); const len=4+((Math.random()*11)|0); for(let k=0;k<len;k++){ if(y>=N_SKY+1&&y<NR&&x>=0&&x<NC)nestG[nestIdx(x,y)]=N_ROCK; x+=(Math.random()*3|0)-1; y+=(Math.random()*3|0)-1; x=Math.max(0,Math.min(NC-1,x)); y=Math.max(N_SKY+1,Math.min(NR-1,y)); } } nestOwn=new Uint8Array(N); // 🕳️ Trzy gniazda: Ty pośrodku, rywale na obu flankach — teren pomiędzy jest do wzięcia. // Każde dostaje szyb na powierzchnię (dostęp do okruchów) i komnatę królowej 5×3. nestChs=[]; const sites=[{qx:18,qy:9,sx:20},{qx:3,qy:16,sx:5},{qx:32,qy:16,sx:33}]; sites.forEach((s,ci)=>{ for(let y=N_SKY;y<s.qy;y++){ nestG[nestIdx(s.sx,y)]=N_TUN;nestG[nestIdx(s.sx+1,y)]=N_TUN; nestOwnTile(nestIdx(s.sx,y),ci);nestOwnTile(nestIdx(s.sx+1,y),ci);} for(let y=s.qy;y<s.qy+3;y++)for(let x=s.qx;x<s.qx+5;x++){ nestG[nestIdx(x,y)]=N_TUN;nestOwnTile(nestIdx(x,y),ci);} nestChs.push({ty:'queen',c:ci,x0:s.qx,y0:s.qy,w:5,h:3,done:true,prog:1,tiles:nestTiles(s.qx,s.qy,5,3)}); }); } function nestTiles(x0,y0,w,h){const a=[];for(let y=y0;y<y0+h;y++)for(let x=x0;x<x0+w;x++)if(x>=0&&x<NC&&y>=0&&y<NR)a.push(nestIdx(x,y));return a;} function nestChamAt(i){for(const c of nestChs)if(c.tiles.indexOf(i)>=0)return c;return null;} function nestChamOf(ty){return nestChs.filter(c=>c.done&&c.ty===ty);} const nestCap=()=>120+150*nestChamOf('store').length; const nestPopCap=()=>12+6*nestChamOf('nursery').length; // ── START ───────────────────────────────────────────────────────── function startNest(){ nestGen(); nestAnts=[];nestFoes=[];nestEggs=[];nestTraps=[];nestCrumbs=[];nestPt=[];nestFl=[]; nestClaim.clear(); nestFood=90;nestMin=60;nestWave=0;nestWaveT=90*60;nestPaused=false;nestSpeed=1; nestTool='dig';nestCham='fungus';nestRaise='work';nestOrder=null;nestRally=null; nestOver=0;nestKills=0;nestT=0;nestCrumbT=0;nestEggT=0;nestDirty=true;nestDrag=null;nestDown=false;nestWin=0; nestBest=parseInt(localStorage.getItem('md_nestBest')||'0')||0; // 🏴 trzy kolonie z IDENTYCZNYM startem — przewaga ma wyjść z gry, nie z rozdania nestCols=N_COLS.map((def,ci)=>{ const q=nestChs[ci],qcx=(q.x0+2)*NT+NT/2,qcy=(q.y0+1)*NT+NT/2; const queen=nestNewAnt('queen',qcx,qcy,ci);nestAnts.push(queen); for(let k=0;k<6;k++)nestAnts.push(nestNewAnt('work',qcx+(Math.random()-0.5)*46,qcy+(Math.random()-0.5)*26,ci)); for(let k=0;k<2;k++)nestAnts.push(nestNewAnt('sold',qcx+(Math.random()-0.5)*46,qcy+(Math.random()-0.5)*26,ci)); return{def,qch:q,queen,food:90,min:60,aiT:40+ci*30,goal:null,raid:0,kills:0}; }); nestQueen=nestCols[0].queen; for(let k=0;k<7;k++)nestSpawnCrumb(); nestSay('🏴 Trzy kolonie, jeden loch. Zaznacz ziemię — mrówki wykopią. SPACJA = pauza.'); gs='nest'; } function nestNewAnt(role,x,y,c){ const hp=role==='queen'?280:role==='sold'?46:26; return{role,c:c|0,x,y,ang:0,wk:0,hp,mhp:hp,task:null,path:null,pt:0,cd:0,think:0,carry:0,repath:0,flee:0,hit:0,eggT:300}; } function nestSpawnCrumb(){ if(nestCrumbs.length>=12)return; const x=2+((Math.random()*(NC-4))|0), ti=nestIdx(x,N_SKY-1); if(nestCrumbs.some(c=>c.ti===ti))return; nestCrumbs.push({ti,x:nestPX(ti)+(Math.random()-0.5)*8,y:nestPY(ti)+6,amt:8+((Math.random()*6)|0)}); } // ── ŚCIEŻKI ─────────────────────────────────────────────────────── // BFS po kafelkach chodliwych; zwraca tablicę indeksów (bez startu) lub null function nestPath(from,to){ if(from===to)return[]; const st=++nestStamp;nestVis[from]=st;nestPrev[from]=from; const q=[from];let h=0; while(h<q.length){ const c=q[h++]; nestNb(c,_nb); for(let k=0;k<_nb.length;k++){const n=_nb[k]; if(nestVis[n]===st||!nestWalk(n))continue; nestVis[n]=st;nestPrev[n]=c; if(n===to){const p=[];let z=n;while(z!==from){p.push(z);z=nestPrev[z];}return p.reverse();} q.push(n);} } return null; } // Dijkstra kosztowa dla wrogów: tunel tani, ziemia droga, BETON bardzo drogi function nestField(srcs){ const N=NC*NR,d=new Float32Array(N).fill(1e9),hi=[],hd=[]; const up=(c)=>{while(c>0){const p=(c-1)>>1;if(hd[p]<=hd[c])break;const a=hi[p];hi[p]=hi[c];hi[c]=a;const b=hd[p];hd[p]=hd[c];hd[c]=b;c=p;}}; const dn=()=>{let c=0;for(;;){const l=c*2+1,r=l+1;let s=c;if(l<hd.length&&hd[l]<hd[s])s=l;if(r<hd.length&&hd[r]<hd[s])s=r;if(s===c)break;const a=hi[s];hi[s]=hi[c];hi[c]=a;const b=hd[s];hd[s]=hd[c];hd[c]=b;c=s;}}; for(const s of srcs){if(s>=0&&s<N&&d[s]>0){d[s]=0;hi.push(s);hd.push(0);up(hi.length-1);}} while(hi.length){ const c=hi[0],cd=hd[0]; const li=hi.pop(),ld=hd.pop(); if(hi.length){hi[0]=li;hd[0]=ld;dn();} if(cd>d[c]+0.001)continue; nestNb(c,_nb2); for(let k=0;k<_nb2.length;k++){const n=_nb2[k],t=nestG[n]; const w=(t===N_TUN||t===N_AIR)?1:t===N_EARTH?16:t===N_CRETE?85:260; const nd=cd+w; if(nd<d[n]){d[n]=nd;hi.push(n);hd.push(nd);up(hi.length-1);}} } return d; } function nestFields(){ // zwierzyna idzie do NAJBLIŻSZEJ żywej królowej — pole ma wiele źródeł, więc to za darmo const q=[]; for(let ci=0;ci<nestCols.length;ci++)if(colAlive(ci))q.push(nestAt(nestCols[ci].queen.x,nestCols[ci].queen.y)); nestFieldQ=nestField(q.length?q:[0]); const ph=nestTraps.filter(t=>t.ty==='pher').map(t=>t.ti); nestFieldP=ph.length?nestField(ph):null; nestFieldT=45; } // ── ROBOTA DLA MRÓWEK (autonomia) ───────────────────────────────── // Zwraca zadanie, jeśli STOJĄC na kaflu i można coś zrobić (tu lub obok) function nestWorkAt(i){ if(nestClaim.has(i))return null; const d=nestDes[i]; if((d===3||d===4)&&nestG[i]===N_TUN&&!nestTraps.some(t=>t.ti===i)){ if(nestFood>=(d===3?N_TRAP_COST:N_PHER_COST))return{t:'trap',ti:i,ty:d}; } for(const c of nestCrumbs)if(c.ti===i&&!nestClaim.has(i))return{t:'crumb',ti:i}; const ch=nestChamAt(i); if(ch&&!ch.done&&nestG[i]===N_TUN)return{t:'build',ti:i,ch}; if(ch&&ch.done&&ch.ty==='fungus'&&i===ch.tiles[4]&&nestFood<nestCap())return{t:'farm',ti:i,ch}; // 1 grzybiarka na farmę nestNb(i,_nb); for(let k=0;k<_nb.length;k++){const n=_nb[k],dn2=nestDes[n]; if(dn2===1&&nestSolid(nestG[n])&&!nestClaim.has(n))return{t:'dig',ti:n,from:i}; if(dn2===2&&nestG[n]!==N_CRETE&&nestG[n]!==N_ROCK&&!nestClaim.has(n)&&nestMin>=N_CRETE_COST)return{t:'crete',ti:n,from:i};} return null; } // BFS od mrówki: znajdź NAJBLIŻSZĄ dostępną robotę i ścieżkę do niej function nestFindWork(a){ const start=nestAt(a.x,a.y); if(!nestWalk(start))return null; const st=++nestStamp;nestVis[start]=st;nestPrev[start]=start; const q=[start];let h=0; while(h<q.length){ const c=q[h++]; const job=nestWorkAt(c); if(job){const p=[];let z=c;while(z!==start){p.push(z);z=nestPrev[z];}job.path=p.reverse();return job;} nestNb(c,_nb2); for(let k=0;k<_nb2.length;k++){const n=_nb2[k]; if(nestVis[n]===st||!nestWalk(n))continue; nestVis[n]=st;nestPrev[n]=c;q.push(n);} } return null; } // ── 🤖 KIEROWNIK OBCEJ KOLONII ──────────────────────────────────── // Rywale nie mają oznaczeń gracza — dostają CEL, a robotnice same kopią w jego stronę. // Młoda kolonia się żywi i rozbudowuje, dojrzała rusza na najbliższą obcą królową. function nestAiGoal(ci){ const C=nestCols[ci]; if(!C.queen||C.queen.hp<=0)return null; const mine=nestAnts.reduce((s,a)=>s+(a.c===ci?1:0),0); if(mine>=10){ let best=null,bd=1e9; for(let k=0;k<nestCols.length;k++){ if(k===ci||!colAlive(k))continue; const q=nestCols[k].queen,d=Math.hypot(q.x-C.queen.x,q.y-C.queen.y); if(d<bd){bd=d;best=q;}} if(best){C.raid=1;return nestAt(best.x,best.y);} } C.raid=0; let cr=null,cd=1e9; for(const c of nestCrumbs){const d=Math.hypot(c.x-C.queen.x,c.y-C.queen.y);if(d<cd){cd=d;cr=c;}} if(cr)return cr.ti; const qx=C.qch.x0+2,qy=C.qch.y0+1; return nestIdx(Math.max(1,Math.min(NC-2,qx+(ci===1?7:-7))),Math.min(NR-2,qy+3)); } // BFS po własnych tunelach: albo okruch pod nogami, albo kafel do wykopania, // który NAJBARDZIEJ zbliża kolonię do celu. To zastępuje rywalom nestDes. function nestRivalWork(a){ const start=nestAt(a.x,a.y); if(!nestWalk(start))return null; const C=nestCols[a.c],goal=(C&&C.goal!=null)?C.goal:start; const gx=goal%NC,gy=(goal/NC)|0; const st=++nestStamp;nestVis[start]=st;nestPrev[start]=start; const q=[start];let h=0,steps=0,bestDig=-1,bestFrom=-1,bestScore=1e9; while(h<q.length&&steps<900){ const c=q[h++];steps++; for(const cr of nestCrumbs)if(cr.ti===c&&!nestClaim.has(c)){ const p=[];let z=c;while(z!==start){p.push(z);z=nestPrev[z];} return{t:'crumb',ti:c,path:p.reverse()};} nestNb(c,_nb2); for(let k=0;k<_nb2.length;k++){const n=_nb2[k]; if(nestVis[n]===st)continue; if(!nestWalk(n)){ // ściana: kandydat na wykop if(nestG[n]===N_ROCK||nestClaim.has(n))continue; const sc=Math.abs(n%NC-gx)+Math.abs(((n/NC)|0)-gy); if(sc<bestScore){bestScore=sc;bestDig=n;bestFrom=c;} continue;} nestVis[n]=st;nestPrev[n]=c;q.push(n);} } if(bestDig>=0){ const p=[];let z=bestFrom;while(z!==start){p.push(z);z=nestPrev[z];} return{t:'dig',ti:bestDig,from:bestFrom,path:p.reverse()};} return null; } function nestDrop(a){ // gdzie odnieść jedzenie: spiżarnia → komnata królowej (własnej!) if(a.c!==0){const q=colQCh(a.c);return q.tiles[(q.tiles.length/2)|0];} const st=nestChamOf('store'),q=nestChs[0]; const c=st.length?st[0]:q; return c.tiles[(c.tiles.length/2)|0]; } function nestFree(a){ // zwolnij rezerwację kafla if(a.task){if(a.task.ti!==undefined&&nestClaim.get(a.task.ti)===a)nestClaim.delete(a.task.ti);} a.task=null;a.path=null; } function nestTake(a,job){ a.task=job;a.path=job.path||null; if(job.ti!==undefined)nestClaim.set(job.ti,a); if(job.t==='dig'||job.t==='crete')nestClaim.set(job.ti,a); } // ── RUCH ────────────────────────────────────────────────────────── function nestGo(a,tx,ty,sp){ const dx=tx-a.x,dy=ty-a.y,d=Math.hypot(dx,dy); if(d<1.4)return true; a.ang=Math.atan2(dy,dx);a.x+=dx/d*sp;a.y+=dy/d*sp;a.wk+=sp; return false; } // 0=idzie, 1=doszedł, 2=ścieżka zablokowana function nestFollow(a,sp){ if(!a.path||!a.path.length)return 1; const ti=a.path[0]; if(!nestWalk(ti)){a.path=null;return 2;} if(nestGo(a,nestPX(ti),nestPY(ti),sp))a.path.shift(); return a.path.length?0:1; } // ── MRÓWKI ──────────────────────────────────────────────────────── function nestUpdAnt(a){ if(a.hit>0)a.hit--; if(a.cd>0)a.cd--; // 🧱 zamurowana? (ktoś postawił beton na jej kaflu) — wypchnij do najbliższego tunelu {const t0=nestAt(a.x,a.y); if(!nestWalk(t0)){ const x=t0%NC,y=(t0/NC)|0;let out=-1; if(x>0&&nestWalk(t0-1))out=t0-1;else if(x<NC-1&&nestWalk(t0+1))out=t0+1; else if(y>0&&nestWalk(t0-NC))out=t0-NC;else if(y<NR-1&&nestWalk(t0+NC))out=t0+NC; if(out>=0){a.x=nestPX(out);a.y=nestPY(out);}else a.hp-=0.4; nestFree(a); }} // 🏴 TEREN: mrówka depcząc kafel przeciąga go na stronę swojej kolonii. // Stąd bierze się ruchomy front — żadnej osobnej mechaniki nie trzeba. if(nestT%10===0){const ti0=nestAt(a.x,a.y); if(nestWalk(ti0)&&nestOwn[ti0]!==a.c+1&&Math.random()<0.34)nestOwnTile(ti0,a.c);} if(a.role==='queen'){nestUpdQueen(a);return;} if(a.role==='sold'){nestUpdSold(a);return;} // 🐜 ROBOTNICA — ucieka przed zwierzem ORAZ przed żołnierzami obcej kolonii let danger=null,dd=1e9; for(const f of nestFoes){const d=Math.hypot(f.x-a.x,f.y-a.y);if(d<44&&d<dd){dd=d;danger=f;}} for(const o of nestAnts){if(o.c===a.c||o.role==='work')continue; const d=Math.hypot(o.x-a.x,o.y-a.y);if(d<38&&d<dd){dd=d;danger=o;}} if(danger){ a.flee=40;nestFree(a); const ang=Math.atan2(a.y-danger.y,a.x-danger.x); const nx=a.x+Math.cos(ang)*6,ny=a.y+Math.sin(ang)*6; if(nestWalk(nestAt(nx,ny))){a.x=nx;a.y=ny;a.ang=ang;a.wk+=1.4;} return; } if(a.flee>0){a.flee--;} if(!a.task){ if(a.carry>0){const dst=nestDrop(a);a.task={t:'haul',ti:dst};a.path=nestPath(nestAt(a.x,a.y),dst);} else if(--a.think<=0){ const job=a.c===0?nestFindWork(a):nestRivalWork(a); // 🤖 rywale mają własnego kierownika a.think=18+((Math.random()*22)|0); if(job)nestTake(a,job); else{ // brak roboty → spacer po gnieździe const q=colQCh(a.c),c=q.tiles[(Math.random()*q.tiles.length)|0]; a.path=nestPath(nestAt(a.x,a.y),c); } } if(!a.task){nestFollow(a,0.5);return;} } const T=a.task; const r=nestFollow(a,0.85); if(r===2){nestFree(a);return;} if(r===0)return; // jeszcze w drodze // ── na miejscu: wykonuj ── if(T.t==='dig'||T.t==='crete'){ const ti=T.ti; // oznaczenia to narzędzie GRACZA — rywale kopią z rozkazu kierownika, nie z nestDes if(a.c===0){if(nestDes[ti]!==(T.t==='dig'?1:2)){nestFree(a);return;}} else if(T.t!=='dig'||!nestSolid(nestG[ti])){nestFree(a);return;} a.ang=Math.atan2(nestPY(ti)-a.y,nestPX(ti)-a.x); if(T.t==='dig'){ nestHp[ti]+=nestG[ti]===N_ROCK?0.85:1.15; if(nestT%7===0)nestPart(nestPX(ti)+(Math.random()-0.5)*10,nestPY(ti)+(Math.random()-0.5)*10,nestG[ti]===N_ROCK?'#8d8d96':'#6b4423',1,1.1); if(nestHp[ti]>=nestMaxHp(nestG[ti])){ const rock=nestG[ti]===N_ROCK; nestG[ti]=N_TUN;nestDes[ti]=0;nestHp[ti]=0;nestDirty=true; nestOwnTile(ti,a.c); // 🏴 kto wykopał, ten ma if(a.c===0)nestMin=Math.min(nestCap(),nestMin+(rock?6:2)); else nestCols[a.c].min+=rock?6:2; nestPart(nestPX(ti),nestPY(ti),rock?'#8d8d96':'#6b4423',9); nestFree(a); } } else { nestHp[ti]+=0.75; if(nestHp[ti]>=90){ if(nestMin<N_CRETE_COST){nestHp[ti]=0;nestDes[ti]=0;nestSay('🪨 Brak minerałów na mrówkobeton',1);nestFree(a);return;} nestMin-=N_CRETE_COST;nestG[ti]=N_CRETE;nestDes[ti]=0;nestHp[ti]=0;nestDirty=true; nestPart(nestPX(ti),nestPY(ti),'#b9a07a',10);nestFloat(nestPX(ti),nestPY(ti)-8,'🧱','#d8c9a8'); nestFree(a); } } return; } if(T.t==='trap'){ const ti=T.ti; if(nestDes[ti]!==T.ty){nestFree(a);return;} a.pt++; if(a.pt>110){ const cost=T.ty===3?N_TRAP_COST:N_PHER_COST; if(nestFood<cost){nestSay('🍞 Brak jedzenia na pułapkę',1);nestDes[ti]=0;nestFree(a);a.pt=0;return;} nestFood-=cost;nestDes[ti]=0; nestTraps.push(T.ty===3?{ti,ty:'fung',chg:320}:{ti,ty:'pher',t:1500}); nestPart(nestPX(ti),nestPY(ti),T.ty===3?'#7ee081':'#ff86d0',14); nestFloat(nestPX(ti),nestPY(ti)-10,T.ty===3?'🍄':'💨',T.ty===3?'#7ee081':'#ff86d0'); nestDirty=true;a.pt=0;nestFree(a); } return; } if(T.t==='build'){ const ch=T.ch; if(!ch||ch.done){nestFree(a);return;} ch.prog+=0.0032; if(nestT%9===0)nestPart(a.x,a.y,'#d8c9a8',1,0.9); if(ch.prog>=1){ ch.prog=1;ch.done=true; const info=N_CHAMS.find(c=>c.id===ch.ty); nestSay((info?info.ic+' '+info.n:'Komora')+' gotowa!'); nestFloat((ch.x0+ch.w/2)*NT,(ch.y0)*NT,'✅ '+(info?info.n:''),'#7ee081'); nestPart((ch.x0+ch.w/2)*NT,(ch.y0+ch.h/2)*NT,'#ffd24a',18); } return; } if(T.t==='farm'){ a.pt++; colGain(a.c,0.021); if(nestT%26===0)nestPart(a.x+(Math.random()-0.5)*14,a.y-4,'#7ee081',1,0.7); if(a.pt>360||nestFood>=nestCap()){a.pt=0;nestFree(a);} return; } if(T.t==='crumb'){ const ci=nestCrumbs.findIndex(c=>c.ti===T.ti); if(ci<0){nestFree(a);return;} a.carry=nestCrumbs[ci].amt;nestCrumbs.splice(ci,1); nestFloat(a.x,a.y-10,'🌿','#9ee493'); nestFree(a); const dst=nestDrop(a);a.task={t:'haul',ti:dst};a.path=nestPath(nestAt(a.x,a.y),dst); return; } if(T.t==='haul'){ if(a.carry>0){ colGain(a.c,a.carry); nestFloat(a.x,a.y-10,'+'+a.carry+'🍞',N_COLS[a.c].terr);a.carry=0; } nestFree(a); return; } nestFree(a); } function nestUpdQueen(a){ const q=colQCh(a.c),cx=(q.x0+q.w/2)*NT,cy=(q.y0+q.h/2)*NT; nestGo(a,cx+Math.sin(nestT*0.006+a.c)*22,cy+Math.cos(nestT*0.004+a.c)*10,0.22); if(--a.eggT>0)return; // każda królowa ma własny zegar a.eggT=300; let pop=0; for(const o of nestAnts)if(o.c===a.c)pop++; for(const e of nestEggs)if(e.c===a.c)pop++; const cap=a.c===0?nestPopCap():16; // rywale mają twardy limit, gracz rozbudowuje wylęgarnie if(colFood(a.c)<N_EGG_COST||pop>=cap)return; colPay(a.c,N_EGG_COST); const nur=a.c===0?nestChamOf('nursery'):[],tgt=nur.length?nur[0]:q; const t=tgt.tiles[(Math.random()*tgt.tiles.length)|0]; // Ty wybierasz kogo wychować; rywal w trybie najazdu przestawia się na żołnierzy const role=a.c===0?(nestRaise==='sold'?'sold':'work') :(nestCols[a.c].raid&&Math.random()<0.6?'sold':'work'); nestEggs.push({c:a.c,x:nestPX(t)+(Math.random()-0.5)*10,y:nestPY(t)+(Math.random()-0.5)*8,t:nur.length?420:840,role}); nestFloat(a.x,a.y-14,'🥚',N_COLS[a.c].terr); } function nestUpdSold(a){ // 🎯 cel: najbliższe zwierzę ALBO mrówka obcej kolonii — liczy się kto bliżej let tgt=null,bd=1e9; for(const f of nestFoes){const d=Math.hypot(f.x-a.x,f.y-a.y);if(d<bd){bd=d;tgt=f;}} for(const o of nestAnts){if(o.c===a.c||o.hp<=0)continue; const d=Math.hypot(o.x-a.x,o.y-a.y);if(d<bd){bd=d;tgt=o;}} const bar=a.c===0?nestChamOf('barracks').length:0; if(tgt&&bd<300){ if(bd<14){ a.ang=Math.atan2(tgt.y-a.y,tgt.x-a.x); if(a.cd<=0){ a.cd=30; let dmg=5.5*(bar?1.25:1); const ph=nestTraps.some(t=>t.ty==='pher'&&Math.hypot(nestPX(t.ti)-a.x,nestPY(t.ti)-a.y)<70); if(ph)dmg*=1.5; tgt.hp-=dmg;tgt.hit=8; nestPart(tgt.x,tgt.y,'#ff5a3c',5); } a.path=null; } else { if(--a.repath<=0||!a.path||!a.path.length){a.repath=22;a.path=nestPath(nestAt(a.x,a.y),nestAt(tgt.x,tgt.y));} if(nestFollow(a,0.95)===2)a.path=null; if(!a.path)nestGo(a,tgt.x,tgt.y,0.5); } return; } // brak celu w zasięgu let home; if(a.c!==0){ // 🤖 rywal: najazd prze na cel kolonii, inaczej pilnuje gniazda const C=nestCols[a.c]; home=(C.raid&&C.goal!=null)?C.goal:colQCh(a.c).tiles[2]; } else { // gracz: punkt zbiórki / feromon / koszary / królowa home=nestRally; if(home===null){ const ph=nestTraps.find(t=>t.ty==='pher'); if(ph)home=ph.ti; else{const b=nestChamOf('barracks');home=b.length?b[0].tiles[(b[0].tiles.length/2)|0]:nestChs[0].tiles[(nestChs[0].tiles.length/2)|0];} } } const d=Math.hypot(nestPX(home)-a.x,nestPY(home)-a.y); if(d>26){ if(--a.repath<=0||!a.path||!a.path.length){a.repath=34;a.path=nestPath(nestAt(a.x,a.y),home);} if(nestFollow(a,0.8)===2)a.path=null; } else if(nestT%40===0){a.ang=Math.random()*Math.PI*2;} else{const nx=a.x+Math.cos(a.ang)*0.25,ny=a.y+Math.sin(a.ang)*0.25;if(nestWalk(nestAt(nx,ny))){a.x=nx;a.y=ny;a.wk+=0.25;}} } // ── WROGOWIE ────────────────────────────────────────────────────── function nestSpawnWave(){ nestWave++; const cnt=1+Math.floor(nestWave*0.8); const pool=N_FOES.filter(f=>f.w<=nestWave); for(let k=0;k<cnt;k++){ const ty=pool[(Math.random()*pool.length)|0]; const side=Math.random()<0.5?0:1; const x=side?12+Math.random()*60:W-12-Math.random()*60; const f={ty,x,y:(N_SKY-1)*NT+8,hp:ty.hp*(1+nestWave*0.16),mhp:ty.hp*(1+nestWave*0.16),cd:0,hit:0,lure:false,chew:-1}; nestFoes.push(f); } nestSay('🌊 FALA '+nestWave+' — '+cnt+' wrogów wchodzi do lochu!',1); nestFloat(W/2,44,'🌊 FALA '+nestWave,'#ff6b4a'); } function nestUpdFoe(f){ if(f.hit>0)f.hit--; if(f.cd>0)f.cd--; const ti=nestAt(f.x,f.y); // 🍄 pułapka grzybowa — zarodniki: obrażenia + spowolnienie let slow=1; const tr=nestTraps.find(t=>t.ti===ti&&t.ty==='fung'); if(tr){f.hp-=0.42;slow=0.45;tr.chg--;if(nestT%5===0)nestPart(f.x,f.y-4,'#7ee081',1,0.8);} // atak na mrówki w zwarciu let tgt=null,bd=1e9; for(const a of nestAnts){const d=Math.hypot(a.x-f.x,a.y-f.y);if(d<bd){bd=d;tgt=a;}} if(tgt&&bd<15){ if(f.cd<=0){f.cd=44;tgt.hp-=f.ty.dmg;tgt.hit=8;nestPart(tgt.x,tgt.y,'#ff2200',5); if(tgt.role==='queen'&&nestT%2===0)nestSay('👑 KRÓLOWA ATAKOWANA!',1);} f.ang=Math.atan2(tgt.y-f.y,tgt.x-f.x); return; } // 💨 feromon zwabia — inaczej idą po królową f.lure=false; if(nestFieldP&&nestFieldP[ti]<40)f.lure=true; const fld=(f.lure&&nestFieldP)?nestFieldP:nestFieldQ; if(!fld)return; let best=-1,bv=fld[ti]; nestNb(ti,_nb); for(let k=0;k<_nb.length;k++){const n=_nb[k];if(fld[n]<bv){bv=fld[n];best=n;}} if(best<0)return; if(nestSolid(nestG[best])){ // 🦷 przegryza ścianę — BETON trzyma najdłużej if(f.chew!==best){f.chew=best;} nestHp[best]+=0.42*f.ty.chew; if(nestT%9===0)nestPart(nestPX(best)+(Math.random()-0.5)*12,nestPY(best)+(Math.random()-0.5)*12,nestG[best]===N_CRETE?'#b9a07a':'#6b4423',1,1); f.ang=Math.atan2(nestPY(best)-f.y,nestPX(best)-f.x); if(nestHp[best]>=nestMaxHp(nestG[best])){ nestG[best]=N_TUN;nestHp[best]=0;nestDes[best]=0;nestDirty=true;f.chew=-1; nestPart(nestPX(best),nestPY(best),'#6b4423',10); } return; } nestGo(f,nestPX(best),nestPY(best),f.ty.sp*slow); } // ── KROK SYMULACJI ──────────────────────────────────────────────── function nestStep(){ nestT++; if(nestDirty||--nestFieldT<=0){nestFields();nestDirty=false;} // fala if(--nestWaveT<=0){nestSpawnWave();nestWaveT=(55-Math.min(20,nestWave))*60;} // okruchy na powierzchni if(--nestCrumbT<=0){nestCrumbT=380;nestSpawnCrumb();} // jedzenie: mrówki jedzą // 🍞 każda kolonia je z WŁASNEGO zapasu — głód osłabia ją niezależnie od reszty for(let ci=0;ci<nestCols.length;ci++){ if(!colAlive(ci))continue; let pop=0;for(const a of nestAnts)if(a.c===ci)pop++; if(ci===0){ nestFood=Math.max(0,nestFood-pop*0.0016); if(nestFood<=0&&nestT%180===0&&pop>1){ const w=nestAnts.find(a=>a.c===0&&a.role!=='queen'); if(w){w.hp-=6;nestSay('🍞 GŁÓD! Mrówki słabną — postaw farmę grzybów',1);}} } else { const C=nestCols[ci]; C.food=Math.max(0,C.food-pop*0.0016); if(C.food<=0&&nestT%180===0&&pop>1){ const w=nestAnts.find(a=>a.c===ci&&a.role!=='queen'); if(w)w.hp-=6;} } } // 🤖 kierownicy obcych kolonii — cel przeliczany rzadko, bo w środku siedzą BFS-y for(let ci=1;ci<nestCols.length;ci++){ const C=nestCols[ci]; if(!colAlive(ci))continue; if(--C.aiT<=0){C.aiT=240;C.goal=nestAiGoal(ci);} } // jaja → mrówki for(let i=nestEggs.length-1;i>=0;i--){const e=nestEggs[i]; if(--e.t<=0){nestAnts.push(nestNewAnt(e.role,e.x,e.y,e.c|0));nestEggs.splice(i,1); nestFloat(e.x,e.y-10,e.role==='sold'?'⚔️':'🐜',N_COLS[e.c|0].terr);nestPart(e.x,e.y,'#fff0b0',10);}} // mrówki for(const a of nestAnts)nestUpdAnt(a); for(let i=nestAnts.length-1;i>=0;i--){const a=nestAnts[i]; if(a.hp<=0){ nestPart(a.x,a.y,N_COLS[a.c].bd,12);nestFree(a); if(a.role==='queen'){ if(a.c===0){nestOver=1;nestWin=1;nestSay('💀 Twoja królowa zginęła — mrowisko upadło');nestSaveBest();} else{nestSay('👑 '+N_COLS[a.c].n+' stracili królową!');nestFloat(a.x,a.y-20,'👑💀',N_COLS[a.c].terr);} } else if(a.c!==0)nestKills++; nestAnts.splice(i,1); }} // 🏆 dominacja — padły wszystkie obce królowe if(!nestOver&&nestCols.length>1&&!nestCols.some((C,ci)=>ci>0&&colAlive(ci))){ nestOver=1;nestWin=2;nestSay('🏆 DOMINACJA — cały loch należy do Ciebie!');nestSaveBest();} if(!nestOver&&!nestAnts.some(a=>a.c===0)){nestOver=1;nestWin=1;nestSaveBest();} // wrogowie for(const f of nestFoes)nestUpdFoe(f); for(let i=nestFoes.length-1;i>=0;i--){const f=nestFoes[i]; if(f.hp<=0){nestPart(f.x,f.y,'#ff5a3c',16);nestKills++; nestMin=Math.min(nestCap(),nestMin+3);nestFloat(f.x,f.y-10,'+3🪨','#d8c9a8');nestFoes.splice(i,1);}} // pułapki for(let i=nestTraps.length-1;i>=0;i--){const t=nestTraps[i]; if(t.ty==='fung'&&t.chg<=0){nestTraps.splice(i,1);nestSay('🍄 Pułapka zużyta');continue;} if(t.ty==='pher'&&--t.t<=0){nestTraps.splice(i,1);nestDirty=true;}} // cząstki i napisy for(let i=nestPt.length-1;i>=0;i--){const q=nestPt[i];q.x+=q.vx;q.y+=q.vy;q.vy+=0.06;q.vx*=0.96;if(--q.l<=0)nestPt.splice(i,1);} for(let i=nestFl.length-1;i>=0;i--){const q=nestFl[i];q.y-=0.42;if(--q.l<=0)nestFl.splice(i,1);} if(nestWarn>0)nestWarn--; } function nestSaveBest(){ if(nestWave>nestBest){nestBest=nestWave;localStorage.setItem('md_nestBest',String(nestBest));} } // ── WEJŚCIE: przeciąganie prostokątem (RTS) ─────────────────────── function nestInput(){ const paint=nestTool==='dig'||nestTool==='crete'||nestTool==='erase'; if(shootHeld&&!nestDown){ nestDown=true; if(mouse.y<NGH&&paint&&!nestOrder)nestDrag={x0:(mouse.x/NT)|0,y0:(mouse.y/NT)|0,x1:(mouse.x/NT)|0,y1:(mouse.y/NT)|0}; } else if(shootHeld&&nestDrag){ nestDrag.x1=Math.max(0,Math.min(NC-1,(mouse.x/NT)|0)); nestDrag.y1=Math.max(0,Math.min(NR-1,(mouse.y/NT)|0)); } else if(!shootHeld&&nestDown){ nestDown=false; if(nestDrag){ const x0=Math.min(nestDrag.x0,nestDrag.x1),x1=Math.max(nestDrag.x0,nestDrag.x1); const y0=Math.min(nestDrag.y0,nestDrag.y1),y1=Math.max(nestDrag.y0,nestDrag.y1); for(let y=y0;y<=y1;y++)for(let x=x0;x<=x1;x++)nestPaint(x,y,true); nestDrag=null; } } } function nestPaint(cx,cy,quiet){ if(cx<0||cy<0||cx>=NC||cy>=NR)return; const i=nestIdx(cx,cy),t=nestG[i]; if(nestTool==='dig'){ if(!nestSolid(t)){if(!quiet)nestSay('⛏️ Kopać można tylko w ziemi i skale',1);return;} if(t===N_CRETE){if(!quiet)nestSay('🧱 Beton jest zbyt twardy do kopania',1);return;} nestDes[i]=1; } else if(nestTool==='crete'){ if(t===N_ROCK){if(!quiet)nestSay('🪨 Skały nie da się zabetonować',1);return;} if(t===N_CRETE||t===N_AIR)return; if(nestChamAt(i)){if(!quiet)nestSay('🏛️ To komora — nie betonuj jej',1);return;} nestDes[i]=2; } else if(nestTool==='trap'||nestTool==='pher'){ if(t!==N_TUN){if(!quiet)nestSay('Pułapkę stawia się w wykopanym tunelu',1);return;} if(nestTraps.some(x=>x.ti===i)){if(!quiet)nestSay('Tu już jest pułapka',1);return;} nestDes[i]=nestTool==='trap'?3:4; } else if(nestTool==='cham'){ if(quiet)return; // komory stawia się pojedynczo (nie przeciąganiem) nestPlaceCham(cx,cy); } else if(nestTool==='erase'){ nestDes[i]=0;nestHp[i]=0; const ch=nestChamAt(i); if(ch&&ch.ty!=='queen'&&!ch.done){ const info=N_CHAMS.find(c=>c.id===ch.ty); if(info){nestMin+=info.m;nestFood+=info.f;} for(const ti of ch.tiles)if(nestDes[ti]===1)nestDes[ti]=0; nestChs.splice(nestChs.indexOf(ch),1); if(!quiet)nestSay('🧹 Plan komory anulowany — surowce zwrócone'); } } } function nestPlaceCham(cx,cy){ const info=N_CHAMS.find(c=>c.id===nestCham); if(!info)return; const x0=cx-1,y0=cy-1; if(x0<0||y0<N_SKY||x0+3>NC||y0+3>NR){nestSay('🏛️ Za blisko krawędzi lochu',1);return;} const tiles=nestTiles(x0,y0,3,3); for(const ti of tiles){ if(nestChamAt(ti)){nestSay('🏛️ Tu już jest inna komora',1);return;} if(nestG[ti]===N_CRETE){nestSay('🧱 Najpierw usuń beton',1);return;} } if(nestMin<info.m||nestFood<info.f){nestSay('❌ Brak surowców: '+info.ic+' '+info.n+' kosztuje 🪨'+info.m+' 🍞'+info.f,1);return;} nestMin-=info.m;nestFood-=info.f; nestChs.push({ty:info.id,x0,y0,w:3,h:3,done:false,prog:0,tiles}); for(const ti of tiles)if(nestSolid(nestG[ti]))nestDes[ti]=1; // mrówki najpierw wykopią nestSay(info.ic+' '+info.n+': mrówki wykopią i zbudują'); nestFloat((x0+1.5)*NT,y0*NT,'🏛️ plan','#ffd24a'); } // ── KLIKNIĘCIA ──────────────────────────────────────────────────── const N_TOOLS=[ {id:'dig', ic:'⛏️',n:'Kop', h:'Zaznacz ziemię — mrówki wykopią tunel (przeciągaj myszą)'}, {id:'crete',ic:'🧱',n:'Beton', h:'Mrówkobeton: 🪨'+N_CRETE_COST+'/kafel — wróg gryzie go 5× dłużej'}, {id:'trap', ic:'🍄',n:'Grzyb', h:'Pułapka zarodnikowa: 🍞'+N_TRAP_COST+' — rani i spowalnia wroga'}, {id:'pher', ic:'💨',n:'Feromon',h:'Wabik: 🍞'+N_PHER_COST+' — ściąga wrogów i wzmacnia żołnierzy'}, {id:'cham', ic:'🏛️',n:'Komora', h:'Wybierz typ komory i kliknij w gnieździe (3×3)'}, {id:'erase',ic:'🧹',n:'Zetrzyj',h:'Kasuje oznaczenia i plany komór'}, ]; function nestBtnRects(){ const r=[];const bw=104,bh=30,gp=6;let x=8; for(const t of N_TOOLS){r.push({x,y:486,w:bw,h:bh,tool:t});x+=bw+gp;} return r; } function handleNestClick(cx,cy){ if(nestOver){ if(isOR(cx,cy,W/2-210,H/2+56,190,44)){startNest();return;} if(isOR(cx,cy,W/2+20,H/2+56,190,44)){nestSaveBest();gs='menu';return;} return; } // ── pasek narzędzi ── if(cy>=NGH){ for(const b of nestBtnRects())if(isOR(cx,cy,b.x,b.y,b.w,b.h)){nestTool=b.tool.id;nestOrder=null;nestSay(b.tool.ic+' '+b.tool.h);return;} if(isOR(cx,cy,8,520,104,28)){nestOrder=nestOrder==='rally'?null:'rally';nestSay(nestOrder?'⚔️ Kliknij miejsce zbiórki żołnierzy':'Rozkaz anulowany');return;} if(isOR(cx,cy,118,520,104,28)){nestRally=null;nestSay('🏠 Żołnierze wracają do gniazda');return;} if(isOR(cx,cy,228,520,124,28)){nestRaise=nestRaise==='work'?'sold':'work';nestSay(nestRaise==='work'?'🐜 Królowa wychowuje robotnice':'⚔️ Królowa wychowuje żołnierzy');return;} if(isOR(cx,cy,358,520,104,28)){nestPaused=!nestPaused;return;} if(isOR(cx,cy,468,520,80,28)){nestSpeed=nestSpeed===1?2:nestSpeed===2?3:1;return;} if(isOR(cx,cy,W-96,520,88,28)){nestSaveBest();gs='menu';return;} return; } // ── wybór typu komory (pasek nad UI) ── if(nestTool==='cham'&&cy>=NGH-34&&cy<NGH){ N_CHAMS.forEach((c,i)=>{const bx=8+i*172;if(isOR(cx,cy,bx,NGH-32,168,28)){nestCham=c.id;nestSay(c.ic+' '+c.n+': '+c.d+' (🪨'+c.m+' 🍞'+c.f+')');}}); return; } // ── rozkaz zbiórki ── if(nestOrder==='rally'){ const i=nestAt(cx,cy); if(!nestWalk(i)){nestSay('⚔️ Zbiórka tylko w wykopanym tunelu',1);return;} nestRally=i;nestOrder=null;nestSay('⚔️ Żołnierze maszerują na miejsce zbiórki'); nestFloat(cx,cy-10,'⚔️','#ff6b4a'); return; } nestPaint((cx/NT)|0,(cy/NT)|0,false); } // ── RYSOWANIE ───────────────────────────────────────────────────── function nestHash(x,y){const h=Math.sin(x*127.1+y*311.7)*43758.5453;return h-Math.floor(h);} function drawNest(){ // ── niebo ── const sky=ctx.createLinearGradient(0,0,0,N_SKY*NT); sky.addColorStop(0,'#12203a');sky.addColorStop(1,'#2c3550'); ctx.fillStyle=sky;ctx.fillRect(0,0,W,N_SKY*NT); // ── kafle ── for(let y=0;y<NR;y++)for(let x=0;x<NC;x++){ const i=nestIdx(x,y),t=nestG[i],px=x*NT,py=y*NT; if(t===N_AIR)continue; if(t===N_TUN){ ctx.fillStyle='#14100b';ctx.fillRect(px,py,NT,NT); const h=nestHash(x,y); ctx.fillStyle='rgba(0,0,0,0.35)';ctx.fillRect(px+h*4,py+h*3,NT-h*8,NT-h*6); const o=nestOwn[i]; // 🏴 barwa właściciela terenu if(o){ctx.save();ctx.globalAlpha=0.18;ctx.fillStyle=N_COLS[o-1].terr;ctx.fillRect(px,py,NT,NT);ctx.restore();} continue; } if(t===N_EARTH){ const h=nestHash(x,y),dk=Math.min(26,y*1.1); ctx.fillStyle=`rgb(${88-dk+h*16|0},${58-dk*0.7+h*12|0},${34-dk*0.4+h*8|0})`; ctx.fillRect(px,py,NT,NT); ctx.fillStyle='rgba(0,0,0,0.16)'; ctx.fillRect(px+2+h*12,py+3+h*10,3,2);ctx.fillRect(px+12-h*8,py+13-h*6,2,3); } else if(t===N_ROCK){ const h=nestHash(x,y); ctx.fillStyle=`rgb(${86+h*22|0},${88+h*22|0},${98+h*22|0})`;ctx.fillRect(px,py,NT,NT); ctx.fillStyle='rgba(255,255,255,0.10)';ctx.beginPath();ctx.moveTo(px+3,py+NT-4);ctx.lineTo(px+NT*0.5,py+3);ctx.lineTo(px+NT-3,py+NT-5);ctx.closePath();ctx.fill(); } else if(t===N_CRETE){ ctx.fillStyle='#9a8259';ctx.fillRect(px,py,NT,NT); ctx.fillStyle='#b0966a';ctx.fillRect(px+1,py+1,NT-2,NT/2-2); ctx.strokeStyle='rgba(60,44,22,0.55)';ctx.lineWidth=1; ctx.beginPath();ctx.moveTo(px,py+NT/2);ctx.lineTo(px+NT,py+NT/2); ctx.moveTo(px+((x+y)%2?NT/2:0),py);ctx.lineTo(px+((x+y)%2?NT/2:0),py+NT/2); ctx.moveTo(px+((x+y)%2?0:NT/2),py+NT/2);ctx.lineTo(px+((x+y)%2?0:NT/2),py+NT);ctx.stroke(); } // postęp kucia/gryzienia if(nestHp[i]>0){const f=Math.min(1,nestHp[i]/nestMaxHp(t)); ctx.fillStyle=`rgba(0,0,0,${0.42*f})`;ctx.fillRect(px,py,NT,NT); ctx.strokeStyle=`rgba(255,220,120,${0.5*f})`;ctx.lineWidth=1;ctx.strokeRect(px+2.5,py+2.5,NT-5,NT-5);} } // ── linia trawy ── ctx.fillStyle='#3c6b32';ctx.fillRect(0,N_SKY*NT-5,W,6); ctx.strokeStyle='#4f8a41';ctx.lineWidth=2;ctx.beginPath(); for(let x=0;x<W;x+=7){ctx.moveTo(x,N_SKY*NT-4);ctx.lineTo(x+3*(nestHash(x,1)-0.5),N_SKY*NT-9-nestHash(x,2)*4);}ctx.stroke(); // ── oznaczenia gracza ── for(let i=0;i<nestDes.length;i++){ const d=nestDes[i];if(!d)continue; const px=(i%NC)*NT,py=((i/NC)|0)*NT; const col=d===1?'#ffd24a':d===2?'#d8c9a8':d===3?'#7ee081':'#ff86d0'; ctx.save();ctx.globalAlpha=0.30+Math.sin(nestT*0.07+i)*0.07;ctx.fillStyle=col;ctx.fillRect(px,py,NT,NT);ctx.restore(); ctx.strokeStyle=col;ctx.lineWidth=1.4;ctx.setLineDash([3,3]);ctx.strokeRect(px+1,py+1,NT-2,NT-2);ctx.setLineDash([]); tx(d===1?'⛏️':d===2?'🧱':d===3?'🍄':'💨',px+NT/2,py+NT/2,11,'#fff','center'); } // ── komory ── for(const c of nestChs){ const x=c.x0*NT,y=c.y0*NT,w=c.w*NT,h=c.h*NT; const info=c.ty==='queen'?{ic:'👑',n:'Królowa'}:N_CHAMS.find(k=>k.id===c.ty); ctx.save(); if(c.done){ const qc=c.ty==='queen'?N_COLS[c.c|0].terr:'#5adcff'; // 🏴 komnata w barwie właściciela ctx.globalAlpha=0.20;ctx.fillStyle=qc;ctx.fillRect(x,y,w,h); ctx.globalAlpha=1;ctx.strokeStyle=qc;ctx.lineWidth=2;ctx.strokeRect(x+1,y+1,w-2,h-2); } else { ctx.globalAlpha=0.16;ctx.fillStyle='#ffd24a';ctx.fillRect(x,y,w,h); ctx.globalAlpha=1;ctx.strokeStyle='#ffd24a';ctx.lineWidth=1.6;ctx.setLineDash([5,4]);ctx.strokeRect(x+1,y+1,w-2,h-2);ctx.setLineDash([]); ctx.fillStyle='rgba(0,0,0,0.55)';ctx.fillRect(x+4,y+h-9,w-8,5); ctx.fillStyle='#7ee081';ctx.fillRect(x+4,y+h-9,(w-8)*c.prog,5); } ctx.restore(); if(info)tx(info.ic,x+w/2,y+10,13,'#fff','center'); } // ── pułapki ── for(const t of nestTraps){ const px=nestPX(t.ti),py=nestPY(t.ti); if(t.ty==='fung'){ ctx.save();ctx.globalAlpha=0.28+Math.sin(nestT*0.09)*0.08;ctx.fillStyle='#7ee081'; ctx.beginPath();ctx.arc(px,py,NT*0.62,0,Math.PI*2);ctx.fill();ctx.restore(); tx('🍄',px,py,15,'#fff','center'); ctx.fillStyle='rgba(0,0,0,0.5)';ctx.fillRect(px-9,py+7,18,3); ctx.fillStyle='#7ee081';ctx.fillRect(px-9,py+7,18*Math.max(0,t.chg/320),3); } else { ctx.save();ctx.globalAlpha=0.20+Math.sin(nestT*0.05)*0.07;ctx.fillStyle='#ff86d0'; ctx.beginPath();ctx.arc(px,py,NT*1.9,0,Math.PI*2);ctx.fill();ctx.restore(); tx('💨',px,py,15,'#fff','center'); } } // ── punkt zbiórki ── if(nestRally!==null){ const px=nestPX(nestRally),py=nestPY(nestRally); ctx.save();ctx.strokeStyle='#ff6b4a';ctx.lineWidth=2;ctx.globalAlpha=0.6+Math.sin(nestT*0.1)*0.3; ctx.beginPath();ctx.arc(px,py,10+Math.sin(nestT*0.1)*3,0,Math.PI*2);ctx.stroke();ctx.restore(); tx('⚔️',px,py,12,'#fff','center'); } // ── okruchy ── for(const c of nestCrumbs)tx('🌿',c.x,c.y,13,'#9ee493','center'); // ── jaja ── for(const e of nestEggs){ ctx.fillStyle='#fff0c8';ctx.beginPath();ctx.ellipse(e.x,e.y,3.4,4.6,0,0,Math.PI*2);ctx.fill(); ctx.strokeStyle='rgba(160,120,60,0.6)';ctx.lineWidth=0.8;ctx.stroke(); } // ── mrówki i wrogowie ── for(const a of nestAnts)nestDrawAnt(a); for(const f of nestFoes)nestDrawFoe(f); // ── cząstki / napisy ── for(const q of nestPt){ctx.globalAlpha=Math.min(1,q.l/18);ctx.fillStyle=q.col;ctx.fillRect(q.x-1,q.y-1,2.4,2.4);} ctx.globalAlpha=1; for(const q of nestFl){ctx.globalAlpha=Math.min(1,q.l/40);tx(q.t,q.x,q.y,13,q.col,'center',true);} ctx.globalAlpha=1; // ── podgląd narzędzia pod kursorem ── if(mouse.y<NGH&&!nestOver){ if(nestDrag){ const x0=Math.min(nestDrag.x0,nestDrag.x1)*NT,x1=(Math.max(nestDrag.x0,nestDrag.x1)+1)*NT; const y0=Math.min(nestDrag.y0,nestDrag.y1)*NT,y1=(Math.max(nestDrag.y0,nestDrag.y1)+1)*NT; ctx.save();ctx.globalAlpha=0.22;ctx.fillStyle='#ffd24a';ctx.fillRect(x0,y0,x1-x0,y1-y0);ctx.restore(); ctx.strokeStyle='#ffd24a';ctx.lineWidth=2;ctx.strokeRect(x0,y0,x1-x0,y1-y0); } else { const cx=(mouse.x/NT|0)*NT,cy=(mouse.y/NT|0)*NT; const sz=nestTool==='cham'?3:1,off=nestTool==='cham'?NT:0; ctx.save();ctx.globalAlpha=0.5;ctx.strokeStyle=nestOrder==='rally'?'#ff6b4a':'#ffd24a';ctx.lineWidth=2; ctx.strokeRect(cx-off,cy-off,NT*sz,NT*sz);ctx.restore(); } } // ── HUD nad ziemią ── nestHUD(); // ── pauza ── if(nestPaused&&!nestOver){ ctx.save();ctx.globalAlpha=0.26;ctx.fillStyle='#000';ctx.fillRect(0,0,W,NGH);ctx.restore(); tx('⏸ PAUZA — wydawaj rozkazy spokojnie',W/2,NGH/2,26,'#ffe08a','center',true); tx('SPACJA = wznów · 1–6 = narzędzia',W/2,NGH/2+28,13,'#cfa','center'); } nestBar(); if(nestOver)nestOverScreen(); } function nestDrawAnt(a){ const q=a.role==='queen',s=q?1.9:a.role==='sold'?1.3:1; ctx.save();ctx.translate(a.x,a.y);ctx.rotate(a.ang); const P=N_COLS[a.c]||N_COLS[0]; // 🏴 barwy własnej kolonii const bd=q?P.qbd:a.role==='sold'?P.sbd:P.bd; const lg=q?P.qlg:a.role==='sold'?P.slg:P.lg; // nogi ctx.strokeStyle=lg;ctx.lineWidth=1.1*s; for(let k=-1;k<2;k++){const ph=Math.sin(a.wk*0.35+k*1.4)*1.9; ctx.beginPath();ctx.moveTo(k*2.4*s,0);ctx.lineTo(k*2.4*s-1*s,-4.6*s-ph);ctx.moveTo(k*2.4*s,0);ctx.lineTo(k*2.4*s-1*s,4.6*s+ph);ctx.stroke();} // odwłok / tułów / głowa ctx.fillStyle=bd; ctx.beginPath();ctx.ellipse(-4.6*s,0,3.5*s,2.7*s,0,0,Math.PI*2);ctx.fill(); ctx.beginPath();ctx.ellipse(-0.4*s,0,2.3*s,2.0*s,0,0,Math.PI*2);ctx.fill(); ctx.beginPath();ctx.ellipse(3.3*s,0,2.4*s,2.1*s,0,0,Math.PI*2);ctx.fill(); // czułki ctx.strokeStyle=lg;ctx.lineWidth=0.9*s; ctx.beginPath();ctx.moveTo(4.6*s,-1.1*s);ctx.lineTo(7.4*s,-3.2*s);ctx.moveTo(4.6*s,1.1*s);ctx.lineTo(7.4*s,3.2*s);ctx.stroke(); if(a.role==='sold'){ // żuwaczki ctx.strokeStyle='#f0c987';ctx.lineWidth=1.3*s; ctx.beginPath();ctx.moveTo(5.2*s,-1.4*s);ctx.lineTo(8*s,-0.5*s);ctx.moveTo(5.2*s,1.4*s);ctx.lineTo(8*s,0.5*s);ctx.stroke();} ctx.restore(); if(a.carry>0)tx('🌿',a.x,a.y-9,10,'#9ee493','center'); if(q)tx('👑',a.x,a.y-14,13,'#ffd24a','center'); if(a.hit>0){ctx.save();ctx.globalAlpha=a.hit/8;ctx.fillStyle='#ff2200';ctx.beginPath();ctx.arc(a.x,a.y,9*s,0,Math.PI*2);ctx.fill();ctx.restore();} if(a.hp<a.mhp){const w=q?30:14; ctx.fillStyle='rgba(0,0,0,0.6)';ctx.fillRect(a.x-w/2,a.y-(q?22:11),w,3); ctx.fillStyle=a.hp/a.mhp>0.4?'#7ee081':'#ff5a3c';ctx.fillRect(a.x-w/2,a.y-(q?22:11),w*Math.max(0,a.hp/a.mhp),3);} } function nestDrawFoe(f){ ctx.save(); if(f.hit>0){ctx.globalAlpha=0.55+Math.random()*0.45;} tx(f.ty.ic,f.x,f.y,f.ty.boss?24:17,'#fff','center'); ctx.restore(); const w=f.ty.boss?32:18; ctx.fillStyle='rgba(0,0,0,0.6)';ctx.fillRect(f.x-w/2,f.y-(f.ty.boss?17:12),w,3); ctx.fillStyle='#ff5a3c';ctx.fillRect(f.x-w/2,f.y-(f.ty.boss?17:12),w*Math.max(0,f.hp/f.mhp),3); } function nestHUD(){ const s=Math.max(0,Math.ceil(nestWaveT/60)); const mm=(s/60|0),ss=s%60; ctx.save();ctx.globalAlpha=0.55;ctx.fillStyle='#000';rr(6,6,246,34,8,'#000',null);ctx.restore(); tx('🌊 Fala '+nestWave+' ⏳ '+mm+':'+(ss<10?'0':'')+ss,14,17,13,nestWaveT<300?'#ff6b4a':'#ffe08a','left',true); tx('👑 '+(nestQueen?Math.max(0,Math.ceil(nestQueen.hp)):0)+' 💀 '+nestKills+' 🏆 rekord: fala '+nestBest,14,32,11,'#cbb','left'); if(nestFoes.length){ ctx.save();ctx.globalAlpha=0.55;rr(W-140,6,134,22,8,'#3a0d0d',null);ctx.restore(); tx('⚠️ Zwierzyna: '+nestFoes.length,W-134,17,12,'#ff8a6a','left',true); } // 🏴 PASEK TERENU — kto ile lochu trzyma, plus liczebność każdej kolonii {const t=nestTerr(),tot=Math.max(1,t[0]+t[1]+t[2]); const bx=266,bw=W-266-152,by=8; ctx.save();ctx.globalAlpha=0.5;rr(bx-6,6,bw+12,34,8,'#000',null);ctx.restore(); let px=bx; for(let ci=0;ci<nestCols.length;ci++){ const seg=bw*(t[ci]/tot); ctx.fillStyle=N_COLS[ci].terr;ctx.fillRect(px,by+13,seg,9);px+=seg;} ctx.strokeStyle='rgba(255,255,255,0.22)';ctx.lineWidth=1;ctx.strokeRect(bx,by+13,bw,9); const pop=[0,0,0];for(const a of nestAnts)pop[a.c]++; for(let ci=0;ci<nestCols.length;ci++){ const dead=!colAlive(ci); tx(N_COLS[ci].ic+' '+(dead?'💀':pop[ci]+'🐜 '+Math.round(100*t[ci]/tot)+'%'), bx+ci*(bw/3),by+3,10,dead?'#6a6a6a':N_COLS[ci].terr,'left',true);} } } function nestBar(){ // ── pasek wyboru komory (nad UI) ── if(nestTool==='cham'){ ctx.save();ctx.globalAlpha=0.9;rr(4,NGH-36,W-8,34,8,'#1a1208','#5adcff',1.5);ctx.restore(); N_CHAMS.forEach((c,i)=>{ const bx=8+i*172,on=nestCham===c.id; rr(bx,NGH-32,168,28,7,on?'#1c4a5a':'#2a1f10',on?'#5adcff':'#6b5a34',on?2:1); tx(c.ic+' '+c.n,bx+8,NGH-18,12,on?'#dff':'#c8b68a','left',on); tx('🪨'+c.m+' 🍞'+c.f,bx+160,NGH-18,10,'#9c8a60','right'); }); } // ── tło paska ── ctx.fillStyle='#120c06';ctx.fillRect(0,NGH,W,H-NGH); ctx.strokeStyle='#3a2a14';ctx.lineWidth=2;ctx.beginPath();ctx.moveTo(0,NGH+1);ctx.lineTo(W,NGH+1);ctx.stroke(); // ── narzędzia ── for(const b of nestBtnRects()){ const on=nestTool===b.tool.id,hov=isOR(mouse.x,mouse.y,b.x,b.y,b.w,b.h); rr(b.x,b.y,b.w,b.h,8,on?'#5a3a10':(hov?'#2c2010':'#1d1509'),on?'#ffd24a':'#5a4526',on?2:1); tx(b.tool.ic+' '+b.tool.n,b.x+b.w/2,b.y+b.h/2,13,on?'#ffe08a':'#b9a682','center',on); } // ── rozkazy ── const ob=(x,y,w,h,lab,on,col)=>{const hov=isOR(mouse.x,mouse.y,x,y,w,h); rr(x,y,w,h,7,on?'#123a4a':(hov?'#241a0e':'#1a1408'),on?(col||'#5adcff'):'#4a3a20',on?2:1); tx(lab,x+w/2,y+h/2,12,on?(col||'#9fe8ff'):'#a8956a','center',on);}; ob(8,520,104,28,'⚔️ Zbiórka',nestOrder==='rally','#ff6b4a'); ob(118,520,104,28,'🏠 Odwrót',false); ob(228,520,124,28,nestRaise==='work'?'🥚 Wychów: 🐜':'🥚 Wychów: ⚔️',true,'#ffd24a'); ob(358,520,104,28,nestPaused?'▶ Wznów':'⏸ Pauza',nestPaused,'#ff6b4a'); ob(468,520,80,28,'⏩ ×'+nestSpeed,nestSpeed>1,'#7ee081'); ob(W-96,520,88,28,'🚪 Menu',false); // ── surowce + komunikat ── const pop=nestAnts.length,sol=nestAnts.filter(a=>a.role==='sold').length; const y=566; tx('🍞 '+Math.floor(nestFood)+'/'+nestCap(),12,y,15,nestFood<20?'#ff6b4a':'#ffd24a','left',true); tx('🪨 '+Math.floor(nestMin)+'/'+nestCap(),128,y,15,'#d8c9a8','left',true); tx('🐜 '+pop+'/'+nestPopCap(),248,y,15,'#e8b07a','left',true); tx('⚔️ '+sol,340,y,15,'#ff9a7a','left',true); tx('🥚 '+nestEggs.length,394,y,15,'#fff0b0','left',true); const fung=nestChamOf('fungus').length,nur=nestChamOf('nursery').length,st=nestChamOf('store').length,bar=nestChamOf('barracks').length; tx('🍄'+fung+' 🥚'+nur+' 📦'+st+' ⚔️'+bar,462,y,13,'#8fa8c8','left'); if(nestMsgT>0){ ctx.save();ctx.globalAlpha=Math.min(1,nestMsgT/40); tx(nestMsg,12,589,12.5,nestWarn>0?'#ff8a6a':'#9ee493','left'); ctx.restore(); } else tx('SPACJA = pauza · 1–6 = narzędzia · przeciągnij myszą = zaznacz obszar',12,589,11.5,'#6b5a3a','left'); } function nestOverScreen(){ ctx.save();ctx.globalAlpha=0.78;ctx.fillStyle='#000';ctx.fillRect(0,0,W,H);ctx.restore(); const won=nestWin===2; tx(won?'🏆 DOMINACJA':'💀 MROWISKO UPADŁO',W/2,H/2-70,34,won?'#ffd24a':'#ff6b4a','center',true); {const t=nestTerr(),tot=Math.max(1,t[0]+t[1]+t[2]); tx(won?'Obie obce królowe martwe — loch jest Twój.':'Twoja królowa zginęła. Kolonia rozpadła się.', W/2,H/2-40,15,'#ffe08a','center'); tx('Teren: '+Math.round(100*t[0]/tot)+'% · fal: '+nestWave+' · obce mrówki: '+nestKills, W/2,H/2-16,14,'#c8b68a','center');} tx('🏆 Rekord: fala '+nestBest,W/2,H/2+4,14,'#9ee493','center'); rr(W/2-210,H/2+56,190,44,10,'#5a3a10','#ffd24a',2);tx('🔄 Jeszcze raz',W/2-115,H/2+78,15,'#ffe08a','center',true); rr(W/2+20,H/2+56,190,44,10,'#1d1509','#8a7550',2);tx('🚪 Menu',W/2+115,H/2+78,15,'#c8b68a','center',true); } // ── PĘTLA TRYBU ─────────────────────────────────────────────────── function updNest(){ nestInput(); // zaznaczanie działa TAKŻE na pauzie (RTS z pauzą) if(nestMsgT>0)nestMsgT--; if(nestOver||nestPaused)return; for(let s=0;s<nestSpeed;s++)nestStep(); } // ── KLAWIATURA TRYBU (własny listener — nie ruszamy globalnego) ─── window.addEventListener('keydown',e=>{ if(gs!=='nest')return; if(e.key===' '){nestPaused=!nestPaused;e.preventDefault();} else if(e.key==='Escape'){nestSaveBest();gs='menu';} else if(e.key>='1'&&e.key<='6'){nestTool=N_TOOLS[+e.key-1].id;nestOrder=null;nestSay(N_TOOLS[+e.key-1].ic+' '+N_TOOLS[+e.key-1].h);} else if(e.key==='+'||e.key==='='){nestSpeed=Math.min(3,nestSpeed+1);} else if(e.key==='-'){nestSpeed=Math.max(1,nestSpeed-1);} }); // ── PĘTLA ───────────────────────────────────────────────────────── let _lastT=0,_accT=0; function loop(ts){ requestAnimationFrame(loop); if(typeof ts!=='number')ts=0; if(!_lastT)_lastT=ts; _accT+=ts-_lastT;_lastT=ts; if(_accT>100)_accT=100; if(gs!=='nest'){startNest();} // brak menu głównego w wersji samodzielnej → 🚪/ESC = nowe mrowisko let n=0; while(_accT>=16.6667&&n<5){_accT-=16.6667;updNest();n++;} while(clicks.length){const c=clicks.shift();handleNestClick(c.x,c.y);} ctx.fillStyle='#0a0400';ctx.fillRect(0,0,W,H); drawNest(); } startNest(); requestAnimationFrame(loop); </script> </body> </html>
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <title>🐜 Mrówcza Obrona — Tower Defense</title> <style> html,body{margin:0;height:100%;background:#07100a;color:#c8e6b0;font-family:'Segoe UI',sans-serif; display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;overflow:hidden} canvas{border:3px solid #2f5a2a;border-radius:8px;background:#0a1608;max-width:100vw;max-height:94vh; image-rendering:auto;touch-action:none;box-shadow:0 0 34px rgba(0,0,0,0.6)} .tip{font-size:12px;color:#5f8a52} </style> </head> <body> <canvas id="c" width="800" height="660"></canvas> <div class="tip">🐜 Mrówcza Obrona · wybierz mrówkę na dole → kliknij pole trawy · [1–6] wieże · [Spacja] fala · [Esc] odznacz</div> <script> // ══════════════════════════════════════════════════════════════════ // 🐜 MRÓWCZA OBRONA — tryb Tower Defense (osobny plik, prefiks atd*). // KROK 1: mapa. KROK 2 (ten): grywalny rdzeń — wrogowie na ścieżce, // 6 mrówek-wież, budowa za Pokarm, ULEPSZANIE wież, fale, boss, przegrana. // Reużywa API reszty gry (W,H,ctx,mouse,shootHeld,rr,tx,isOR,gs); łatwe do // wklejenia do index.html później (żadna nazwa nie zaczyna się jak istniejące). // ══════════════════════════════════════════════════════════════════ const C=document.getElementById('c'),ctx=C.getContext('2d'); const W=C.width,H=C.height; let gs='menu', frame=0; const mouse={x:0,y:0};let shootHeld=false;const clicks=[];const keyq=[]; function rr(x,y,w,h,r,fill,stroke,lw=2){ctx.beginPath();ctx.roundRect(x,y,w,h,r);if(fill){ctx.fillStyle=fill;ctx.fill();}if(stroke){ctx.strokeStyle=stroke;ctx.lineWidth=lw;ctx.stroke();}} function tx(s,x,y,sz,col,al='center',bold=false){ctx.font=`${bold?'bold ':''}${sz}px 'Segoe UI'`;ctx.fillStyle=col;ctx.textAlign=al;ctx.textBaseline='middle';ctx.fillText(s,x,y);} function isOR(mx,my,x,y,w,h){return mx>=x&&mx<=x+w&&my>=y&&my<=y+h;} function cl(v,lo,hi){return Math.max(lo,Math.min(hi,v));} function evPos(e){const r=C.getBoundingClientRect(),bw=3;return{x:(e.clientX-r.left-bw)*(W/(r.width-2*bw)),y:(e.clientY-r.top-bw)*(H/(r.height-2*bw))};} C.addEventListener('mousemove',e=>{const m=evPos(e);mouse.x=m.x;mouse.y=m.y;}); C.addEventListener('mousedown',e=>{if(e.button===0){const m=evPos(e);mouse.x=m.x;mouse.y=m.y;shootHeld=true;clicks.push(m);}}); window.addEventListener('mouseup',e=>{if(e.button===0)shootHeld=false;}); C.addEventListener('contextmenu',e=>e.preventDefault()); C.addEventListener('touchstart',e=>{e.preventDefault();const t=e.changedTouches[0],p=evPos(t);mouse.x=p.x;mouse.y=p.y;shootHeld=true;clicks.push(p);},{passive:false}); C.addEventListener('touchmove',e=>{e.preventDefault();const t=e.changedTouches[0],p=evPos(t);mouse.x=p.x;mouse.y=p.y;},{passive:false}); function _endT(e){e.preventDefault();shootHeld=false;} C.addEventListener('touchend',_endT,{passive:false});C.addEventListener('touchcancel',_endT,{passive:false}); window.addEventListener('keydown',e=>{keyq.push(e.key);}); // ── SIATKA ──────────────────────────────────────────────────────── const TILE=40, COLS=20, ROWS=15, MAPH=ROWS*TILE; // pole gry 800×600, pasek budowy pod spodem const atdIdx=(cx,cy)=>cy*COLS+cx; const atdPX=cx=>cx*TILE+TILE/2, atdPY=cy=>cy*TILE+TILE/2; function atdHash(x,y){const h=Math.sin(x*127.1+y*311.7)*43758.5453;return h-Math.floor(h);} function atdShade(hex,f){const n=parseInt(hex.slice(1),16);let r=(n>>16)&255,g=(n>>8)&255,b=n&255;const t=f>0?255:0,p=Math.abs(f);r=Math.round(r+(t-r)*p);g=Math.round(g+(t-g)*p);b=Math.round(b+(t-b)*p);return'rgb('+r+','+g+','+b+')';} // ── DANE: MAPY ──────────────────────────────────────────────────── // Każda mapa: własny kręty tor (odcinki prostopadłe), gniazdo/królowa, paleta, // PULA wrogów (tier0 słaby → wyżej groźniejsi) i WŁASNY BOSS (co 10 fal). const ATD_MAPS=[ {id:'forest',n:'Mrówczy Las',ic:'🌳',locked:false,grass:'#356b2b',accent:'#57923c',dirt:'#8a6038', deco:['🍄','🌿','🪨','🍄','🌱'],mood:'Cichy las pełen mchu i grzybów', path:[[-1,2],[4,2],[4,6],[9,6],[9,2],[14,2],[14,10],[6,10],[6,13],[17,13],[17,8]],queen:[18,7,2,2],spawn:[0,2], pool:['gasienica','zuk','komar','pajak','skorpion'],boss:'boss'}, {id:'mush',n:'Grzybowa Polana',ic:'🍄',locked:false,grass:'#4a6b3e',accent:'#c86b9a',dirt:'#8a6038', deco:['🍄','🍄','🌸','🍄','🌱'],mood:'Zarodniki unoszą się nad polaną', path:[[2,-1],[2,3],[8,3],[8,7],[2,7],[2,11],[15,11],[15,5],[17,5]],queen:[18,4,2,2],spawn:[2,0], pool:['gasienica','sporeling','komar','zuk'],boss:'bossMush'}, {id:'spider',n:'Pajęcza Jaskinia',ic:'🕷️',locked:false,grass:'#2c2740',accent:'#8a6bd0',dirt:'#3a3450', deco:['🕸️','🕷️','🪨','🕸️','🦇'],mood:'Pajęczyny lśnią w ciemności', path:[[-1,7],[3,7],[3,2],[9,2],[9,12],[13,12],[13,4],[17,4],[17,9]],queen:[18,8,2,2],spawn:[0,7], pool:['gasienica','pajak','venomSpider','komar'],boss:'bossWidow'}, {id:'desert',n:'Mrówcza Pustynia',ic:'🏜️',locked:false,grass:'#b39a5c',accent:'#e0c070',dirt:'#9a7c44', deco:['🌵','🦴','🪨','🌵','☀️'],mood:'Skwar i piasek po horyzont', path:[[1,-1],[1,4],[7,4],[7,10],[12,10],[12,3],[16,3],[16,10],[17,10]],queen:[18,9,2,2],spawn:[1,0], pool:['gasienica','sandmite','komar','skorpion'],boss:'bossScorp'}, {id:'volcano',n:'Wulkan',ic:'🌋',locked:false,grass:'#3c1c12',accent:'#ff5a1e',dirt:'#5a2a16', deco:['🌋','🔥','🪨','🔥','💥'],mood:'Magma bulgocze tuż pod stopami', path:[[-1,1],[5,1],[5,5],[2,5],[2,10],[10,10],[10,5],[14,5],[14,12],[17,12],[17,7]],queen:[18,6,2,2],spawn:[0,1], pool:['gasienica','komar','firebeetle','skorpion'],boss:'bossMagma'}, {id:'ice',n:'Lodowe Mrowisko',ic:'❄️',locked:false,grass:'#6f9ec0',accent:'#d0ecff',dirt:'#587f9c', deco:['❄️','🧊','🪨','❄️','☃️'],mood:'Lodowy oddech zamraża wszystko', path:[[4,-1],[4,2],[15,2],[15,6],[6,6],[6,10],[15,10],[15,13],[17,13],[17,8]],queen:[18,7,2,2],spawn:[4,0], pool:['gasienica','frostbug','komar','pajak'],boss:'bossFrost'}, ]; // ── DANE: WROGOWIE ──────────────────────────────────────────────── // hp/spd/bounty(Pokarm za ubicie)/leak(ile HP zabiera Królowej)/air/boss const ATD_ENE={ gasienica:{n:'Gąsienica',ic:'🐛',hp:20,spd:1.05,bounty:4,leak:1,col:'#8ac24a'}, zuk: {n:'Żuk', ic:'🪲',hp:78,spd:0.6, bounty:9,leak:2,col:'#5a7d3a'}, pajak: {n:'Pająk', ic:'🕷️',hp:34,spd:1.85,bounty:6,leak:1,col:'#7a4bd0'}, komar: {n:'Komar', ic:'🦟',hp:18,spd:1.5, bounty:7,leak:1,air:true,col:'#9fd0e0'}, skorpion: {n:'Skorpion', ic:'🦂',hp:190,spd:0.72,bounty:18,leak:3,col:'#d08a2a'}, boss: {n:'Król Pająków',ic:'👑',hp:1500,spd:0.5,bounty:220,leak:20,boss:true,summon:'pajak',col:'#b03adc'}, // 🗺️ tematyczni przeciwnicy poszczególnych map sporeling: {n:'Zarodnik', ic:'🍄',hp:34, spd:1.0, bounty:5, leak:1,col:'#d38ac0'}, venomSpider:{n:'Jadowity Pająk', ic:'🕷️',hp:46, spd:1.6, bounty:8, leak:1,col:'#6b3ad0'}, sandmite: {n:'Roztocz', ic:'🪳',hp:52, spd:1.15,bounty:7, leak:1,col:'#c8a24a'}, firebeetle: {n:'Ognisty Żuk', ic:'🪲',hp:110,spd:0.72,bounty:11,leak:2,col:'#ff6a2a'}, frostbug: {n:'Lodowy Świerszcz',ic:'🦗',hp:58, spd:1.05,bounty:8, leak:1,col:'#9fd8ff'}, // 👑 bossowie map (każda mapa ma swojego) bossMush: {n:'Grzybowy Matecznik',ic:'🍄',hp:1300,spd:0.5, bounty:200,leak:18,boss:true,summon:'sporeling', col:'#d38ac0'}, bossWidow:{n:'Czarna Wdowa', ic:'🕷️',hp:1700,spd:0.55,bounty:240,leak:20,boss:true,summon:'venomSpider',col:'#6b3ad0'}, bossScorp:{n:'Król Skorpionów', ic:'🦂',hp:1900,spd:0.6, bounty:260,leak:22,boss:true,summon:'sandmite', col:'#c8a24a'}, bossMagma:{n:'Władca Magmy', ic:'🌋',hp:2200,spd:0.5, bounty:300,leak:24,boss:true,summon:'firebeetle', col:'#ff6a2a'}, bossFrost:{n:'Lodowy Tytan', ic:'❄️',hp:2000,spd:0.5, bounty:280,leak:22,boss:true,summon:'frostbug', col:'#9fd8ff'}, }; // ── DANE: MRÓWKI-WIEŻE ──────────────────────────────────────────── // każdy poziom (0..4): d=obrażenia, r=zasięg, cd=przeładowanie(kl.), inc=dochód/tyk (zbieracz) // nazwy poziomów: bazowa → II → III → Elitarny → Królewski const ATD_TW={ woj: {n:'Wojownik',ic:'⚔️',rar:'common',col:'#c0392b',cost:100,up:[70,140,260,460],air:false,kind:'shot',proj:'#ffcf6b', d:[10,16,24,36,52],r:[74,80,86,92,100],cd:[34,30,26,22,18]}, luk: {n:'Łucznik',ic:'🏹',rar:'uncommon',col:'#3aa06b',cost:130,up:[90,180,320,560],air:true,kind:'shot',proj:'#e8f0c0', d:[8,13,20,30,44],r:[150,160,172,186,204],cd:[30,27,24,21,17]}, zb: {n:'Zbieracz',ic:'💰',rar:'common',col:'#e0a92b',cost:90,up:[80,160,300,520],air:false,kind:'gold',proj:'#ffd24a', d:[0,0,0,0,0],r:[10,10,10,10,10],cd:[190,165,140,115,90],inc:[6,10,15,22,32]}, alch: {n:'Alchemik',ic:'🧪',rar:'rare',col:'#7ee081',cost:150,air:true,up:[120,230,410,700],kind:'shot',proj:'#8effa0', d:[5,8,12,18,26],r:[110,118,128,140,156],cd:[40,36,32,28,24],slow:[0.55,0.5,0.45,0.4,0.32],poison:[2,3,5,8,12]}, obr: {n:'Obrońca',ic:'🛡️',rar:'uncommon',col:'#6b8fbf',cost:120,air:false,up:[100,200,360,620],kind:'aura',proj:'#bcd0ff', d:[0.5,0.9,1.4,2.2,3.4],r:[64,70,78,88,100],cd:[1,1,1,1,1],slow:[0.62,0.56,0.5,0.44,0.36]}, ogn: {n:'Ognista',ic:'🔥',rar:'epic',col:'#ff6a2a',cost:200,air:true,up:[170,320,560,950],kind:'shot',proj:'#ff9a3a', d:[12,18,27,40,58],r:[104,112,122,134,150],cd:[52,47,42,37,30],splash:[34,40,46,54,64],burn:[3,5,8,12,18]}, }; const ATD_ORDER=['woj','luk','zb','alch','obr','ogn']; const ATD_RARC={common:'#c8c8c8',uncommon:'#7dff6b',rare:'#5ab0ff',epic:'#b06bff',legendary:'#ffd24a',mythic:'#ff4a4a'}; function atdLvName(id,lv){const b=ATD_TW[id].n;return lv===0?b:lv===1?b+' II':lv===2?b+' III':lv===3?'Elitarny '+b:'Królewski '+b;} function atdUpCost(id,lv){return lv<ATD_TW[id].up.length?ATD_TW[id].up[lv]:null;} // ── STAN ROZGRYWKI ──────────────────────────────────────────────── // 🔥 POZIOMY TRUDNOŚCI — wyższy = mocniejsi/szybsi wrogowie, mniej Pokarmu i HP Królowej, // ale WIĘKSZA nagroda w klejnotach 💠 (gemMul). Wybór trwały: md_obronaDiff. const ATD_DIFFS=[ {id:'easy', n:'Easy', ic:'🟢',col:'#7dff6b',startFood:340,queenHp:140,ehp:0.75,espd:0.95,bounty:1.10,gemMul:0.6}, {id:'normal', n:'Normal', ic:'🔵',col:'#5ab0ff',startFood:260,queenHp:100,ehp:1.00,espd:1.00,bounty:1.00,gemMul:1.0}, {id:'hard', n:'Hard', ic:'🟣',col:'#b06bff',startFood:220,queenHp:80, ehp:1.45,espd:1.06,bounty:1.00,gemMul:1.7}, {id:'nightmare',n:'Nightmare',ic:'🔴',col:'#ff5a4a',startFood:190,queenHp:60, ehp:1.95,espd:1.13,bounty:0.95,gemMul:2.4}, {id:'insane', n:'Insane', ic:'💀',col:'#ff2a2a',startFood:160,queenHp:45, ehp:2.60,espd:1.22,bounty:0.90,gemMul:3.3}, ]; let atdDiff=1; // domyślnie Normal function atdD(){return ATD_DIFFS[atdDiff]||ATD_DIFFS[1];} let atdGrid=null,atdDecos=[],atdMotes=[],atdMap=null,atdPathPx=[]; let atdTowers=[],atdEnemies=[],atdShots=[],atdParts=[],atdFloats=[]; let atdFood=0,atdWave=0,atdQHp=0,atdQHpMax=100,atdKills=0,atdDmgDealt=0,atdBestWave=0; let atdWaveActive=false,atdQueue=[],atdSpawnT=0,atdBuild=null,atdSelTw=null,atdOver=0,atdQFlash=0,atdMsg='',atdMsgT=0; function atdSay(m){atdMsg=m;atdMsgT=200;} function atdFloat(x,y,t,col){atdFloats.push({x,y,t,col,l:56});} function atdPart(x,y,col,n,sp=1.6){for(let k=0;k<n;k++)atdParts.push({x,y,vx:(Math.random()-0.5)*sp*2,vy:(Math.random()-0.5)*sp*2-0.4,l:16+Math.random()*16,col});} // ── 💎 RZADKOŚCI • KOLEKCJA • JAJKA ─────────────────────────────── // Kolekcja trwała: dla każdego typu mrówki trzymamy NAJLEPSZĄ posiadaną rzadkość. // Rzadkość mnoży obrażenia/dochód wieży — zbieranie lepszych mrówek wzmacnia grę. const ATD_RARORDER=['common','uncommon','rare','epic','legendary','mythic']; const ATD_RARNAME={common:'Zwykła',uncommon:'Niezwykła',rare:'Rzadka',epic:'Epicka',legendary:'Legendarna',mythic:'Mityczna'}; const ATD_RARDOT={common:'⚪',uncommon:'🟢',rare:'🔵',epic:'🟣',legendary:'🟡',mythic:'🔴'}; const ATD_RARMUL={common:1,uncommon:1.18,rare:1.4,epic:1.7,legendary:2.05,mythic:2.5}; const ATD_EGGS=[ {id:'basic', n:'Basic Egg', ic:'🥚',col:'#c8c8c8',cost:6, odds:{common:60,uncommon:32,rare:8}}, {id:'forest',n:'Forest Egg',ic:'🥚',col:'#7dff6b',cost:14,odds:{common:32,uncommon:42,rare:21,epic:5}}, {id:'spider',n:'Spider Egg',ic:'🥚',col:'#8a6bd0',cost:26,odds:{uncommon:28,rare:42,epic:25,legendary:5}}, {id:'royal', n:'Royal Egg', ic:'🥚',col:'#ffd24a',cost:44,odds:{rare:30,epic:40,legendary:25,mythic:5}}, {id:'mythic',n:'Mythic Egg',ic:'🥚',col:'#ff4a4a',cost:80,odds:{epic:28,legendary:47,mythic:25}}, ]; let atdGems=0, atdCol={}, atdReveal=null; function atdColLoad(){ try{const d=JSON.parse(localStorage.getItem('md_obronaCol'));if(d&&typeof d==='object')atdCol=d;}catch(e){} for(const id of ATD_ORDER)if(atdCol[id]==null)atdCol[id]=ATD_RARORDER.indexOf(ATD_TW[id].rar); // start = bazowa rzadkość typu atdGems=parseInt(localStorage.getItem('md_obronaGems')||'0')||0; {const dd=localStorage.getItem('md_obronaDiff');if(dd!=null)atdDiff=cl(parseInt(dd)||0,0,ATD_DIFFS.length-1);} } function atdColSave(){try{localStorage.setItem('md_obronaCol',JSON.stringify(atdCol));localStorage.setItem('md_obronaGems',atdGems);}catch(e){}} function atdRar(id){return ATD_RARORDER[atdCol[id]||0];} // posiadana rzadkość typu function atdRmul(id){return ATD_RARMUL[atdRar(id)];} function atdGainGems(v){atdGems+=v;atdColSave();} function atdRollRarity(egg){let t=0;for(const k in egg.odds)t+=egg.odds[k];let r=Math.random()*t;for(const k of ATD_RARORDER)if(egg.odds[k]){r-=egg.odds[k];if(r<=0)return k;}return'common';} function atdOpenEgg(egg){ if(atdGems<egg.cost){atdSay('❌ Za mało klejnotów — potrzeba '+egg.cost+'💠');return;} atdGems-=egg.cost; const rar=atdRollRarity(egg), id=ATD_ORDER[(Math.random()*ATD_ORDER.length)|0], ri=ATD_RARORDER.indexOf(rar); let better=false, refund=0; if(ri>(atdCol[id]||0)){atdCol[id]=ri;better=true;} else refund=2; atdGems+=refund; atdColSave(); atdReveal={id,rar,better,refund,t:170}; atdPart(W/2,300,ATD_RARC[rar],20,2.4); } // ── BUDOWA MAPY ─────────────────────────────────────────────────── function atdBuildMap(m){ atdMap=m;atdGrid=new Uint8Array(COLS*ROWS);atdDecos=[];atdMotes=[]; const wp=m.path; for(let s=0;s<wp.length-1;s++){let[ax,ay]=wp[s];const[bx,by]=wp[s+1];const dx=Math.sign(bx-ax),dy=Math.sign(by-ay);let x=ax,y=ay; while(x!==bx||y!==by){if(x>=0&&x<COLS&&y>=0&&y<ROWS)atdGrid[atdIdx(x,y)]=1;x+=dx;y+=dy;} if(bx>=0&&bx<COLS&&by>=0&&by<ROWS)atdGrid[atdIdx(bx,by)]=1;} const[qx,qy,qw,qh]=m.queen;for(let y=qy;y<qy+qh;y++)for(let x=qx;x<qx+qw;x++)if(x<COLS&&y<ROWS)atdGrid[atdIdx(x,y)]=3; const sp=m.spawn;atdGrid[atdIdx(sp[0],sp[1])]=4; for(let y=0;y<ROWS;y++)for(let x=0;x<COLS;x++){const i=atdIdx(x,y);if(atdGrid[i]!==0)continue; if(atdHash(x,y)>0.87&&!atdNearPath(x,y)){atdGrid[i]=2;atdDecos.push({x:atdPX(x),y:atdPY(y),ic:m.deco[(atdHash(x+7,y+3)*m.deco.length)|0]});}} for(let k=0;k<26;k++)atdMotes.push({x:Math.random()*W,y:Math.random()*MAPH,vx:0.1+Math.random()*0.25,vy:-0.05+Math.random()*0.12,r:0.8+Math.random()*1.6,a:0.15+Math.random()*0.3}); atdPathPx=wp.map(([c,r])=>({x:atdPX(c),y:atdPY(r)})); } function atdNearPath(cx,cy){for(let dy=-1;dy<=1;dy++)for(let dx=-1;dx<=1;dx++){const x=cx+dx,y=cy+dy;if(x<0||x>=COLS||y<0||y>=ROWS)continue;if(atdGrid[atdIdx(x,y)]===1)return true;}return false;} function atdBuildable(cx,cy){return cx>=0&&cx<COLS&&cy>=0&&cy<ROWS&&atdGrid[atdIdx(cx,cy)]===0;} function atdTowerAt(cx,cy){return atdTowers.find(t=>t.cx===cx&&t.cy===cy)||null;} function atdStart(m){ atdBuildMap(m); atdTowers=[];atdEnemies=[];atdShots=[];atdParts=[];atdFloats=[]; atdFood=atdD().startFood;atdWave=0;atdQHpMax=atdD().queenHp;atdQHp=atdQHpMax; atdKills=0;atdDmgDealt=0;atdWaveActive=false;atdQueue=[];atdSpawnT=0; atdBuild=null;atdSelTw=null;atdOver=0;atdQFlash=0;atdMsgT=0; atdBestWave=parseInt(localStorage.getItem('md_obronaBest')||'0')||0; atdSay('Postaw mrówki, potem [Spacja] lub ▶ FALA. Broń Królowej!'); gs='game'; } // ── FALE ────────────────────────────────────────────────────────── function atdGenWave(n){ const q=[],pool=(atdMap&&atdMap.pool)||['gasienica','zuk','komar','pajak'],bossId=(atdMap&&atdMap.boss)||'boss'; const push=(id,cnt,gap)=>{if(!id)return;for(let k=0;k<cnt;k++)q.push({id,gap});}; if(n%10===0){push(bossId,1,0);push(pool[Math.min(2,pool.length-1)],6+n/10,26);return q;} // boss mapy co 10 fal push(pool[0],6+n*2,Math.max(16,34-n)); // tier0 — podstawowy rój if(n>=3)push(pool[1],Math.floor(n*0.7),38); if(n>=4)push(pool[2],Math.floor(n*0.8),30); if(n>=6)push(pool[3],Math.floor(n*0.9),24); if(n>=9)push(pool[4],Math.floor((n-6)*0.5),60); // tier4 (jeśli mapa ma 5 wrogów) // przetasuj lekko, ale stabilnie (bez psucia gap) return q; } function atdStartWave(){ if(atdmpGuest()){atdmpSend({t:'act',a:'wave'});return;} // gość: rozkaz do hosta if(atdWaveActive||atdOver)return; atdWave++;atdWaveActive=true;atdQueue=atdGenWave(atdWave);atdSpawnT=0; atdSay((atdWave%10===0?'👑 BOSS! ':'')+'FALA '+atdWave+' — '+atdQueue.length+' wrogów!'); atdFloat(W/2,60,'🌊 FALA '+atdWave,atdWave%10===0?'#ff5a3c':'#ffe08a'); } function atdSpawnEnemy(id){ const d=ATD_ENE[id],hpm=atdD().ehp*(1+atdWave*0.09); const p0=atdPathPx[0]; atdEnemies.push({id,def:d,x:p0.x,y:p0.y,seg:0,hp:d.hp*hpm*(d.boss?1:1),mhp:d.hp*hpm, slowT:0,poisonT:0,poisonDmg:0,burnT:0,burnDmg:0,hit:0,summonCd:180,stunCd:180,rageT:0}); } // ── AKTUALIZACJA ────────────────────────────────────────────────── function atdEProg(e){return e.seg;} // postęp po ścieżce (do wyboru celu "najdalszy") function atdUpdEnemy(e){ // efekty let sp=e.def.spd*atdD().espd; if(e.slowT>0){e.slowT--;sp*=e.slowMul||0.5;} if(e.poisonT>0){e.poisonT--;if(frame%15===0){e.hp-=e.poisonDmg;atdDmgDealt+=e.poisonDmg;atdPart(e.x,e.y,'#8effa0',1,0.7);}} if(e.burnT>0){e.burnT--;if(frame%12===0){e.hp-=e.burnDmg;atdDmgDealt+=e.burnDmg;atdPart(e.x,e.y-4,'#ff8a3a',1,0.8);}} if(e.def.boss){ if(e.hp<e.mhp*0.4)sp*=1.6; // boss przyspiesza gdy słaby if(--e.summonCd<=0){e.summonCd=200;const s=ATD_ENE[e.def.summon]; atdEnemies.push({id:e.def.summon,def:s,x:e.x,y:e.y,seg:e.seg,hp:s.hp,mhp:s.hp,slowT:0,poisonT:0,poisonDmg:0,burnT:0,hit:0}); atdFloat(e.x,e.y-18,'+🕷️','#d0a0ff');} if(--e.stunCd<=0){e.stunCd=240;let any=false; // 💫 boss ogłusza pobliskie wieże for(const t of atdTowers)if(Math.hypot(t.px-e.x,t.py-e.y)<130){t.stunT=100;any=true;atdPart(t.px,t.py,'#ffe08a',6);} if(any)atdFloat(e.x,e.y-24,'💫 OGŁUSZENIE','#ffe08a');} } if(e.hit>0)e.hit--; // ruch po łamanej const ti=e.seg+1; if(ti>=atdPathPx.length){atdLeak(e);return true;} const tgt=atdPathPx[ti],dx=tgt.x-e.x,dy=tgt.y-e.y,d=Math.hypot(dx,dy); if(d<=sp){e.x=tgt.x;e.y=tgt.y;e.seg++;if(e.seg>=atdPathPx.length-1){atdLeak(e);return true;}} else{e.x+=dx/d*sp;e.y+=dy/d*sp;} return false; } function atdLeak(e){ e._dead=true; // oznacz — pociski lecące w niego mają przestać go gonić do komnaty atdQHp-=e.def.leak;atdQFlash=16;atdPart(atdPathPx[atdPathPx.length-1].x,atdPathPx[atdPathPx.length-1].y,'#ff3b3b',12); atdFloat(atdPX(atdMap.queen[0])+20,atdPY(atdMap.queen[1]),'-'+e.def.leak+'👑','#ff5a4a'); if(atdQHp<=0&&!atdOver){atdQHp=0;atdOver=1;atdBestWave=Math.max(atdBestWave,atdWave);localStorage.setItem('md_obronaBest',atdBestWave);} } function atdHitEnemy(e,dmg,tw){ e.hp-=dmg;e.hit=6;atdDmgDealt+=dmg; const T=ATD_TW[tw.id],lv=tw.lv; if(tw.id==='alch'){e.slowT=90;e.slowMul=T.slow[lv];e.poisonT=200;e.poisonDmg=T.poison[lv];} if(tw.id==='ogn'){e.burnT=150;e.burnDmg=T.burn[lv]; const R=T.splash[lv];for(const o of atdEnemies)if(o!==e&&!o._dead){const dd=Math.hypot(o.x-e.x,o.y-e.y);if(dd<R){o.hp-=dmg*0.5;o.burnT=120;o.burnDmg=T.burn[lv];o.hit=6;}} atdPart(e.x,e.y,'#ff8a3a',8);} } function atdUpdTower(t){ if(t.stunT>0){t.stunT--;return;} // 💫 ogłuszona przez bossa — nie działa const T=ATD_TW[t.id],lv=t.lv;t.cd=(t.cd||0)-1; const rm=t.rmul||1; if(t.id==='zb'){ if(t.cd<=0){t.cd=T.cd[lv];const g=Math.round(T.inc[lv]*rm);atdFood+=g;atdFloat(t.px,t.py-12,'+'+g+'🍖','#ffd24a');atdPart(t.px,t.py,'#ffd24a',5);} return; } if(t.id==='obr'){ // aura — spowalnia i lekko rani wrogów w zasięgu (miękka ściana) const R=T.r[lv];for(const e of atdEnemies){const d=Math.hypot(e.x-t.px,e.y-t.py);if(d<R){e.slowT=8;e.slowMul=T.slow[lv];e.hp-=T.d[lv]*rm;atdDmgDealt+=T.d[lv]*rm;}} t.pulse=(t.pulse||0)+1;return; } if(t.cd>0)return; // wybierz cel: najdalej po ścieżce, w zasięgu, latające tylko jeśli air let tgt=null,bp=-1;const R=T.r[lv]; for(const e of atdEnemies){if(e.def.air&&!T.air)continue;const d=Math.hypot(e.x-t.px,e.y-t.py);if(d>R)continue;const p=e.seg*1000-d;if(p>bp){bp=p;tgt=e;}} if(!tgt)return; t.cd=T.cd[lv];t.ang=Math.atan2(tgt.y-t.py,tgt.x-t.px); atdShots.push({x:t.px,y:t.py,tgt,dmg:T.d[lv]*rm,tw:t,col:T.proj,spd:tw_spd(t.id),life:60,melee:t.id==='woj'}); } function tw_spd(id){return id==='luk'?9:id==='ogn'?6:id==='woj'?7:7;} function atdUpdShot(s){ if(!s.tgt||s.tgt._dead){return true;} const dx=s.tgt.x-s.x,dy=s.tgt.y-s.y,d=Math.hypot(dx,dy); if(d<=s.spd+6){atdHitEnemy(s.tgt,s.dmg,s.tw);atdPart(s.x,s.y,s.col,4,1.2);return true;} s.x+=dx/d*s.spd;s.y+=dy/d*s.spd;return(--s.life<=0); } function atdUpdate(){ frame++; for(const mo of atdMotes){mo.x+=mo.vx;mo.y+=mo.vy;if(mo.x>W+4)mo.x=-4;if(mo.y<-4)mo.y=MAPH+4;} while(keyq.length)atdKey(keyq.shift()); while(clicks.length){const c=clicks.shift(); if(gs==='menu')atdMenuClick(c.x,c.y); else if(gs==='eggs')atdEggsClick(c.x,c.y); else if(gs==='collection')atdCollectionClick(c.x,c.y); else if(gs==='coop')atdCoopClick(c.x,c.y); else atdGameClick(c.x,c.y);} if(atdReveal&&atdReveal.t>0)atdReveal.t--; // 👥 GOŚĆ nie symuluje — wysyła tylko kursor i rysuje świat hosta if(atdmpGuest()){if(gs==='game'&&--atdmpSyncT<=0){atdmpSyncT=4;atdmpSend({t:'cur',x:Math.round(mouse.x),y:Math.round(mouse.y)});}return;} if(gs!=='game'||atdOver)return; if(atdMsgT>0)atdMsgT--;if(atdQFlash>0)atdQFlash--; // spawn z kolejki if(atdWaveActive){ if(atdQueue.length){ if(--atdSpawnT<=0){const it=atdQueue.shift();atdSpawnEnemy(it.id);atdSpawnT=it.gap;} } else if(atdEnemies.length===0){ // fala wyczyszczona atdWaveActive=false;const rew=40+atdWave*8, gem=Math.max(1,Math.round((1+(atdWave%5===0?1:0))*atdD().gemMul));atdFood+=rew;atdGainGems(gem); atdSay('✅ Fala '+atdWave+' odparta! +'+rew+'🍖 +'+gem+'💠');atdFloat(W/2,80,'+'+rew+'🍖','#7dff6b');atdFloat(W/2,64,'+'+gem+'💠','#bfe6ff'); atdBestWave=Math.max(atdBestWave,atdWave);localStorage.setItem('md_obronaBest',atdBestWave); } } for(const t of atdTowers)atdUpdTower(t); for(let i=atdShots.length-1;i>=0;i--)if(atdUpdShot(atdShots[i]))atdShots.splice(i,1); // aktualizuj i usuwaj w JEDNEJ pętli wstecz: leak (doszedł do Królowej) LUB śmierć (hp≤0) for(let i=atdEnemies.length-1;i>=0;i--){const e=atdEnemies[i]; if(e.hp>0){ if(atdUpdEnemy(e)){atdEnemies.splice(i,1);continue;} } // true = doszedł do Królowej → już usunięty z gry if(e.hp<=0){e._dead=true;atdKills++;const bnt=Math.round(e.def.bounty*atdD().bounty);atdFood+=bnt; atdFloat(e.x,e.y-8,'+'+bnt+'🍖','#ffd24a');atdPart(e.x,e.y,e.def.col,12); if(e.def.boss){const bg=Math.round(6*atdD().gemMul);atdSay('👑 BOSS POKONANY! +'+e.def.bounty+'🍖 +'+bg+'💠');atdGainGems(bg);atdFloat(e.x,e.y-22,'+'+bg+'💠','#bfe6ff');} atdEnemies.splice(i,1);}} for(let i=atdParts.length-1;i>=0;i--){const p=atdParts[i];p.x+=p.vx;p.y+=p.vy;p.vy+=0.05;p.vx*=0.96;if(--p.l<=0)atdParts.splice(i,1);} for(let i=atdFloats.length-1;i>=0;i--){const f=atdFloats[i];f.y-=0.42;if(--f.l<=0)atdFloats.splice(i,1);} if(atdmpHost&&atdmpOn&&atdmpConnOk()&&--atdmpSyncT<=0){atdmpSyncT=3;atdmpSendState();} // 👥 host strumieniuje świat } function atdKey(k){ if((gs==='eggs'||gs==='collection')&&k==='Escape'){gs='menu';atdReveal=null;return;} if(gs==='coop'&&k==='Escape'){atdmpCleanup(true);gs='menu';return;} if(gs!=='game')return; if(k===' '){atdStartWave();return;} if(k==='Escape'){atdBuild=null;atdSelTw=null;return;} const n=parseInt(k);if(n>=1&&n<=6){atdBuild=ATD_ORDER[n-1];atdSelTw=null;} } // ── KLIKI ───────────────────────────────────────────────────────── function atdGameClick(mx,my){ // przyciski górne / dolne if(isOR(mx,my,W-92,4,86,24)){atdStartWave();return;} // ▶ FALA if(isOR(mx,my,8,4,74,24)){if(atdmpOn){atdmpSend({t:'bye'});atdmpOn=false;gs='coop';}else gs='menu';return;} // ◀ Menu (w co-opie → lobby) // panel ulepszeń wybranej wieży (prawa strona) — klik w panel NIE stawia wieży za nim if(atdSelTw){ const P=atdSelPanel(); if(isOR(mx,my,P.x,P.upY,P.w,34)){atdUpgrade(atdSelTw);return;} if(isOR(mx,my,P.x,P.selY,P.w,28)){atdSell(atdSelTw);return;} if(isOR(mx,my,P.x,P.y,P.w,P.h))return; } if(my<30)return; // pasek HUD — nie buduj pod nim // pasek budowy (dół) if(my>=MAPH){const bw=(W-16)/6;for(let i=0;i<6;i++){if(isOR(mx,my,8+i*bw,MAPH+6,bw-6,54)){atdBuild=(atdBuild===ATD_ORDER[i]?null:ATD_ORDER[i]);atdSelTw=null;return;}}return;} // pole gry const cx=(mx/TILE)|0,cy=(my/TILE)|0; const ex=atdTowerAt(cx,cy); if(ex){atdSelTw=ex;atdBuild=null;return;} // wybór postawionej wieży if(atdBuild&&atdBuildable(cx,cy)){atdPlace(atdBuild,cx,cy);return;} atdSelTw=null; } function atdPlace(id,cx,cy){ if(atdmpGuest()){atdmpSend({t:'act',a:'place',id,cx,cy});atdBuild=null;return;} // gość: rozkaz budowy const cost=ATD_TW[id].cost; if(atdFood<cost){atdSay('❌ Za mało Pokarmu ('+cost+'🍖)');return;} atdFood-=cost; atdTowers.push({id,cx,cy,px:atdPX(cx),py:atdPY(cy),lv:0,cd:0,ang:0,rar:atdRar(id),rmul:atdRmul(id)}); atdGrid[atdIdx(cx,cy)]=5; // zajęte przez wieżę (niebudowalne) atdPart(atdPX(cx),atdPY(cy),ATD_TW[id].col,10);atdSelTw=atdTowers[atdTowers.length-1];atdBuild=null; } function atdUpgrade(t){ if(atdmpGuest()){atdmpSend({t:'act',a:'upg',cx:t.cx,cy:t.cy});return;} // gość: rozkaz ulepszenia const c=atdUpCost(t.id,t.lv); if(c==null){atdSay('⭐ Maksymalny poziom!');return;} if(atdFood<c){atdSay('❌ Ulepszenie kosztuje '+c+'🍖');return;} atdFood-=c;t.lv++;atdPart(t.px,t.py,'#ffd24a',14);atdFloat(t.px,t.py-14,'⬆ '+atdLvName(t.id,t.lv),'#ffd24a'); } function atdSell(t){ if(atdmpGuest()){atdmpSend({t:'act',a:'sell',cx:t.cx,cy:t.cy});return;} // gość: rozkaz sprzedaży let paid=ATD_TW[t.id].cost;for(let l=0;l<t.lv;l++)paid+=ATD_TW[t.id].up[l]; const back=Math.round(paid*0.6);atdFood+=back; atdGrid[atdIdx(t.cx,t.cy)]=0;atdTowers=atdTowers.filter(x=>x!==t);atdSelTw=null; atdFloat(t.px,t.py-10,'+'+back+'🍖','#7dff6b');atdPart(t.px,t.py,'#888',10); } // ── RYSOWANIE ───────────────────────────────────────────────────── function atdStroke(wp){ctx.beginPath();ctx.moveTo(wp[0].x,wp[0].y);for(let i=1;i<wp.length;i++)ctx.lineTo(wp[i].x,wp[i].y);ctx.stroke();} function atdDrawMap(){ const m=atdMap,gbase=m.grass,gac=m.accent||m.grass,dirt=m.dirt||'#8a6038'; for(let y=0;y<ROWS;y++)for(let x=0;x<COLS;x++){ const i=atdIdx(x,y),t=atdGrid[i],px=x*TILE,py=y*TILE,h=atdHash(x,y); if(t===1){ctx.fillStyle=atdShade(dirt,-0.12+h*0.12);ctx.fillRect(px,py,TILE,TILE); ctx.fillStyle='rgba(0,0,0,0.14)';ctx.fillRect(px+3+h*20,py+5+h*14,3,2);ctx.fillRect(px+22-h*10,py+24-h*8,2,3);} else{ctx.fillStyle=atdShade(gbase,(h-0.5)*0.16);ctx.fillRect(px,py,TILE,TILE); ctx.strokeStyle=atdShade(gac,0.05);ctx.lineWidth=1.4;ctx.globalAlpha=0.5+h*0.3;ctx.beginPath(); for(let k=0;k<3;k++){const gx=px+8+k*10+h*4,gy=py+30;ctx.moveTo(gx,gy);ctx.lineTo(gx-1.5+h*2,gy-6-h*3);}ctx.stroke();ctx.globalAlpha=1;} } const wp=atdPathPx;ctx.lineCap='round';ctx.lineJoin='round'; ctx.strokeStyle=atdShade(dirt,-0.4);ctx.lineWidth=TILE-4;atdStroke(wp); ctx.strokeStyle=atdShade(dirt,0.06);ctx.lineWidth=TILE-13;atdStroke(wp); ctx.fillStyle='rgba(30,18,8,0.4)'; for(let s=0;s<wp.length-1;s++){const a=wp[s],b=wp[s+1],d=Math.hypot(b.x-a.x,b.y-a.y),n=Math.floor(d/16); for(let k=0;k<n;k++){const t=k/n,x=a.x+(b.x-a.x)*t,y=a.y+(b.y-a.y)*t;ctx.beginPath();ctx.arc(x+(k%2?3:-3),y,1.6,0,7);ctx.fill();}} ctx.strokeStyle='rgba(255,255,255,0.05)';ctx.lineWidth=1; for(let y=0;y<ROWS;y++)for(let x=0;x<COLS;x++)if(atdGrid[atdIdx(x,y)]===0)ctx.strokeRect(x*TILE+0.5,y*TILE+0.5,TILE-1,TILE-1); for(const d of atdDecos){ctx.font='19px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.globalAlpha=0.35;ctx.fillStyle='#000';ctx.fillText(d.ic,d.x+1,d.y+11);ctx.globalAlpha=1;ctx.fillText(d.ic,d.x,d.y+9);} for(const mo of atdMotes){ctx.globalAlpha=mo.a;ctx.fillStyle='#bfe6a0';ctx.beginPath();ctx.arc(mo.x,mo.y,mo.r,0,7);ctx.fill();}ctx.globalAlpha=1; // gniazdo {const sp=m.spawn,px=atdPX(sp[0]),py=atdPY(sp[1]);ctx.save();ctx.fillStyle='#0a0602';ctx.beginPath();ctx.ellipse(px,py,15,12,0,0,7);ctx.fill(); ctx.strokeStyle=atdShade(dirt,-0.3);ctx.lineWidth=3;ctx.stroke();ctx.fillStyle='rgba(255,80,40,'+(0.3+0.2*Math.sin(frame*0.08))+')';ctx.beginPath();ctx.arc(px,py,6,0,7);ctx.fill();ctx.restore(); tx('👹',px,py-24,15,'#ff8a6a','center');} // komnata Królowej {const[qx,qy,qw,qh]=m.queen,x=qx*TILE,y=qy*TILE,w=qw*TILE,hh=qh*TILE;ctx.save(); const g=ctx.createRadialGradient(x+w/2,y+hh/2,4,x+w/2,y+hh/2,w);g.addColorStop(0,'rgba(255,210,74,'+(atdQFlash>0?0.5:0.28)+')');g.addColorStop(1,'rgba(255,210,74,0.05)'); ctx.fillStyle=g;ctx.fillRect(x,y,w,hh);ctx.strokeStyle=atdQFlash>0?'#ff5a4a':'#ffd24a';ctx.lineWidth=2.5;ctx.shadowColor='#ffd24a';ctx.shadowBlur=14;rr(x+3,y+3,w-6,hh-6,10,null,ctx.strokeStyle,2.5);ctx.restore(); atdDrawQueen(x+w/2,y+hh/2);tx('👑 KRÓLOWA',x+w/2,y-8,11,'#ffe08a','center',true); // pasek HP królowej const bw=w-8;rr(x+4,y+hh+4,bw,7,3,'rgba(0,0,0,0.6)',null);ctx.fillStyle=atdQHp/atdQHpMax>0.35?'#7dff6b':'#ff5a3c';ctx.fillRect(x+5,y+hh+5,(bw-2)*cl(atdQHp/atdQHpMax,0,1),5);} } function atdDrawQueen(x,y){ctx.save();ctx.translate(x,y+Math.sin(frame*0.05)*1.2); ctx.strokeStyle='#c08f1e';ctx.lineWidth=2;for(let k=-1;k<2;k++){const ph=Math.sin(frame*0.08+k*1.3)*2;ctx.beginPath();ctx.moveTo(k*5,2);ctx.lineTo(k*5-3,10+ph);ctx.moveTo(k*5,2);ctx.lineTo(k*5-3,-8-ph);ctx.stroke();} ctx.fillStyle='#e0a92b';ctx.beginPath();ctx.ellipse(-11,0,9,7,0,0,7);ctx.fill();ctx.beginPath();ctx.ellipse(-1,0,6,5,0,0,7);ctx.fill();ctx.beginPath();ctx.ellipse(8,0,6,5.5,0,0,7);ctx.fill(); ctx.strokeStyle='#c08f1e';ctx.lineWidth=1.4;ctx.beginPath();ctx.moveTo(12,-2);ctx.lineTo(18,-7);ctx.moveTo(12,2);ctx.lineTo(18,7);ctx.stroke();ctx.restore();tx('👑',x,y-16,15,'#ffd24a','center');} function atdDrawTower(t){ const T=ATD_TW[t.id],lv=t.lv,x=t.px,y=t.py; // podstawka ctx.save();ctx.fillStyle='rgba(0,0,0,0.28)';ctx.beginPath();ctx.ellipse(x,y+10,15,6,0,0,7);ctx.fill();ctx.restore(); // korpus mrówki-wieży (barwa typu), obrys wg rzadkości const RC=ATD_RARC[t.rar||T.rar]; ctx.save();ctx.translate(x,y); ctx.fillStyle=T.col;ctx.strokeStyle=RC;ctx.lineWidth=1.6; ctx.beginPath();ctx.ellipse(-7,0,6,5,0,0,7);ctx.fill();ctx.beginPath();ctx.ellipse(0,0,4.5,4,0,0,7);ctx.fill();ctx.beginPath();ctx.ellipse(6,0,5,4.6,0,0,7);ctx.fill();ctx.stroke(); ctx.restore(); tx(T.ic,x,y-1,15,'#fff','center'); // gwiazdki poziomu for(let k=0;k<=lv;k++){ctx.fillStyle='#ffd24a';ctx.beginPath();ctx.arc(x-8+k*4,y-15,1.7,0,7);ctx.fill();} // ring rzadkości (posiadanej) ctx.strokeStyle=RC;ctx.globalAlpha=0.4;ctx.lineWidth=1.6;ctx.beginPath();ctx.arc(x,y,14,0,7);ctx.stroke();ctx.globalAlpha=1; if(t.stunT>0){tx('💫',x,y-17,13,'#ffe08a','center');ctx.strokeStyle='#ffe08a';ctx.globalAlpha=0.5;ctx.beginPath();ctx.arc(x,y,16,0,7);ctx.stroke();ctx.globalAlpha=1;} } function atdDrawEnemy(e){ ctx.save();if(e.hit>0)ctx.globalAlpha=0.5+Math.random()*0.5; tx(e.def.ic,e.x,e.y,e.def.boss?26:17,'#fff','center');ctx.restore(); if(e.slowT>0){ctx.fillStyle='rgba(120,220,255,0.5)';ctx.beginPath();ctx.arc(e.x-8,e.y-8,2,0,7);ctx.fill();} if(e.poisonT>0||e.burnT>0){ctx.fillStyle=e.burnT>0?'#ff8a3a':'#8effa0';ctx.beginPath();ctx.arc(e.x+8,e.y-8,2,0,7);ctx.fill();} const w=e.def.boss?34:18;ctx.fillStyle='rgba(0,0,0,0.6)';ctx.fillRect(e.x-w/2,e.y-(e.def.boss?20:13),w,3); ctx.fillStyle='#ff5a3c';ctx.fillRect(e.x-w/2,e.y-(e.def.boss?20:13),w*cl(e.hp/e.mhp,0,1),3); } function atdDrawRange(t,col){ctx.save();ctx.strokeStyle=col;ctx.globalAlpha=0.5;ctx.lineWidth=1.5;ctx.setLineDash([5,5]); ctx.beginPath();ctx.arc(t.px,t.py,ATD_TW[t.id].r[t.lv],0,7);ctx.stroke();ctx.setLineDash([]); ctx.globalAlpha=0.08;ctx.fillStyle=col;ctx.fill();ctx.restore();} function atdHUD(){ ctx.save();ctx.globalAlpha=0.85;rr(0,0,W,30,0,'#0c1a0a',null);ctx.restore(); tx('🍖 '+Math.floor(atdFood),10,15,15,'#ffe08a','left',true); tx('👑 '+Math.ceil(atdQHp)+'/'+atdQHpMax,120,15,13,atdQHp/atdQHpMax>0.35?'#c8e6b0':'#ff6a5a','left',true); tx(atdMap.ic+' '+atdMap.n+' '+atdD().ic+' '+atdD().n,W/2,15,12.5,'#c8e6b0','center',true); tx('🌊 '+atdWave+(atdWaveActive?' (trwa)':'')+' 💀 '+atdKills,W-104,15,12,'#c8e6b0','right'); // przyciski const wb=isOR(mouse.x,mouse.y,W-92,4,86,24); rr(W-92,4,86,24,6,atdWaveActive?'#3a2a10':(wb?'#2a5a1e':'#1a4010'),atdWaveActive?'#6b5a2a':'#7dff6b',1.5); tx(atdWaveActive?'⏳ trwa':'▶ FALA',W-49,15,12,atdWaveActive?'#c8b060':'#dfffcf','center',true); const mb=isOR(mouse.x,mouse.y,8,4,74,24);rr(8,4,74,24,6,mb?'#2a4a1e':'#16300f','#4f8a41',1.5);tx('◀ Menu',45,15,12,'#dfffcf','center',true); } function atdBuildBar(){ ctx.save();ctx.globalAlpha=0.95;rr(0,MAPH,W,H-MAPH,0,'#0c1a0a',null);ctx.restore(); const bw=(W-16)/6; ATD_ORDER.forEach((id,i)=>{const T=ATD_TW[id],x=8+i*bw,on=atdBuild===id,can=atdFood>=T.cost,hov=isOR(mouse.x,mouse.y,x,MAPH+6,bw-6,54); rr(x,MAPH+6,bw-6,54,8,on?'#20401a':(hov?'#16300f':'#101c0c'),on?ATD_RARC[T.rar]:(can?'#3f6b34':'#5a2a22'),on?2.4:1.4); tx(T.ic,x+18,MAPH+26,20,'#fff','center'); tx(T.n,x+34,MAPH+18,11,can?'#dfffcf':'#a06a5a','left',true); tx('🍖'+T.cost,x+34,MAPH+34,10.5,can?'#ffd24a':'#a06a5a','left',true); tx('['+(i+1)+']',x+bw-14,MAPH+50,9,'#5f8a52','center'); }); } function atdSelPanel(){const w=196,x=W-w-6,y=36,h=176;return{x,y,w,h,upY:y+h-70,selY:y+h-32};} function atdDrawSelPanel(){ const t=atdSelTw,T=ATD_TW[t.id],lv=t.lv,P=atdSelPanel(),RC=ATD_RARC[t.rar||T.rar]; atdDrawRange(t,T.col); ctx.save();ctx.globalAlpha=0.96;rr(P.x,P.y,P.w,P.h,10,'#0e1c0b',RC,2);ctx.restore(); tx(T.ic+' '+atdLvName(t.id,lv),P.x+P.w/2,P.y+18,13,RC,'center',true); tx((ATD_RARDOT[t.rar]||'⚪')+' '+(ATD_RARNAME[t.rar]||'Zwykła')+' ×'+(t.rmul||1).toFixed(2),P.x+P.w/2,P.y+36,10,RC,'center',true); let yy=P.y+56; const line=(l,v)=>{tx(l,P.x+12,yy,11,'#9fc48a','left');tx(v,P.x+P.w-12,yy,11,'#dfffcf','right',true);yy+=18;}; const rm=t.rmul||1; if(t.id==='zb'){line('Dochód',Math.round(T.inc[lv]*rm)+'🍖 / '+(T.cd[lv]/60).toFixed(1)+'s');} else if(t.id==='obr'){line('Aura DPS',(T.d[lv]*rm*60).toFixed(0));line('Zasięg',T.r[lv]);line('Spowoln.',Math.round((1-T.slow[lv])*100)+'%');} else{line('Obrażenia',Math.round(T.d[lv]*rm));line('Zasięg',T.r[lv]);line('Szybkość',(60/T.cd[lv]).toFixed(1)+'/s'); if(t.id==='alch')line('Trucizna',T.poison[lv]);if(t.id==='ogn')line('Ogień',T.burn[lv]);} // przycisk ULEPSZ const c=atdUpCost(t.id,lv),can=c!=null&&atdFood>=c,hb=isOR(mouse.x,mouse.y,P.x,P.upY,P.w,34); rr(P.x+8,P.upY,P.w-16,34,8,c==null?'#3a3410':(can?(hb?'#2a7d2a':'#1a5a1a'):'#2a1a12'),c==null?'#ffd24a':(can?'#7dff6b':'#6a4a3a'),1.8); tx(c==null?'⭐ MAKS. POZIOM':('⬆ ULEPSZ '+c+'🍖'),P.x+P.w/2,P.upY+17,12.5,c==null?'#ffd24a':(can?'#fff':'#a08a7a'),'center',true); if(c!=null)tx('→ '+atdLvName(t.id,lv+1),P.x+P.w/2,P.upY-8,9.5,'#8fbf7a','center'); // przycisk SPRZEDAJ const sb=isOR(mouse.x,mouse.y,P.x,P.selY,P.w,28);let paid=T.cost;for(let l=0;l<lv;l++)paid+=T.up[l]; rr(P.x+8,P.selY,P.w-16,26,7,sb?'#3a2418':'#241610','#6a4a3a',1.4);tx('💰 Sprzedaj (+'+Math.round(paid*0.6)+'🍖)',P.x+P.w/2,P.selY+13,11,'#d0b090','center',true); } function atdDraw(){ if(gs==='menu'){atdMenu();return;} if(gs==='eggs'){atdEggsScreen();return;} if(gs==='collection'){atdCollectionScreen();return;} if(gs==='coop'){atdCoopScreen();return;} atdDrawMap(); for(const t of atdTowers)atdDrawTower(t); for(const s of atdShots){ctx.fillStyle=s.col;ctx.beginPath();ctx.arc(s.x,s.y,s.melee?3.4:2.6,0,7);ctx.fill(); if(s.tw&&s.tw.id==='luk'){ctx.strokeStyle=s.col;ctx.lineWidth=1.6;ctx.beginPath();ctx.moveTo(s.x,s.y);ctx.lineTo(s.x-4,s.y);ctx.stroke();}} for(const e of atdEnemies)atdDrawEnemy(e); for(const p of atdParts){ctx.globalAlpha=cl(p.l/24,0,1);ctx.fillStyle=p.col;ctx.fillRect(p.x-1.5,p.y-1.5,3,3);}ctx.globalAlpha=1; for(const f of atdFloats){ctx.globalAlpha=cl(f.l/40,0,1);tx(f.t,f.x,f.y,12,f.col,'center',true);}ctx.globalAlpha=1; // podgląd budowy pod kursorem if(atdBuild&&mouse.y<MAPH){const cx=(mouse.x/TILE)|0,cy=(mouse.y/TILE)|0;if(cx>=0&&cx<COLS&&cy>=0&&cy<ROWS){const ok=atdBuildable(cx,cy),px=cx*TILE,py=cy*TILE; ctx.save();ctx.globalAlpha=0.3;ctx.fillStyle=ok?'#7dff6b':'#ff5a4a';ctx.fillRect(px,py,TILE,TILE);ctx.restore(); if(ok){ctx.save();ctx.strokeStyle=ATD_TW[atdBuild].col;ctx.globalAlpha=0.5;ctx.setLineDash([5,5]);ctx.beginPath();ctx.arc(px+20,py+20,ATD_TW[atdBuild].r[0],0,7);ctx.stroke();ctx.setLineDash([]);ctx.restore(); tx(ATD_TW[atdBuild].ic,px+20,py+19,15,'#fff','center');}}} // 👥 kursor znajomego if(atdmpOn&&atdmpConnOk()&&atdmpOx>-50&&atdmpOy<MAPH){ctx.save();ctx.strokeStyle='#5adcff';ctx.lineWidth=2;ctx.globalAlpha=0.85; ctx.beginPath();ctx.arc(atdmpOx,atdmpOy,7,0,7);ctx.moveTo(atdmpOx-11,atdmpOy);ctx.lineTo(atdmpOx+11,atdmpOy);ctx.moveTo(atdmpOx,atdmpOy-11);ctx.lineTo(atdmpOx,atdmpOy+11);ctx.stroke(); tx('👥',atdmpOx,atdmpOy-15,11,'#5adcff','center');ctx.restore();} if(atdSelTw)atdDrawSelPanel(); atdHUD();atdBuildBar(); if(atdmpOn){ctx.save();ctx.globalAlpha=0.9;rr(W/2-90,32,180,18,6,'#0d3a5a','#5adcff',1.2);ctx.restore();tx('👥 CO-OP '+(atdmpHost?'(host)':'(gość)'),W/2,41,10.5,'#bfe6ff','center',true);} if(atdMsgT>0){ctx.save();ctx.globalAlpha=0.9;const mw=Math.min(560,atdMsg.length*7.6+30);rr(W/2-mw/2,34,mw,26,7,'#0e1c0b','#4f8a41',1.4);ctx.restore();tx(atdMsg,W/2,47,12,'#dfffcf','center',true);} if(atdOver)atdOverScreen(); } function atdOverScreen(){ ctx.save();ctx.globalAlpha=0.8;ctx.fillStyle='#000';ctx.fillRect(0,0,W,H);ctx.restore(); tx('💀 KRÓLOWA PADŁA',W/2,H/2-90,34,'#ff6b4a','center',true); tx('Mrowisko przetrwało do fali '+atdWave+' ('+atdD().ic+' '+atdD().n+')',W/2,H/2-50,16,'#ffe08a','center'); tx('💀 Pokonani: '+atdKills+' ⚔️ Zadane obrażenia: '+Math.round(atdDmgDealt),W/2,H/2-24,13,'#c8e6b0','center'); tx('🏆 Rekord fal: '+atdBestWave,W/2,H/2+2,13,'#9ee493','center'); const r1=isOR(mouse.x,mouse.y,W/2-210,H/2+40,190,46),r2=isOR(mouse.x,mouse.y,W/2+20,H/2+40,190,46); rr(W/2-210,H/2+40,190,46,10,r1?'#2a6a2a':'#1a4a1a','#7dff6b',2);tx('🔄 Jeszcze raz',W/2-115,H/2+63,15,'#dfffcf','center',true); rr(W/2+20,H/2+40,190,46,10,r2?'#3a3018':'#241a0c','#8a7550',2);tx('🚪 Menu',W/2+115,H/2+63,15,'#c8b68a','center',true); } // ── MENU ────────────────────────────────────────────────────────── function atdMenu(){ const g=ctx.createLinearGradient(0,0,0,H);g.addColorStop(0,'#0e2410');g.addColorStop(1,'#07120a');ctx.fillStyle=g;ctx.fillRect(0,0,W,H); for(const mo of atdMotes){ctx.globalAlpha=mo.a;ctx.fillStyle='#bfe6a0';ctx.beginPath();ctx.arc(mo.x,mo.y,mo.r,0,7);ctx.fill();}ctx.globalAlpha=1; ctx.save();ctx.shadowColor='#7dff6b';ctx.shadowBlur=20;tx('🐜 MRÓWCZA OBRONA',W/2,58,36,'#dfffcf','center',true);ctx.restore(); tx('Tower Defense w świecie Mrówczego Dungeonu — broń Królowej przez kolejne fale',W/2,92,13,'#8fbf7a','center'); // 💠 klejnoty + przyciski Jajka / Kolekcja / powrót do gry tx('💠 '+atdGems,16,22,15,'#bfe6ff','left',true); {const ho=isOR(mouse.x,mouse.y,W-306,10,140,28);rr(W-306,10,140,28,8,ho?'#3a2f10':'#241d0a','#ffd24a',1.8);tx('🥚 Jajka',W-236,24,13,'#ffe08a','center',true);} {const ho=isOR(mouse.x,mouse.y,W-156,10,140,28);rr(W-156,10,140,28,8,ho?'#182f3a':'#0f1e26','#5ab0ff',1.8);tx('📖 Kolekcja',W-86,24,13,'#bfe0ff','center',true);} {const ho=isOR(mouse.x,mouse.y,16,H-40,246,28);rr(16,H-40,246,28,8,ho?'#2a2018':'#1a130c','#8a7550',1.6);tx('◀ Do Mrówczego Dungeonu',139,H-26,12,'#d8c8a0','center',true);} {const ho=isOR(mouse.x,mouse.y,W-250,H-40,234,28);ctx.save();if(ho)ctx.shadowBlur=10,ctx.shadowColor='#5adcff';rr(W-250,H-40,234,28,8,ho?'#12507a':'#0d3a5a','#5adcff',1.8);ctx.restore();tx('👥 Graj ze znajomym',W-133,H-26,12.5,'#cfeaff','center',true);} // 🔥 selektor trudności (wyższa = lepsze nagrody 💠) tx('⚔️ Trudność — wyższa = trudniej, ale więcej 💠:',W/2,120,12.5,'#c8e6b0','center',true); ATD_DIFFS.forEach((d,i)=>{const cw=142,gap=10,x=(W-(5*cw+4*gap))/2+i*(cw+gap),y=130,h=32,on=atdDiff===i,hov=isOR(mouse.x,mouse.y,x,y,cw,h); ctx.save();if(on){ctx.shadowColor=d.col;ctx.shadowBlur=12;} rr(x,y,cw,h,8,on?'rgba(30,40,24,0.96)':'rgba(18,26,14,0.85)',on||hov?d.col:'#3a4a2e',on?2.4:1.3);ctx.restore(); tx(d.ic+' '+d.n,x+cw/2,y+12,12.5,on?'#fff':'#c8d8b0','center',true); tx('nagroda ×'+d.gemMul.toFixed(1)+'💠',x+cw/2,y+24,8.5,on?d.col:'#7a9a6a','center');}); ATD_MAPS.forEach((m,i)=>{const c=i%3,r=(i/3|0),cw=232,ch=134,gap=18,x=(W-(3*cw+2*gap))/2+c*(cw+gap),y=182+r*(ch+gap); const hov=isOR(mouse.x,mouse.y,x,y,cw,ch)&&!m.locked;ctx.save();if(hov){ctx.shadowColor=m.accent||'#7dff6b';ctx.shadowBlur=16;} rr(x,y,cw,ch,12,m.locked?'rgba(18,26,14,0.9)':'rgba(24,44,18,0.95)',m.locked?'#33442a':(hov?(m.accent||'#7dff6b'):'#3f6b34'),m.locked?1.5:2.2);ctx.restore(); rr(x+12,y+12,cw-24,54,7,m.grass||'#356b2b',null);ctx.save();ctx.beginPath();ctx.roundRect(x+12,y+12,cw-24,54,7);ctx.clip(); ctx.strokeStyle=m.dirt||'#8a6038';ctx.lineWidth=12;ctx.lineCap='round';ctx.beginPath();ctx.moveTo(x+6,y+52);ctx.lineTo(x+70,y+22);ctx.lineTo(x+150,y+54);ctx.lineTo(x+cw-16,y+26);ctx.stroke(); ctx.font='20px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(m.ic,x+cw-30,y+34);ctx.restore(); tx(m.n,x+cw/2,y+84,15,m.locked?'#6a7a5e':'#dfffcf','center',true); if(m.locked)tx('🔒 wkrótce',x+cw/2,y+108,12,'#6a7a5e','center'); else{tx('▶ GRAJ',x+cw/2,y+107,13,hov?'#bfffb0':'#7dff6b','center',true);tx(m.mood,x+cw/2,y+123,9.5,'#8fbf7a','center');}}); tx('🏆 Rekord fal: '+(parseInt(localStorage.getItem('md_obronaBest')||'0')||0)+' · 6 rodzajów mrówek, ulepszenia, boss co 10 fal',W/2,H-22,11,'#5f8a52','center'); } function atdMenuClick(mx,my){ if(isOR(mx,my,W-306,10,140,28)){gs='eggs';atdReveal=null;return;} // 🥚 Jajka if(isOR(mx,my,W-156,10,140,28)){gs='collection';return;} // 📖 Kolekcja if(isOR(mx,my,16,H-40,246,28)){try{window.parent.gameClose();}catch(e){}return;} // ◀ powrót do gry if(isOR(mx,my,W-250,H-40,234,28)){atdmpHost=false;atdmpOn=false;atdmpStatus='Stwórz pokój lub dołącz kodem znajomego';gs='coop';return;} // 👥 co-op for(let i=0;i<ATD_DIFFS.length;i++){const cw=142,gap=10,x=(W-(5*cw+4*gap))/2+i*(cw+gap); // 🔥 wybór trudności if(isOR(mx,my,x,130,cw,32)){atdDiff=i;try{localStorage.setItem('md_obronaDiff',atdDiff);}catch(e){}return;}} ATD_MAPS.forEach((m,i)=>{if(m.locked)return;const c=i%3,r=(i/3|0),cw=232,ch=134,gap=18,x=(W-(3*cw+2*gap))/2+c*(cw+gap),y=182+r*(ch+gap);if(isOR(mx,my,x,y,cw,ch))atdStart(m);}); } // ── 🥚 EKRAN JAJEK ──────────────────────────────────────────────── function atdEggBg(){const g=ctx.createLinearGradient(0,0,0,H);g.addColorStop(0,'#0e2410');g.addColorStop(1,'#07120a');ctx.fillStyle=g;ctx.fillRect(0,0,W,H); for(const mo of atdMotes){ctx.globalAlpha=mo.a;ctx.fillStyle='#bfe6a0';ctx.beginPath();ctx.arc(mo.x,mo.y,mo.r,0,7);ctx.fill();}ctx.globalAlpha=1;} function atdEggRect(i){const cw=140,gap=14,x=(W-(5*cw+4*gap))/2+i*(cw+gap);return{x,y:196,w:cw,h:212};} function atdEggsScreen(){ atdEggBg(); ctx.save();ctx.shadowColor='#ffd24a';ctx.shadowBlur=18;tx('🥚 JAJKA MRÓWEK',W/2,54,32,'#ffe08a','center',true);ctx.restore(); tx('Otwieraj jajka za 💠 klejnoty — zdobywaj mrówki w coraz rzadszych wersjach do KOLEKCJI',W/2,88,12,'#9adf5a','center'); tx('💠 '+atdGems+' klejnotów · zdobywasz je za odparte fale i bossów',W/2,116,13,'#bfe6ff','center',true); ATD_EGGS.forEach((e,i)=>{const R=atdEggRect(i),can=atdGems>=e.cost,hov=isOR(mouse.x,mouse.y,R.x,R.y,R.w,R.h); ctx.save();if(hov&&can){ctx.shadowColor=e.col;ctx.shadowBlur=16;} rr(R.x,R.y,R.w,R.h,12,can?'rgba(24,34,18,0.95)':'rgba(20,22,16,0.9)',hov&&can?e.col:(can?'#3f6b34':'#443a2a'),hov&&can?2.4:1.6);ctx.restore(); ctx.save();ctx.font='46px serif';ctx.textAlign='center';ctx.textBaseline='middle'; ctx.shadowColor=e.col;ctx.shadowBlur=12;ctx.fillText('🥚',R.x+R.w/2,R.y+52+Math.sin(frame*0.05+i)*2);ctx.restore(); tx(e.n,R.x+R.w/2,R.y+96,13,can?'#dfffcf':'#8a9a7a','center',true); // szanse let yy=R.y+118;for(const k of ATD_RARORDER)if(e.odds[k]){tx(ATD_RARDOT[k]+' '+e.odds[k]+'%',R.x+R.w/2,yy,9.5,ATD_RARC[k],'center');yy+=14;} rr(R.x+14,R.y+R.h-34,R.w-28,26,7,can?(hov?'#2a7d2a':'#1a5a1a'):'#2a2418',can?'#7dff6b':'#5a4a3a',1.6); tx(can?('OTWÓRZ '+e.cost+'💠'):(e.cost+'💠'),R.x+R.w/2,R.y+R.h-21,12,can?'#fff':'#8a7f6a','center',true); }); {const ho=isOR(mouse.x,mouse.y,16,H-40,110,28);rr(16,H-40,110,28,8,ho?'#2a4a1e':'#16300f','#4f8a41',1.5);tx('◀ Wróć',71,H-26,12,'#dfffcf','center',true);} if(atdReveal)atdRevealDraw(); } function atdRevealDraw(){ const r=atdReveal,T=ATD_TW[r.id],RC=ATD_RARC[r.rar]; ctx.save();ctx.globalAlpha=0.72;ctx.fillStyle='#000';ctx.fillRect(0,0,W,H);ctx.restore(); const cx=W/2,cy=H/2-10,pop=cl((170-r.t)/12,0,1); ctx.save();ctx.translate(cx,cy);ctx.scale(pop,pop); ctx.shadowColor=RC;ctx.shadowBlur=30;rr(-120,-96,240,192,16,'#0e1c0b',RC,3);ctx.restore(); ctx.save();ctx.font='60px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.globalAlpha=pop; ctx.shadowColor=RC;ctx.shadowBlur=20;ctx.fillText(T.ic,cx,cy-30);ctx.restore();ctx.globalAlpha=1; tx((ATD_RARDOT[r.rar]||'')+' '+(ATD_RARNAME[r.rar]||''),cx,cy+18,16,RC,'center',true); tx(T.n,cx,cy+40,15,'#dfffcf','center',true); tx(r.better?'✨ NOWY REKORD RZADKOŚCI! wieża silniejsza':'duplikat — zwrot +'+r.refund+'💠',cx,cy+66,11,r.better?'#ffe08a':'#9fc48a','center',true); tx('(kliknij, aby zamknąć)',cx,cy+88,9.5,'#7a9a6a','center'); } function atdEggsClick(mx,my){ if(atdReveal){atdReveal=null;return;} if(isOR(mx,my,16,H-40,110,28)){gs='menu';return;} ATD_EGGS.forEach((e,i)=>{const R=atdEggRect(i);if(isOR(mx,my,R.x,R.y,R.w,R.h))atdOpenEgg(e);}); } // ── 📖 EKRAN KOLEKCJI ───────────────────────────────────────────── function atdColRect(i){const cw=232,ch=150,gap=20,c=i%3,r=(i/3|0),x=(W-(3*cw+2*gap))/2+c*(cw+gap),y=176+r*(ch+gap);return{x,y,w:cw,h:ch};} function atdCollectionScreen(){ atdEggBg(); ctx.save();ctx.shadowColor='#5ab0ff';ctx.shadowBlur=18;tx('📖 KOLEKCJA MRÓWEK',W/2,54,32,'#bfe0ff','center',true);ctx.restore(); tx('Twoja najlepsza wersja każdej mrówki — rzadkość mnoży obrażenia/dochód w KAŻDEJ grze',W/2,90,12,'#8fbf7a','center'); let owned=0,total=ATD_ORDER.length*6;ATD_ORDER.forEach(id=>owned+=(atdCol[id]||0)+1); tx('💠 '+atdGems+' · moc kolekcji: '+owned+'/'+total,W/2,116,12,'#bfe6ff','center',true); ATD_ORDER.forEach((id,i)=>{const T=ATD_TW[id],R=atdColRect(i),rar=atdRar(id),RC=ATD_RARC[rar]; ctx.save();ctx.shadowColor=RC;ctx.shadowBlur=8;rr(R.x,R.y,R.w,R.h,12,'rgba(20,30,16,0.95)',RC,2);ctx.restore(); ctx.save();ctx.font='34px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(T.ic,R.x+40,R.y+42);ctx.restore(); tx(T.n,R.x+70,R.y+30,15,'#dfffcf','left',true); tx((ATD_RARDOT[rar]||'')+' '+(ATD_RARNAME[rar]||''),R.x+70,R.y+50,12,RC,'left',true); tx('obrażenia/dochód ×'+ATD_RARMUL[rar].toFixed(2),R.x+16,R.y+78,11,'#9fc48a','left'); // paski rzadkości (6 kropek) const oi=atdCol[id]||0; ATD_RARORDER.forEach((rk,k)=>{const px=R.x+22+k*34,py=R.y+108; ctx.beginPath();ctx.arc(px,py,7,0,7);ctx.fillStyle=k<=oi?ATD_RARC[rk]:'rgba(255,255,255,0.08)';ctx.fill(); if(k===oi){ctx.strokeStyle='#fff';ctx.lineWidth=1.4;ctx.stroke();} ctx.font='8px serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillStyle=k<=oi?'#0a1408':'#000';}); tx('base → mythic',R.x+R.w/2,R.y+130,8.5,'#5f8a52','center'); }); {const ho=isOR(mouse.x,mouse.y,16,H-40,110,28);rr(16,H-40,110,28,8,ho?'#2a4a1e':'#16300f','#4f8a41',1.5);tx('◀ Wróć',71,H-26,12,'#dfffcf','center',true); const ho2=isOR(mouse.x,mouse.y,W-126,H-40,110,28);rr(W-126,H-40,110,28,8,ho2?'#3a2f10':'#241d0a','#ffd24a',1.5);tx('🥚 Jajka',W-71,H-26,12,'#ffe08a','center',true);} } function atdCollectionClick(mx,my){ if(isOR(mx,my,16,H-40,110,28)){gs='menu';return;} if(isOR(mx,my,W-126,H-40,110,28)){gs='eggs';atdReveal=null;return;} } // ── 👥 CO-OP ONLINE (kod pokoju, PeerJS) ────────────────────────── // Wzorowane na sprawdzonym „Gra z Kolegami" z index.html. HOST symuluje całą // grę i strumieniuje świat; GOŚĆ to cienki klient — wysyła akcje (postaw/ulepsz/ // sprzedaj/fala) i rysuje stan hosta. Wspólna Królowa, wspólny Pokarm. // Pokój: mrowobrona-KOD (własny prefiks, nie koliduje z pokojami innej gry). let atdmpPeer=null,atdmpConn=null,atdmpHost=false,atdmpCode='',atdmpStatus='Wybierz opcję',atdmpLib=0,atdmpOn=false,atdmpOx=-99,atdmpOy=-99,atdmpSyncT=0; function atdmpGuest(){return atdmpOn&&!atdmpHost;} function atdmpConnOk(){return atdmpConn&&atdmpConn.open;} function atdmpLoadLib(cb){ if(window.Peer){atdmpLib=2;cb(true);return;} if(atdmpLib===1)return; atdmpLib=1;atdmpStatus='Ładowanie sieci…'; const urls=['https://unpkg.com/peerjs@1.5.4/dist/peerjs.min.js','https://cdn.jsdelivr.net/npm/peerjs@1.5.4/dist/peerjs.min.js']; let i=0;(function nx(){if(i>=urls.length){atdmpLib=3;atdmpStatus='❌ Brak internetu — co-op wymaga połączenia';cb(false);return;} const s=document.createElement('script');s.src=urls[i++];s.onload=()=>{atdmpLib=2;cb(true);};s.onerror=()=>{s.remove();nx();};document.head.appendChild(s);})(); } function atdmpCode4(){const A='ABCDEFGHJKLMNPRSTUWXYZ23456789';let c='';for(let i=0;i<4;i++)c+=A[(Math.random()*A.length)|0];return c;} function atdmpCleanup(full){if(atdmpConn){try{atdmpConn.close()}catch(e){}atdmpConn=null;}if(full&&atdmpPeer){try{atdmpPeer.destroy()}catch(e){}atdmpPeer=null;}atdmpOn=false;} function atdmpSend(o){if(atdmpConnOk()){try{atdmpConn.send(o)}catch(e){}}} function atdmpWire(c){atdmpConn=c; c.on('data',d=>{if(c===atdmpConn)atdmpOnData(d);}); c.on('close',()=>{if(c!==atdmpConn)return;atdmpConn=null;atdmpStatus='😢 Znajomy się rozłączył';if(gs==='game'){atdmpOn=false;gs='coop';}}); c.on('error',()=>{});} function atdmpCreate(){ atdmpLoadLib(ok=>{if(!ok||gs!=='coop')return; atdmpCleanup(true);atdmpCode=atdmpCode4();atdmpHost=true;atdmpStatus='Tworzenie pokoju…'; try{atdmpPeer=new Peer('mrowobrona-'+atdmpCode);}catch(e){atdmpStatus='❌ Błąd sieci';return;} atdmpPeer.on('open',()=>{atdmpStatus='✅ Kod dla znajomego: '+atdmpCode+' · czekam na gracza…';}); atdmpPeer.on('connection',c=>{if(atdmpConnOk()||gs==='game'){try{c.close()}catch(e){}return;} atdmpWire(c);c.on('open',()=>{atdmpStatus='👥 ZNAJOMY DOŁĄCZYŁ! Wybierz mapę, by zacząć wspólną obronę.';atdmpSend({t:'hi'});});}); atdmpPeer.on('error',e=>{atdmpStatus='❌ Błąd: '+(e.type==='unavailable-id'?'spróbuj ponownie':e.type);}); }); } function atdmpJoin(){ const code=(prompt('Wpisz kod pokoju od znajomego:')||'').trim().toUpperCase(); if(!code)return; atdmpLoadLib(ok=>{if(!ok||gs!=='coop')return; atdmpCleanup(true);atdmpHost=false;atdmpStatus='Łączenie z pokojem '+code+'…'; try{atdmpPeer=new Peer();}catch(e){atdmpStatus='❌ Błąd sieci';return;} atdmpPeer.on('open',()=>{const c=atdmpPeer.connect('mrowobrona-'+code,{reliable:true}); atdmpWire(c);c.on('open',()=>{atdmpStatus='👥 POŁĄCZONO! Czekaj — host wybiera mapę…';atdmpSend({t:'hi'});}); setTimeout(()=>{if(gs==='coop'&&!atdmpConnOk())atdmpStatus='❌ Nie znaleziono pokoju '+code;},7000);}); atdmpPeer.on('error',e=>{atdmpStatus='❌ Błąd: '+(e.type==='peer-unavailable'?('nie ma pokoju '+code):e.type);}); }); } function atdmpStartHost(m){atdmpOn=true;atdmpHost=true;atdStart(m);atdmpSend({t:'start',map:m.id,diff:atdDiff});} const ATD_ENEK=Object.keys(ATD_ENE); // stała kolejność kluczy wrogów (host↔gość identyczna) function atdmpOnData(d){try{ if(!d||!d.t)return; if(d.t==='hi')return; if(d.t==='start'&&!atdmpHost){const m=ATD_MAPS.find(x=>x.id===d.map)||ATD_MAPS[0];atdDiff=cl(d.diff|0,0,ATD_DIFFS.length-1);atdmpOn=true;atdStart(m);return;} if(d.t==='act'&&atdmpHost){atdmpApplyAct(d);return;} if(d.t==='cur'){atdmpOx=d.x;atdmpOy=d.y;return;} if(d.t==='state'&&!atdmpHost){atdmpApplyState(d);return;} if(d.t==='bye'){atdmpStatus='😢 Znajomy wyszedł z gry';if(gs==='game'){atdmpOn=false;gs='coop';}return;} }catch(e){}} function atdmpApplyAct(d){ // HOST wykonuje akcję gościa (walidacja przez zwykłe funkcje) if(d.a==='wave')atdStartWave(); else if(d.a==='place'){atdBuild=null;atdPlace(d.id,d.cx,d.cy);} else if(d.a==='upg'){const t=atdTowerAt(d.cx,d.cy);if(t)atdUpgrade(t);} else if(d.a==='sell'){const t=atdTowerAt(d.cx,d.cy);if(t)atdSell(t);} } function atdmpSendState(){ // HOST → GOŚĆ: skompresowany świat const tw=atdTowers.map(t=>[t.cx,t.cy,ATD_ORDER.indexOf(t.id),t.lv,ATD_RARORDER.indexOf(t.rar),t.stunT||0]); const en=atdEnemies.map(e=>[Math.round(e.x),Math.round(e.y),ATD_ENEK.indexOf(e.id),Math.round(e.hp),Math.round(e.mhp),(e.slowT>0?1:0)|(e.poisonT>0?2:0)|(e.burnT>0?4:0),e.seg]); atdmpSend({t:'state',mp:atdMap.id,di:atdDiff,f:Math.round(atdFood),g:atdGems,w:atdWave,wa:atdWaveActive?1:0,q:Math.round(atdQHp),qm:atdQHpMax,k:atdKills,o:atdOver,m:atdMsgT>0?atdMsg:'',hx:Math.round(mouse.x),hy:Math.round(mouse.y),tw,en}); } function atdmpApplyState(d){ // GOŚĆ odtwarza świat hosta if(atdMap==null||atdMap.id!==d.mp){const m=ATD_MAPS.find(x=>x.id===d.mp);if(m){atdDiff=d.di|0;atdStart(m);atdmpOn=true;}} atdFood=d.f;atdGems=d.g;atdWave=d.w;atdWaveActive=!!d.wa;atdQHp=d.q;atdQHpMax=d.qm;atdKills=d.k;atdOver=d.o;atdmpOx=d.hx;atdmpOy=d.hy; if(d.m){atdMsg=d.m;atdMsgT=100;} atdTowers=d.tw.map(a=>{const id=ATD_ORDER[a[2]],rar=ATD_RARORDER[a[4]];return{id,cx:a[0],cy:a[1],px:atdPX(a[0]),py:atdPY(a[1]),lv:a[3],rar,rmul:ATD_RARMUL[rar],stunT:a[5],cd:0};}); atdEnemies=d.en.map(a=>{const id=ATD_ENEK[a[2]];return{id,def:ATD_ENE[id],x:a[0],y:a[1],hp:a[3],mhp:a[4],slowT:(a[5]&1)?30:0,poisonT:(a[5]&2)?30:0,burnT:(a[5]&4)?30:0,seg:a[6],hit:0};}); for(let i=0;i<atdGrid.length;i++)if(atdGrid[i]===5)atdGrid[i]=0; // odśwież zajętość pól for(const t of atdTowers)atdGrid[atdIdx(t.cx,t.cy)]=5; if(atdSelTw)atdSelTw=atdTowerAt(atdSelTw.cx,atdSelTw.cy); // re-wskaż wybraną wieżę } // ── EKRAN LOBBY CO-OP ── function atdCoopScreen(){ atdEggBg(); ctx.save();ctx.shadowColor='#5adcff';ctx.shadowBlur=18;tx('👥 GRAJ ZE ZNAJOMYM',W/2,58,32,'#bfe0ff','center',true);ctx.restore(); tx('Wspólnie brońcie tej samej Królowej — obaj stawiacie mrówki, wspólny Pokarm i fale',W/2,92,12.5,'#8fbf7a','center'); ctx.save();ctx.globalAlpha=0.9;rr(W/2-330,112,660,46,10,'#0e1c26','#3a5a6a',1.5);ctx.restore(); (''+atdmpStatus).split('\n').forEach((ln,i)=>tx(ln,W/2,130+i*16,12,'#cfeaff','center',true)); const conn=atdmpConnOk(); if(!conn){ const b1=isOR(mouse.x,mouse.y,W/2-230,192,220,60),b2=isOR(mouse.x,mouse.y,W/2+10,192,220,60); rr(W/2-230,192,220,60,12,b1?'#12507a':'#0d3a5a','#5adcff',2.2);tx('➕ Stwórz pokój',W/2-120,216,17,'#dff','center',true);tx('dostaniesz kod dla znajomego',W/2-120,235,9.5,'#9cc','center'); rr(W/2+10,192,220,60,12,b2?'#12507a':'#0d3a5a','#5adcff',2.2);tx('🔑 Dołącz kodem',W/2+120,216,17,'#dff','center',true);tx('wpisz kod od znajomego',W/2+120,235,9.5,'#9cc','center'); tx('Kod pokoju wpiszesz w okienku, które się pojawi. Grasz przez internet — jak w „Gra z Kolegami".',W/2,286,10.5,'#7a9aaa','center'); } else if(atdmpHost){ tx('✅ Połączeni! Wybierz mapę — start dla obu:',W/2,182,13.5,'#c8e6b0','center',true); ATD_MAPS.forEach((m,i)=>{const c=i%3,r=(i/3|0),cw=210,ch=66,gap=16,x=(W-(3*cw+2*gap))/2+c*(cw+gap),y=204+r*(ch+gap),hov=isOR(mouse.x,mouse.y,x,y,cw,ch); ctx.save();if(hov){ctx.shadowColor=m.accent||'#7dff6b';ctx.shadowBlur=12;} rr(x,y,cw,ch,10,hov?'rgba(30,50,24,0.96)':'rgba(20,32,16,0.9)',hov?(m.accent||'#7dff6b'):'#3f6b34',hov?2.2:1.4);ctx.restore(); ctx.save();ctx.font='26px serif';ctx.textAlign='left';ctx.textBaseline='middle';ctx.fillText(m.ic,x+14,y+ch/2);ctx.restore(); tx(m.n,x+48,y+ch/2-7,14,'#dfffcf','left',true);tx('▶ start dla obu graczy',x+48,y+ch/2+12,10,'#7dff6b','left');}); } else { tx('⏳ Połączono! Czekaj — host wybiera mapę…',W/2,240,16,'#ffe08a','center',true); } {const ho=isOR(mouse.x,mouse.y,16,H-40,150,28);rr(16,H-40,150,28,8,ho?'#2a4a1e':'#16300f','#4f8a41',1.5);tx('◀ Wróć',91,H-26,12,'#dfffcf','center',true);} } function atdCoopClick(mx,my){ if(isOR(mx,my,16,H-40,150,28)){atdmpCleanup(true);gs='menu';return;} if(!atdmpConnOk()){ if(isOR(mx,my,W/2-230,192,220,60)){atdmpCreate();return;} if(isOR(mx,my,W/2+10,192,220,60)){atdmpJoin();return;} } else if(atdmpHost){ ATD_MAPS.forEach((m,i)=>{const c=i%3,r=(i/3|0),cw=210,ch=66,gap=16,x=(W-(3*cw+2*gap))/2+c*(cw+gap),y=204+r*(ch+gap);if(isOR(mx,my,x,y,cw,ch))atdmpStartHost(m);}); } } function atdOverClick(mx,my){ if(atdmpGuest())return; // gość: restartem steruje host if(isOR(mx,my,W/2-210,H/2+40,190,46)){atdStart(atdMap);if(atdmpHost&&atdmpOn)atdmpSend({t:'start',map:atdMap.id,diff:atdDiff});} else if(isOR(mx,my,W/2+20,H/2+40,190,46)){if(atdmpOn){atdmpSend({t:'bye'});atdmpOn=false;gs='coop';}else gs='menu';} } // klik na ekranie przegranej przechwytujemy w atdGameClick const _origGameClick=atdGameClick; atdGameClick=function(mx,my){if(atdOver){atdOverClick(mx,my);return;}_origGameClick(mx,my);}; // ── PĘTLA ───────────────────────────────────────────────────────── function loop(){atdUpdate();atdDraw();requestAnimationFrame(loop);} for(let k=0;k<26;k++)atdMotes.push({x:Math.random()*W,y:Math.random()*H,vx:0.1+Math.random()*0.25,vy:-0.05+Math.random()*0.12,r:0.8+Math.random()*1.6,a:0.15+Math.random()*0.3}); atdColLoad(); // 💎 wczytaj trwałą kolekcję i klejnoty requestAnimationFrame(loop); </script> </body> </html>