Молот Роскомнадзора: Драка · АЛЬФА 1.0
by EpicKoala43904 lines109.2 KB
<!DOCTYPE html>
<html lang="ru"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Молот Роскомнадзора: Драка · АЛЬФА 1.0</title>
<style>
:root{--bg:#10131a;--fg:#f2f4f8;--red:#e5383b;box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
html{height:100%;scroll-padding-top:env(safe-area-inset-top,0px)}
body{height:100%;margin:0;background:var(--bg);color:var(--fg);font-family:"Courier New",Courier,monospace;font-weight:700;overflow:hidden;touch-action:none;user-select:none;-webkit-user-select:none}
canvas{display:block;position:fixed;inset:0;width:100vw;height:100vh;image-rendering:pixelated}
.b{position:fixed;border:4px solid #fff;border-radius:0;box-shadow:4px 4px 0 #000;background:#e5383b;color:#fff;font-size:22px;display:none;align-items:center;justify-content:center;z-index:2;touch-action:none}
#atk{right:20px;bottom:calc(28px + env(safe-area-inset-bottom,0px));width:96px;height:96px}
#spc{right:126px;bottom:calc(20px + env(safe-area-inset-bottom,0px));width:66px;height:66px;font-size:18px;background:#555;filter:grayscale(1)}
#spc.rdy{background:#f59e0b;filter:none;color:#000}
#ov{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;text-align:center;background:rgba(10,12,18,.94);padding:24px;z-index:3;overflow-y:auto;touch-action:pan-y}#ov>:first-child{margin-top:auto}#ov>:last-child{margin-bottom:auto}
#ov h1{margin:0 0 8px;font-size:28px;color:var(--red)}
#ov p{margin:4px 0;max-width:340px;line-height:1.4;opacity:.92}
.stamp{font-size:26px;font-weight:900;color:var(--red);border:4px solid var(--red);padding:6px 14px;transform:rotate(-6deg);margin:10px 0}
button.go{margin-top:18px;padding:14px 28px;font-size:18px;font-weight:700;border:0;border-radius:0;box-shadow:4px 4px 0 #000;background:var(--red);color:#fff;font-family:inherit}
.it{display:flex;justify-content:space-between;align-items:center;width:100%;max-width:360px;box-sizing:border-box;border:3px solid #fff3;padding:8px 10px;margin:4px 0;text-align:left;gap:8px}.sm{margin:0!important;padding:8px 10px!important;font-size:14px!important;min-width:84px}button:disabled{opacity:.4}input{font:inherit;padding:8px;border:3px solid #fff;background:#000;color:#fff;width:150px;border-radius:0;box-sizing:border-box}small{opacity:.7}#gdg{right:202px;bottom:calc(20px + env(safe-area-inset-bottom,0px));width:66px;height:66px;font-size:13px;background:#2563eb}#gdg.cd,#mgd.cd{opacity:.4}#mgd{right:278px;bottom:calc(20px + env(safe-area-inset-bottom,0px));width:66px;height:66px;font-size:12px;background:#d97706}#ver{position:fixed;left:8px;bottom:calc(6px + env(safe-area-inset-bottom,0px));font-size:12px;opacity:.55;z-index:1;pointer-events:none;letter-spacing:1px}#prb{right:20px;bottom:calc(134px + env(safe-area-inset-bottom,0px));width:66px;height:66px;font-size:12px;background:#0891b2}#prb.cd{opacity:.4}#ult{right:100px;bottom:calc(104px + env(safe-area-inset-bottom,0px));width:76px;height:76px;font-size:13px;background:#6b21a8}#ult.rdy{background:#a855f7;box-shadow:0 0 18px #a855f7}</style></head><body>
<canvas id="c"></canvas><div id="ver">АЛЬФА 1.0</div>
<div class="b" id="prb">ПАРИР</div><div class="b" id="ult">УЛЬТА</div><div class="b" id="mgd">МАМА</div><div class="b" id="gdg">БРОСОК</div><div class="b" id="spc">БАН</div><div class="b" id="atk">УДАР</div>
<div id="ov"><h1>МОЛОТ РКН: ДРАКА 8-BIT</h1><p style="margin:0 0 8px;opacity:.75"><small>версия АЛЬФА 1.0</small></p>
<p>Ты — инспектор с огромным молотом. Приложения озверели и лезут в драку. Круши их волнами!</p>
<p><b>Управление:</b> палец слева — двигаться, УДАР — молот по дуге (цель выбирается сам), БАН — удар на всю арену, когда шкала полна. На ПК: WASD, пробел, E.</p>
<p>VPN убегает, но если поймаешь — вылечит.</p><p>На 2-й волне в клетке появится <b>мама-птица</b>: постой рядом 2 секунды и спаси её — получишь награду, а она останется с тобой до конца боя и будет стрелять из базуки птенцами, которые клюют врагов.</p><p>Кнопка ПАРИР (как в ULTRAKILL): нажми в самый последний момент перед ударом врага или выстрелом — время замрёт, снаряд полетит обратно, а ты вылечишься. Окно очень короткое! У каждого персонажа своя ульта (фиолетовая кнопка, заряжается убийствами и временем).</p>
<button class="go" id="go">В бой!</button><button class="go" id="shp">МАГАЗИН</button><button class="go" id="set">НАСТРОЙКИ</button><button class="go" id="edb">РЕДАКТОР</button><button class="go" id="cmb">КАМПАНИЯ</button></div>
<script>
const cv=document.getElementById('c'),x=cv.getContext('2d'),ov=document.getElementById('ov'),$=id=>document.getElementById(id);
let W,H;
const S=3,sn=v=>Math.round(v/S)*S;function rs(){W=innerWidth;H=innerHeight;cv.width=Math.ceil(W/S);cv.height=Math.ceil(H/S);x.setTransform(1/S,0,0,1/S,0,0);x.imageSmoothingEnabled=false}
addEventListener('resize',rs);rs();
const ET={
tg:{n:'Telegram',c:'#2aabee',e:'✈️',hp:3,sp:70,r:24,dmg:8,pts:10,baz:1},
yt:{n:'YouTube',c:'#e11d1d',e:'▶️',hp:7,sp:55,r:26,dmg:14,pts:25},
dc:{n:'Discord',c:'#5865f2',e:'🎮',hp:2,sp:130,r:22,dmg:7,pts:15},
tt:{n:'Зомби-ТикТок',c:'#6b8f3a',e:'🧟',hp:4,sp:55,r:23,dmg:10,pts:30,zom:1},
vpn:{n:'VPN',c:'#7c3aed',e:'🛡️',hp:3,sp:120,r:22,dmg:0,pts:40,flee:1},
rb:{n:'Роблокс-Демон',c:'#7a0f1a',e:'👹',hp:6,sp:70,r:24,dmg:12,pts:60,demon:1},
mon:{n:'ГИГА-VPN',c:'#7c3aed',e:'👹',hp:70,sp:50,r:58,dmg:24,pts:800,boss:1,mon:1,zz:120},
boss:{n:'МЕГА-МЕССЕНДЖЕР',c:'#f59e0b',e:'👾',hp:40,sp:60,r:48,dmg:20,pts:300,boss:1}};
const U=[{id:'dmg',n:'Сила молота',d:'+1 урон за удар',max:10,base:50},{id:'reach',n:'Длина рукояти',d:'+8% дальность',max:8,base:80},{id:'hp',n:'Броня',d:'+20 макс. здоровья',max:10,base:60},{id:'spd',n:'Кроссовки',d:'+6% скорость',max:8,base:70},{id:'cd',n:'Быстрые руки',d:'быстрее замах',max:8,base:90},{id:'sp',n:'Заряд БАНа',d:'шкала растёт быстрее',max:8,base:100}];
const SK=[
{n:'Сталь',p:0,h:'#c9ccd3',s:'#8b5a2b',b:'#2b4c9b'},
{n:'Золото',p:5000,h:'#f2c14e',s:'#8b5a2b',b:'#8a6d1d',y:'#fff1b0',pp:'#5a4610',pc:['#f2c14e','#fff1b0'],cm:1.1,pk:'+10% монет'},
{n:'Неон',p:25000,h:'#39ff14',s:'#1b5a10',b:'#1b1b3a',y:'#39ff14',pp:'#0f0f28',pc:['#39ff14','#b6ff9e']},
{n:'Розовый',p:100000,h:'#ff5cf0',s:'#6a2a6a',b:'#7a1fa2',y:'#ffd6f7',pp:'#4a1266',pc:['#ff5cf0','#ffd6f7']},
{n:'Лава',p:1000000,h:'#ff5a1f',s:'#3a1a0a',b:'#7a1f0f',y:'#ffb703',pp:'#3a0f08',pc:['#ff5a1f','#ffb703','#ff2d2d']},
{n:'Лёд',p:10000000,h:'#7fe7ff',s:'#4a6b8a',b:'#3b82c4',y:'#e6faff',pp:'#1e4a80',pc:['#7fe7ff','#e6faff','#4dc3ff']},
{n:'Тьма',p:100000000,h:'#3a2a5a',s:'#1a1a22',b:'#241a3a',y:'#a06bff',pp:'#120c1e',pc:['#a06bff','#3a2a5a','#6b3fd4']},
{n:'Радуга',p:1000000000,rb:1,s:'#8b5a2b',b:'#4a3a8a',y:'#ffffff',pp:'#2a2060',pc:['#ff4d4d','#ffd23f','#5ee05e','#4dc3ff','#c77dff'],cm:1.25,pk:'+25% монет'},
{n:'МАНГО',p:3333333333,mango:1,s:'#5a3a1a',b:'#ff9f1c',y:'#3fb950',pp:'#d9480f',pc:['#ff5a36','#ff9f1c','#ffd23f','#9ad64a'],cm:1.5,db:1,pk:'Король-манго в очках и с цепью AURA! +50% монет, +1 урон'}];
const SKX={1:{gl:'#ffd23f',dc:'gem',hat:'crown'},2:{gl:'#39ff14',dc:'str',hat:'visor'},3:{gl:'#ff5cf0',dc:'heart',hat:'bow'},4:{gl:'#ff5a1f',dc:'crk',hat:'horns'},5:{gl:'#7fe7ff',dc:'spk',hat:'icec'},6:{gl:'#a06bff',dc:'eye',hat:'eyes'},7:{gl:'#ffffff',hat:'halo'},8:{gl:'#ffb703'}};
for(const i in SKX)Object.assign(SK[i],SKX[i]);
SK.push({n:'Мясник',p:2500000000,cb:1,h:'#9aa0a6',s:'#3a2a20',b:'#2f2f38',y:'#c0392b',pp:'#1a1a22',pc:['#ff2d2d','#ffffff','#7a0f1a'],gl:'#ff2d2d',hat:'butch',cm:1.2,db:2,crit:.15,hs:3,pk:'лом вместо молота: +2 урона, 15% крит ×2, +3 здоровья за убийство, +20% монет'});
SK.push({n:'Стример',p:1500000000,h:'#2b2b33',s:'#8b5a2b',b:'#1f2937',y:'#ffd23f',pp:'#111827',pc:['#ffd23f','#ff2d6f','#00e5ff'],gl:'#ff2d6f',dc:'live',hat:'streamer',cm:1.3,pk:'+30% монет (донаты!), кепка, наушники, золотая цепь'});
SK.push({n:'Нуб',p:500000,h:'#ef4444',s:'#8b5a2b',cm:1.1,pk:'+10% монет',rows:['....oooooooo....', '...ohhhhhhhho...', '...ohhhhhhhho...', '...offffffffo...', '...ofeffffefo...', '...offfmmfffo...', '...oooooooooo...', 'oaaottttttttoaao', 'oaaottttttttoaao', 'oxxottttttttoxxo', '.oooottttttoooo.', '...ollllllllo...', '...ollloolllo...', '...ollloolllo...', '...ollloolllo...', '...oooo..oooo...'],pal:{'o': '#0b0b12', 'h': '#ffd23f', 'f': '#ffd23f', 'e': '#0b0b12', 'm': '#7a1a1a', 'a': '#ffd23f', 'x': '#ffd23f', 't': '#2563eb', 'l': '#16a34a'}},
{n:'Выживший',p:3000000,h:'#9ca3af',s:'#8b5a2b',hs:1,pk:'+1 здоровье за каждое убийство',rows:['....oooooooo....', '...ohhhhhhhho...', '...ohhhhhhhho...', '...offffffffo...', '...ofeffffefo...', '...offfmmfffo...', '...oooooooooo...', 'oaaottttttttoaao', 'oaaottttttttoaao', 'oxxottttttttoxxo', '.oooottttttoooo.', '...ollllllllo...', '...ollloolllo...', '...ollloolllo...', '...ollloolllo...', '...oooo..oooo...'],pal:{'o': '#0b0b12', 'h': '#1f2937', 'f': '#e0b890', 'e': '#0b0b12', 'm': '#7a3a2a', 'a': '#ea580c', 'x': '#e0b890', 't': '#ea580c', 'l': '#1e3a8a'}},
{n:'Азартный игрок',p:30000000,h:'#ffd23f',s:'#4b3621',dc:'gem',crit:0.12,cm:1.15,pk:'12% крит ×2 и +15% монет',rows:['....oooooooo....', '...ohhhhhhhho...', '...ohhhhhhhho...', '...offffffffo...', '...ofeffffefo...', '...offfmmfffo...', '...oooooooooo...', 'oaaottwrwtttoaao', 'oaaotttrttttoaao', 'oxxotttrttttoxxo', '.oooottttttoooo.', '...ollllllllo...', '...ollloolllo...', '...ollloolllo...', '...ollloolllo...', '...oooo..oooo...'],pal:{'o': '#0b0b12', 'h': '#111111', 'f': '#e0b890', 'e': '#0b0b12', 'm': '#7a1a1a', 'a': '#1f1f26', 'x': '#e0b890', 't': '#1f1f26', 'l': '#15151b', 'r': '#e5383b', 'w': '#ffffff'}},
{n:'Медик',p:120000000,h:'#f8fafc',s:'#8b5a2b',dc:'cross',hs:3,pk:'+3 здоровья за каждое убийство',rows:['....oooooooo....', '...ohhhhhhhho...', '...ohhhhhhhho...', '...offffffffo...', '...ofeffffefo...', '...offfmmfffo...', '...oooooooooo...', 'oaaotttrrtttoaao', 'oaaottrrrrttoaao', 'oxxotttrrtttoxxo', '.oooottttttoooo.', '...ollllllllo...', '...ollloolllo...', '...ollloolllo...', '...ollloolllo...', '...oooo..oooo...'],pal:{'o': '#0b0b12', 'h': '#f8fafc', 'f': '#e0b890', 'e': '#0b0b12', 'm': '#7a3a2a', 'a': '#f8fafc', 'x': '#e0b890', 't': '#f8fafc', 'l': '#94a3b8', 'r': '#e5383b'}},
{n:'Слэшер',p:800000000,h:'#9aa0a6',s:'#4b3621',mc:1,gl:'#ff2d2d',pc:['#ff2d2d', '#7a0f1a'],db:3,crit:0.15,pk:'мачете вместо молота, +3 урона, 15% крит',rows:['....oooooooo....', '...ohhhhhhhho...', '...ohhhhhhhho...', '...offffffffo...', '...ofeffffefo...', '...offfmmfffo...', '...oooooooooo...', 'oaaotrttttttoaao', 'oaaorttttrttoaao', 'oxxottrtttrtoxxo', '.oooottttttoooo.', '...ollllllllo...', '...ollloolllo...', '...ollloolllo...', '...ollloolllo...', '...oooo..oooo...'],pal:{'o': '#0b0b12', 'h': '#0b0b12', 'f': '#c9ced6', 'e': '#000000', 'm': '#0b0b12', 'a': '#2a2a30', 'x': '#c9ced6', 't': '#2a2a30', 'l': '#1a1a22', 'r': '#b91c1c'}},
{n:'Тёмный глитч',p:1200000000,h:'#00e5ff',s:'#111111',dc:'str',gl:'#ff2d6f',hat:'glitch',pc:['#00e5ff', '#ff2d6f', '#ffffff'],db:4,cm:1.3,pk:'+4 урона, +30% монет, глитч-эффект',rows:['....oooooooo....', '...ohhhhhhhho...', '...ohhhhhhhho...', '...offfffpffo...', '...ofeffffefo...', '...ofcfmmfffo...', '...oooooooooo...', 'oaaocttttttcoaao', 'oaaotpttttptoaao', 'oxxottctttttoxxo', '.oooottttttoooo.', '...ollllllllo...', '...oclloolllo...', '...ollloolplo...', '...ollloolllo...', '...oooo..oooo...'],pal:{'o': '#0b0b12', 'h': '#0b0b12', 'f': '#e5e7eb', 'e': '#ff2d6f', 'm': '#0b0b12', 'a': '#0b0b12', 'x': '#e5e7eb', 't': '#0b0b12', 'l': '#0b0b12', 'c': '#00e5ff', 'p': '#ff2d6f'}});
const SC=SK.map(k=>k.p);
const CH=[
{n:'Инспектор',p:0,atk:'hammer',rng:145,arc:1.4,dm:1,kb:440,cd:.45,pc:['#fff'],d:'Огромный молот по дуге'},
{n:'Адмир',p:250000,atk:'burp',rng:260,arc:.6,dm:3,kb:900,cd:.8,pc:['#9be564','#c8f169','#5aa02c'],d:'СИЛЬНО РЫГАЕТ: узкий конус, огромный урон и отброс'},
{n:'Баба Валя',p:2000000,atk:'throw',rng:0,arc:0,dm:2,kb:300,cd:.4,pc:['#ffb703'],d:'Кидает два тапка веером'},
{n:'Качок Гена',p:15000000,atk:'stomp',rng:135,arc:4,dm:2,kb:600,cd:.55,pc:['#c9a26b'],d:'Топает так, что бьёт всех вокруг'},
{n:'Основатель',p:60000000,atk:'vk',rng:0,arc:0,dm:1,kb:350,cd:.3,pc:['#0077ff'],d:'Стреляет значками ВК, каждый пробивает 2 врагов'},
{n:'Мистер Стантик',p:25000000,atk:'ram',rng:0,arc:0,dm:3,kb:520,cd:1.2,pc:['#ffd23f','#ff7a1a'],d:'Ездит на байке: на ходу давит всех, кого касается (и не получает от них урон), а таран сносит толпу'},
{n:'01@',p:30000000,atk:'pull',rng:0,arc:0,dm:3,kb:450,cd:.6,pc:['#4dc3ff','#ffffff'],d:'Человек в капюшоне с одним синим глазом: атакой притягивается к врагу и бьёт ударной волной'}];
const UL=['Молотобой: волна на весь экран, враги оглушены','Мегаотрыжка: гигантское зелёное облако вокруг','Тапкопад: 22 тапка падают на врагов','Землетрясение: три расходящиеся волны','Лавина ВК: 48 значков летят во все стороны','Адский заезд: три тарана подряд','Парирующая волна: огромное парирование — взрывает всех рядом и разворачивает снаряды'];
CH.forEach((c,i)=>{c.d+=' · УЛЬТА — '+UL[i]});
const UK=[{n:'Красная машина',p:8000000,d:'красно-чёрный боевой робот с голубыми глазами'},{n:'Золотой ангел',p:12000000,d:'золотой воин с крыльями и нимбом'},{n:'Алая бабка',p:16000000,d:'кибер-бабка с красными глазами'},{n:'Тяжёлая броня',p:22000000,d:'серая броня с огненным взглядом'},{n:'Кибер-основатель',p:40000000,d:'чёрный киборг с голубым визором'},{n:'Адский байкер',p:60000000,d:'огненный байк и пламя за спиной'},{n:'Джон Доу',p:80000000,d:'бледный безликий призрак с трещинами и белыми зрачками в чёрных глазницах'}];
const ukA=()=>uko[cs]&&ukon[cs];
const GD=[{n:'Бросок молота',sh:'БРОСОК',ch:0,p:150000,cd:6,d:'бросает молот: он летит вперёд, бьёт всех на пути и возвращается'}];
const cg=()=>GD.findIndex((g,i)=>g.ch===cs&&og[i]);
const BS=[
{n:'Синяя',p:0,h:'#4aa3df',B:'#4aa3df',W:'#2f6fa8',C:'#e5383b',c:'#9b1c1f',G:'#0b0b12',y:'#ffd23f'},
{n:'Золотая',p:30000,h:'#ffd23f',B:'#ffd23f',W:'#d9a400',C:'#2a2a2a',c:'#111111',G:'#0b0b12',y:'#fff1b0'},
{n:'Огненная',p:600000,h:'#ff7a1a',B:'#ff7a1a',W:'#d9480f',C:'#ffd23f',c:'#c99700',G:'#0b0b12',y:'#ffb703',dm:1,pk:'птенцы клюют сильнее (+1 урон)'},
{n:'Космо',p:9000000,h:'#8b5cf6',B:'#8b5cf6',W:'#5b21b6',C:'#0ea5e9',c:'#0369a1',G:'#001018',y:'#c4b5fd',v:3,pk:'3 птенца в залпе'},
{n:'Розовая',p:100000000,h:'#ff7ac8',B:'#ff7ac8',W:'#d63a98',C:'#ffffff',c:'#ffd6f7',G:'#0b0b12',y:'#ffd6f7',dm:1,v:3,pk:'3 птенца и +1 урон'},
{n:'Манго-птица',p:2000000000,h:'#ff9f1c',B:'#ff9f1c',W:'#ff5a36',w:'#ffe27a',C:'#ffd23f',c:'#e0a800',G:'#0b0b12',y:'#ffd23f',dm:3,v:5,mg:1,pk:'КОРОЛЕВА: корона, манго-аура, 5 птенцов и +3 урона'},
{n:'Чекушка',p:1000000,h:'#7fd6a8',B:'#7fd6a8',W:'#3f9d73',w:'#ffffff',C:'#cfd3da',c:'#8a8f9c',G:'#0b0b12',y:'#c9f5dd',dm:1,v:3,wb:1,pk:'птенцы шатаются, но клюют крепче'}];
const BX={1:{au:['#ffd23f','#fff1b0'],ag:'rgba(255,210,63,',bd:'chain'},2:{au:['#ff5a1f','#ffb703'],ag:'rgba(255,90,31,',bd:'flame'},3:{au:['#c4b5fd','#ffffff','#00e5ff'],ag:'rgba(139,92,246,',bd:'ant'},4:{au:['#ffd6f7','#ff7ac8'],ag:'rgba(255,122,200,',bd:'bow'},5:{au:['#ffd23f','#ff9f1c','#9ad64a'],ag:'rgba(255,159,28,'},6:{au:['#c9f5dd','#ffffff'],ag:'rgba(127,214,168,',bd:'drop'}};
for(const i in BX)Object.assign(BS[i],BX[i]);
BS.push({n:'Герой-Патриот',p:4000000000,h:'#2b4c9b',B:'#2b4c9b',W:'#1d2f66',w:'#f2c14e',C:'#f5d76e',c:'#c9a227',G:'#0b0b12',y:'#f5d76e',dm:3,v:5,ls:1,cape:1,au:['#ffffff','#e5383b','#2b4c9b'],ag:'rgba(229,56,59,',pk:'плащ со звёздами, мощные лазерные глаза, 5 птенцов и +3 урона'});
const MG=[{n:'Шторм птенцов',sh:'ШТОРМ',p:800000,cd:12,d:'14 птенцов разлетаются во все стороны и клюют всех'},{n:'Тёплое гнездо',sh:'ГНЕЗДО',p:2000000,cd:25,d:'лечит 30% здоровья и даёт 3 секунды неуязвимости'},{n:'Яичный залп',sh:'ЯЙЦА',p:6000000,cd:15,d:'яйца падают на 8 врагов и взрываются'}];
const HL=[{n:'Чекунцы',p:400000,d:'две бутылочки-бойца кружат рядом и таранят врагов'},{n:'ГДЗ',p:5000000,d:'книга с ответами: раз в 7 секунд «решает» самого сильного врага'}];
const GC=12,GR=18,TOP=70;
let LG=new Array(GC*GR).fill(0),lv=null,lvSrc=null,lvIdx=-1,cmp=0,mgOn=false,uko=[],ukon=[],fz=0,pf=0,lvMode=false,spBoost=1,edTool=1;
let coins=0,runCoins=0,L={dmg:0,reach:0,hp:0,spd:0,cd:0,sp:0},skin=0,owned=[1],used=[],msg='',cs=0,oc=[1],pr=[],ep=[],aimJoy=false,aim=null,hm=null,og=[],mb=null,bd=null,mr=0,mbn=0,ck=[],dq=[],gn=null,pw=0,bs=0,ob=[1],oh=[],ha=[],om=[],ms=-1,hl=[],gz=null;
try{const d=JSON.parse(localStorage.getItem('rkn_save')||'{}');coins=d.coins||0;Object.assign(L,d.L||{});skin=d.skin||0;owned=d.owned||owned;used=d.used||[];cs=d.cs||0;oc=d.oc||oc;aimJoy=!!d.aj;og=d.g||og;bs=d.bs||0;ob=d.ob||ob;oh=d.oh||[];ha=d.ha||[];om=d.om||[];ms=d.ms===undefined?-1:d.ms;if(d.lg&&d.lg.length===GC*GR)LG=d.lg;cmp=d.cp||0;uko=d.uk||[];ukon=d.un||[]}catch(e){}
function save(){try{localStorage.setItem('rkn_save',JSON.stringify({coins,L,skin,owned,used,cs,oc,aj:aimJoy,g:og,bs,ob,oh,ha,om,ms,lg:LG,cp:cmp,uk:uko,un:ukon}))}catch(e){}}
const aimOn=()=>aim&&aim.len>12,RM=()=>1+.08*L.reach,cost=(u,l)=>Math.round(u.base*Math.pow(1.75,l));
function fmt(n){const u=['','K','M','B','T','Qa'];let i=0;while(n>=1000&&i<5){n/=1000;i++}return i?n.toFixed(n<10?2:n<100?1:0)+u[i]:''+Math.floor(n)}
const TL=[{n:'Стена',c:'#6b7280',g:'#'},{n:'Лава',c:'#ff5a1f',g:'~'},{n:'Ускор.',c:'#16a34a',g:'»'},{n:'Засада',c:'#e5383b',g:'!'},{n:'Лечилка',c:'#22c55e',g:'+'},{n:'ТП вход',c:'#0ea5e9',g:'>'},{n:'ТП выход',c:'#8b5cf6',g:'<'},{n:'Монеты',c:'#eab308',g:'$'},{n:'Финиш',c:'#ffffff',g:'F'},{n:'Старт',c:'#2563eb',g:'S'},{n:'Враг',c:'#b91c1c',g:'E'},{n:'Босс',c:'#7c3aed',g:'B'},{n:'Мама-птица',c:'#4aa3df',g:'M'},{n:'Генератор',c:'#f59e0b',g:'G'},{n:'Щиток',c:'#64748b',g:'C'},{n:'Дверь',c:'#92400e',g:'D'}];
const TD=['Непроходимый блок. Герой, враги и снаряды упираются в него.','Жжёт героя (12 урона в секунду), пока он в лаве.','Пока герой стоит на плите, он бежит в 1,8 раза быстрее.','Срабатывает один раз: когда герой наступит, рядом появятся 5 врагов.','Срабатывает один раз: лечит героя на 40 здоровья.','Телепортирует героя на клетку «ТП выход». Нужна парная клетка «ТП выход».','Сюда телепортирует «ТП вход».','Срабатывает один раз: +1000 монет.','Герой дошёл сюда — уровень пройден, +2000 монет.','Здесь герой начинает уровень. Можно поставить только одну клетку.','Случайный враг стоит здесь с начала уровня (знак «?»).','Босс ГИГА-VPN стоит здесь с начала уровня.','Клетка с мамой-птицей. Постой рядом 2 секунды — спасёшь её и получишь награду и помощницу с птенцами. Можно поставить только одну клетку.','Мини-игра «Заведи генератор»: нужно 3 раза дёрнуть шнур в зелёной зоне. Награда +500 монет.','Мини-игра «Проложи кабель»: протяни кабель от вилки до розетки. Работает только после запуска генератора (если он есть на уровне).','Закрытая дверь. Открывается, когда выполнены все мини-игры уровня (генераторы и щитки). Без мини-игр открыта сразу.'];
function tileArt(g,t,X,Y,w,h,tm,dn){
const c=TL[t-1];if(!c)return;const m=Math.min(w,h),cx=X+w/2,cy=Y+h/2;
if(t===1){g.fillStyle='#4b5563';g.fillRect(X,Y,w,h);g.fillStyle='#9ca3af';g.fillRect(X,Y,w,Math.max(2,h*.2));g.strokeStyle='#0b0b12';g.lineWidth=Math.max(2,w*.08);g.strokeRect(X,Y,w,h);return}
if(t===2){g.fillStyle='#ff5a1f';g.fillRect(X,Y,w,h);g.fillStyle='#ffd23f';const o=Math.sin(tm/300+X)*w*.2;g.fillRect(X+w*.25+o,Y+h*.25,w*.2,h*.2);g.fillRect(X+w*.6,Y+h*.55+o,w*.2,h*.2);return}
if(t===16){g.fillStyle='#92400e';g.fillRect(X,Y,w,h);g.fillStyle='#b45309';g.fillRect(X,Y,w,Math.max(2,h*.2));g.strokeStyle='#0b0b12';g.lineWidth=Math.max(2,w*.08);g.strokeRect(X,Y,w,h);g.fillStyle='#fbbf24';g.beginPath();g.arc(X+w/2,Y+h*.42,m*.16,0,7);g.fill();g.fillRect(X+w/2-m*.05,Y+h*.45,m*.1,m*.25);return}
if(t>=10&&t<=13){
g.globalAlpha=.35;g.fillStyle=c.c;g.fillRect(X+1,Y+1,w-2,h-2);g.globalAlpha=1;
const sp=t===10?SPL[0][0]:t===11?SP.tg[0]:t===13?SBS[bs][0]:SP.mon[0],sz=m*.95;g.imageSmoothingEnabled=false;g.drawImage(sp,cx-sz/2,cy-sz/2,sz,sz);
if(t===11){g.fillStyle='#fff';g.font='bold '+Math.floor(m*.45)+'px "Courier New",monospace';g.textAlign='center';g.textBaseline='middle';g.fillText('?',X+w*.8,Y+h*.25);g.textBaseline='alphabetic'}
return;
}
g.globalAlpha=dn?.25:.6;g.fillStyle=c.c;g.fillRect(X+1,Y+1,w-2,h-2);g.globalAlpha=dn?.45:1;
g.fillStyle='#fff';g.strokeStyle='#fff';g.lineWidth=Math.max(2,m*.1);
if(t===3){[-.2,.1].forEach(o=>{g.beginPath();g.moveTo(cx+o*m-m*.1,cy-m*.28);g.lineTo(cx+o*m+m*.16,cy);g.lineTo(cx+o*m-m*.1,cy+m*.28);g.stroke()})}
else if(t===4){g.beginPath();g.moveTo(cx,cy-m*.36);g.lineTo(cx+m*.36,cy+m*.3);g.lineTo(cx-m*.36,cy+m*.3);g.closePath();g.fill();g.fillStyle=c.c;g.fillRect(cx-m*.05,cy-m*.14,m*.1,m*.24);g.fillRect(cx-m*.05,cy+m*.14,m*.1,m*.08)}
else if(t===5){g.fillRect(cx-m*.1,cy-m*.32,m*.2,m*.64);g.fillRect(cx-m*.32,cy-m*.1,m*.64,m*.2)}
else if(t===6||t===7){g.beginPath();g.arc(cx,cy,m*.34,0,7);g.stroke();const d=t===6?1:-1;g.beginPath();g.moveTo(cx-d*m*.12,cy-m*.15);g.lineTo(cx+d*m*.14,cy);g.lineTo(cx-d*m*.12,cy+m*.15);g.closePath();g.fill()}
else if(t===8){g.fillStyle='#fff3b0';g.beginPath();g.arc(cx,cy,m*.32,0,7);g.fill();g.fillStyle=c.c;g.font='bold '+Math.floor(m*.45)+'px "Courier New",monospace';g.textAlign='center';g.textBaseline='middle';g.fillText('$',cx,cy);g.textBaseline='alphabetic'}
else if(t===9){const q=m*.17,x0=cx-q*2,y0=cy-q*2;for(let a=0;a<4;a++)for(let b=0;b<4;b++){g.fillStyle=(a+b)%2?'#0b0b12':'#fff';g.fillRect(x0+a*q,y0+b*q,q,q)}}
else if(t===14){g.fillStyle='#fde68a';g.beginPath();g.moveTo(cx+m*.05,cy-m*.36);g.lineTo(cx-m*.22,cy+m*.04);g.lineTo(cx-m*.02,cy+m*.04);g.lineTo(cx-m*.08,cy+m*.36);g.lineTo(cx+m*.24,cy-m*.06);g.lineTo(cx+m*.04,cy-m*.06);g.closePath();g.fill()}
else if(t===15){g.strokeStyle='#fff';g.lineWidth=Math.max(2,m*.08);g.beginPath();g.moveTo(cx-m*.3,cy-m*.2);g.lineTo(cx,cy-m*.2);g.lineTo(cx,cy+m*.2);g.lineTo(cx+m*.3,cy+m*.2);g.stroke();g.fillStyle='#fff';g.fillRect(cx-m*.38,cy-m*.28,m*.14,m*.16);g.fillRect(cx+m*.24,cy+m*.12,m*.14,m*.16)}
if((t===14||t===15)&&dn){g.fillStyle='rgba(124,252,154,.9)';g.fillRect(X+w*.55,Y+h*.05,w*.4,h*.3);g.fillStyle='#0b0b12';g.font='bold '+Math.floor(m*.3)+'px "Courier New",monospace';g.textAlign='center';g.textBaseline='middle';g.fillText('OK',X+w*.75,Y+h*.2);g.textBaseline='alphabetic'}
g.globalAlpha=1;
}
function lvCell(X,Y){const i=Math.floor(X/(W/GC)),j=Math.floor((Y-TOP)/((H-TOP)/GR)),v=(i<0||j<0||i>=GC||j>=GR)?0:lv.g[j*GC+i];return v===16&&!lv.open?1:v}
function wallPush(o,r){
const cw=W/GC,ch=(H-TOP)/GR;
for(let it=0;it<2;it++){
const i0=Math.floor((o.x-r)/cw),i1=Math.floor((o.x+r)/cw),j0=Math.floor((o.y-TOP-r)/ch),j1=Math.floor((o.y-TOP+r)/ch);
for(let j=j0;j<=j1;j++)for(let i=i0;i<=i1;i++){
const vv=(i<0||j<0||i>=GC||j>=GR)?0:lv.g[j*GC+i];if(vv!==1&&!(vv===16&&!lv.open))continue;
const rx=i*cw,ry=TOP+j*ch,cx=Math.max(rx,Math.min(o.x,rx+cw)),cy=Math.max(ry,Math.min(o.y,ry+ch)),dx=o.x-cx,dy=o.y-cy,d=Math.hypot(dx,dy);
if(d<r){if(d>.01){o.x+=dx/d*(r-d);o.y+=dy/d*(r-d)}else o.y+=r}
}
}
}
function drawLevel(){
const cw=W/GC,ch=(H-TOP)/GR;
lv.g.forEach((t,k)=>{if(!t||(t>=10&&t<=13)||(t===16&&lv.open))return;const i=k%GC,j=Math.floor(k/GC),X=sn(i*cw),Y=sn(TOP+j*ch);tileArt(x,t,X,Y,sn((i+1)*cw)-X,sn(TOP+(j+1)*ch)-Y,last,lv.done[k])});
}
function levelInit(){
const cw=W/GC,ch=(H-TOP)/GR,pos=k=>[(k%GC+.5)*cw,TOP+(Math.floor(k/GC)+.5)*ch];
lv.g.forEach((t,k)=>{if(t===10){const a=pos(k);p.x=a[0];p.y=a[1]}});
lv.g.forEach((t,k)=>{if(t!==11&&t!==12)return;const a=pos(k);spawn(t===12?'mon':['tg','dc','yt','tt','rb'][Math.random()*5|0]);const e=en[en.length-1];e.x=a[0];e.y=a[1]});
lv.g.forEach((t,k)=>{if(t===13&&!mb){const a=pos(k);mb={x:a[0],y:a[1],pr:0};mbn=3.5}});
lv.open=!lv.g.some(t=>t===14||t===15);q=[];bt=lvIdx>=0?CMP[lvIdx].n:'УРОВЕНЬ';banner=2;lv.n0=en.length;
}
function lvTick(dt){
const cw=W/GC,ch=(H-TOP)/GR,i=Math.floor(p.x/cw),j=Math.floor((p.y-TOP)/ch);
if(i<0||j<0||i>=GC||j>=GR)return;
const k=j*GC+i,t=lv.g[k];spBoost=t===3?1.8:1;p.tc=(p.tc||0)-dt;p.mgc=(p.mgc||0)-dt;
if(t===2){p.hp-=12*dt;flash=Math.max(flash,.3);if(p.hp<=0){over();return}}
if(lv.done[k])return;
if(t===4){lv.done[k]=1;txt('ЗАСАДА!',p.x,p.y-50,'#ff6b6b');shake=Math.max(shake,12);
for(let n=0;n<5;n++){spawn(['tg','dc','yt','tt'][Math.random()*4|0]);const e=en[en.length-1],a=Math.random()*6.28;e.x=p.x+Math.cos(a)*170;e.y=p.y+Math.sin(a)*170}}
else if(t===5){lv.done[k]=1;p.hp=Math.min(p.mh,p.hp+40);txt('ЛЕЧИЛКА +40',p.x,p.y-50,'#7CFC9A');burst(p.x,p.y,'#7CFC9A',12)}
else if(t===8){lv.done[k]=1;coins+=1000;runCoins+=1000;save();txt('+1000 монет',p.x,p.y-50,'#ffd23f');burst(p.x,p.y,'#ffd23f',14)}
else if(t===6&&p.tc<=0){const d=lv.g.indexOf(7);if(d>=0){p.tc=1;p.x=(d%GC+.5)*cw;p.y=TOP+(Math.floor(d/GC)+.5)*ch;burst(p.x,p.y,'#a06bff',16);txt('ТЕЛЕПОРТ!',p.x,p.y-50,'#a06bff')}}
else if((t===14||t===15)&&p.mgc<=0){
if(t===15&&lv.g.some((tt,kk)=>tt===14&&!lv.done[kk])){txt('Сначала заведи все генераторы!',p.x,p.y-50,'#ffd166');p.mgc=1.5;return}
p.mgc=3;
startMini(t===14?'gen':'cable',ok=>{if(ok){lv.done[k]=1;if(t===14)lv.gen=true;coins+=500;runCoins+=500;save();txt('+500 монет',p.x,p.y-50,'#ffd23f');checkDoor()}else txt('Не вышло — попробуй снова',p.x,p.y-50,'#ff6b6b')},Math.max(0,lvIdx));
}
else if(t===9){lv.done[k]=1;coins+=2000;runCoins+=2000;save();over(true)}
}
function demo(){
LG.fill(0);const S2=(i,j,t)=>{LG[j*GC+i]=t};
for(let i=0;i<GC;i++)if(i!==5&&i!==6)S2(i,12,1);
for(let i=3;i<=8;i++)S2(i,9,2);
S2(6,16,10);S2(6,14,5);S2(5,11,4);S2(3,15,3);S2(8,15,3);
S2(2,7,11);S2(9,7,11);S2(5,5,11);S2(7,5,11);S2(1,5,8);S2(10,5,8);S2(1,13,6);S2(10,3,7);S2(6,1,9);S2(10,10,13);
}
function editor(){
ov.style.display='none';
if(!document.getElementById('edcss')){const st=document.createElement('style');st.id='edcss';st.textContent=`
#edw{position:fixed;inset:0;z-index:4;background:#0b0e16;display:flex;flex-direction:column;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px);font-family:"Courier New",Courier,monospace;font-weight:700;color:#fff;touch-action:none;user-select:none;-webkit-user-select:none}
#edtop{display:flex;gap:6px;padding:6px 8px;align-items:center}
.eb{min-width:46px;height:46px;border:3px solid #fff;background:#1f2937;color:#fff;font:inherit;font-size:22px;box-shadow:3px 3px 0 #000;border-radius:0;padding:0 8px}
.eb.ep{background:#16a34a;min-width:64px}
#edc{position:relative;flex:1;min-height:0}
#edv{position:absolute;inset:0;width:100%;height:100%;touch-action:none}
#edt{position:absolute;top:8px;left:50%;transform:translateX(-50%);background:#000c;border:2px solid #fff;padding:6px 10px;font-size:13px;opacity:0;transition:opacity .2s;pointer-events:none;max-width:90%;text-align:center;line-height:1.4}
#edmn{position:absolute;top:6px;right:6px;background:#111827;border:3px solid #fff;display:none;flex-direction:column;gap:6px;padding:8px;z-index:2}
#edb2{background:#111827;border-top:3px solid #fff;padding:6px 8px 8px}
#edd{font-size:12px;min-height:30px;line-height:1.3;margin-bottom:4px}
.tabs{display:flex;gap:6px;margin-bottom:6px}
.et{flex:1;height:36px;border:3px solid #fff;background:#374151;color:#fff;font:inherit;font-size:13px;border-radius:0}
.et.on{background:#e5383b}.et.ecat.on{background:#2563eb}
#edcar{display:flex;gap:6px;overflow-x:auto;touch-action:pan-x;padding-bottom:2px}
.ec{flex:0 0 64px;border:3px solid #444;background:#1f2937;text-align:center;font-size:10px;padding:3px 0;cursor:pointer}
.ec.on{border-color:#fff;background:#374151}
.ec canvas{display:block;margin:0 auto 2px;width:36px;height:36px;image-rendering:pixelated}
@media (max-height:520px){#edd{display:none}.ec{flex-basis:54px}}`;document.head.appendChild(st)}
const wr=document.createElement('div');wr.id='edw';
wr.innerHTML=`<div id="edtop"><button class="eb" id="e_bk">‹</button><button class="eb" id="e_un">↶</button><button class="eb" id="e_re">↷</button><div style="flex:1"></div><button class="eb" id="e_m">☰</button><button class="eb ep" id="e_pl">▶</button></div>
<div id="edc"><canvas id="edv"></canvas><div id="edt"></div><div id="edmn"></div></div>
<div id="edb2"><div id="edd"></div><div class="tabs" id="edtabs"><button class="et" data-m="b">СТРОИТЬ</button><button class="et" data-m="d">УДАЛЯТЬ</button><button class="et" data-m="h">РУКА</button></div><div class="tabs" id="edcat"></div><div id="edcar"></div></div>`;
document.body.appendChild(wr);
const E=id=>wr.querySelector('#'+id),cv2=E('edv'),g=cv2.getContext('2d');
let mode='b',cat=0,z=1,gx=0,gy=0,vw=1,vh=1,bw=1,rr=1,dpr=1,hist=[],redo=[],stroke=false,er=false,pin=null,tt=0;
const P=new Map(),CATS=[['БЛОКИ',[1,2,3]],['ТРИГГЕРЫ',[4,5,6,7,8,9]],['ОБЪЕКТЫ',[10,11,12,13]],['МИНИ-ИГРЫ',[14,15,16]]];
const size=()=>{const r=cv2.parentNode.getBoundingClientRect();vw=r.width;vh=r.height;dpr=Math.min(devicePixelRatio||1,2);cv2.width=Math.max(1,vw*dpr);cv2.height=Math.max(1,vh*dpr);rr=((H-TOP)/GR)/(W/GC);bw=Math.min(vw*.96/GC,vh*.96/(GR*rr))};
const fit=()=>{z=1;gx=(vw-GC*bw)/2;gy=(vh-GR*bw*rr)/2};
const cs=()=>[bw*z,bw*rr*z];
const toast=m=>{const t=E('edt');t.textContent=m;t.style.opacity=1;clearTimeout(tt);tt=setTimeout(()=>t.style.opacity=0,2400)};
const n=t=>LG.filter(v=>v===t).length;
const infoTxt=()=>{let h='Старт: '+(n(10)?'есть':'нет (центр)')+' · Финиш: '+(n(9)?'есть':'нет')+' · Врагов: '+n(11)+' · Боссов: '+n(12)+' · Мама: '+(n(13)?'есть':'нет');
if(n(6)&&!n(7))h+=' · ТП вход без выхода!';if(n(7)&&!n(6))h+=' · ТП выход без входа!';return h};
const draw=()=>{
g.setTransform(dpr,0,0,dpr,0,0);g.imageSmoothingEnabled=false;g.fillStyle='#0b0e16';g.fillRect(0,0,vw,vh);
const [cw,ch]=cs();g.fillStyle='#12172a';g.fillRect(gx,gy,GC*cw,GR*ch);
g.strokeStyle='rgba(255,255,255,.1)';g.lineWidth=1;g.beginPath();
for(let i=0;i<=GC;i++){g.moveTo(gx+i*cw,gy);g.lineTo(gx+i*cw,gy+GR*ch)}
for(let j=0;j<=GR;j++){g.moveTo(gx,gy+j*ch);g.lineTo(gx+GC*cw,gy+j*ch)}
g.stroke();
LG.forEach((t,k)=>{if(t)tileArt(g,t,gx+(k%GC)*cw,gy+Math.floor(k/GC)*ch,cw,ch,0,0)});
const ex=LG.indexOf(7);if(ex>=0){g.save();g.setLineDash([5,4]);g.strokeStyle='#4dc3ff';g.lineWidth=2;
LG.forEach((t,k)=>{if(t===6){g.beginPath();g.moveTo(gx+(k%GC+.5)*cw,gy+(Math.floor(k/GC)+.5)*ch);g.lineTo(gx+(ex%GC+.5)*cw,gy+(Math.floor(ex/GC)+.5)*ch);g.stroke()}});g.restore()}
g.strokeStyle='#fff';g.lineWidth=3;g.strokeRect(gx,gy,GC*cw,GR*ch);
};
const pos=e=>{const r=cv2.getBoundingClientRect();return{x:e.clientX-r.left,y:e.clientY-r.top}};
const cellAt=p=>{const [cw,ch]=cs(),i=Math.floor((p.x-gx)/cw),j=Math.floor((p.y-gy)/ch);return i<0||j<0||i>=GC||j>=GR?-1:j*GC+i};
const paintK=k=>{if(k<0)return;if(er||mode==='d')LG[k]=0;else{if(edTool===10||edTool===13)for(let a=0;a<LG.length;a++)if(LG[a]===edTool)LG[a]=0;LG[k]=edTool}};
const lineTo=(a,b)=>{const [cw,ch]=cs(),m=Math.max(1,Math.ceil(Math.hypot(b.x-a.x,b.y-a.y)/(Math.min(cw,ch)/2)));for(let s=1;s<=m;s++)paintK(cellAt({x:a.x+(b.x-a.x)*s/m,y:a.y+(b.y-a.y)*s/m}))};
const pinStart=()=>{const [a,b]=[...P.values()];pin={d:Math.hypot(a.x-b.x,a.y-b.y)||1,mx:(a.x+b.x)/2,my:(a.y+b.y)/2,z:z,gx:gx,gy:gy}};
const pinMove=()=>{const [a,b]=[...P.values()],d=Math.hypot(a.x-b.x,a.y-b.y)||1,mx=(a.x+b.x)/2,my=(a.y+b.y)/2;
const wx=(pin.mx-pin.gx)/(bw*pin.z),wy=(pin.my-pin.gy)/(bw*rr*pin.z);z=Math.max(.6,Math.min(4,pin.z*d/pin.d));gx=mx-wx*bw*z;gy=my-wy*bw*rr*z;draw()};
cv2.onpointerdown=e=>{cv2.setPointerCapture(e.pointerId);const p=pos(e);P.set(e.pointerId,p);E('edmn').style.display='none';
if(P.size>=2){if(stroke){stroke=false;if(hist.length)LG=hist.pop()}pinStart();draw();return}
if(mode==='h')return;
stroke=true;hist.push(LG.slice());if(hist.length>60)hist.shift();redo=[];
const k=cellAt(p);er=mode==='b'&&k>=0&&LG[k]===edTool;paintK(k);draw()};
cv2.onpointermove=e=>{if(!P.has(e.pointerId))return;const p=pos(e),o=P.get(e.pointerId);P.set(e.pointerId,p);
if(P.size>=2){if(!pin)pinStart();pinMove();return}
if(mode==='h'){gx+=p.x-o.x;gy+=p.y-o.y;draw();return}
if(stroke){lineTo(o,p);draw()}};
const up=e=>{P.delete(e.pointerId);if(P.size<2)pin=null;if(stroke&&P.size===0){stroke=false;save()}};
cv2.onpointerup=up;cv2.onpointercancel=up;
cv2.onwheel=e=>{e.preventDefault();const p=pos(e),wx=(p.x-gx)/(bw*z),wy=(p.y-gy)/(bw*rr*z);z=Math.max(.6,Math.min(4,z*(e.deltaY<0?1.15:.87)));gx=p.x-wx*bw*z;gy=p.y-wy*bw*rr*z;draw()};
const descr=()=>{E('edd').innerHTML=mode==='d'?'<b>Удаление</b> — води пальцем по клеткам, чтобы стереть их.':mode==='h'?'<b>Рука</b> — двигай поле одним пальцем. Два пальца в любом режиме: приближение и перемещение.':'<b>'+TL[edTool-1].n+'</b> — '+TD[edTool-1]+(' Тап по клетке с таким же блоком стирает её.')};
const setMode=m=>{mode=m;E('edtabs').querySelectorAll('button').forEach(b=>b.classList.toggle('on',b.dataset.m===m));descr()};
const build=()=>{
const car=E('edcar');car.innerHTML='';
E('edcat').innerHTML='';CATS.forEach((c,i)=>{const b=document.createElement('button');b.className='et ecat'+(i===cat?' on':'');b.textContent=c[0];b.onclick=()=>{cat=i;build()};E('edcat').appendChild(b)});
CATS[cat][1].forEach(id=>{const d=document.createElement('div');d.className='ec'+(edTool===id&&mode==='b'?' on':'');
const c=document.createElement('canvas');c.width=c.height=36;const cg=c.getContext('2d');cg.imageSmoothingEnabled=false;cg.fillStyle='#12172a';cg.fillRect(0,0,36,36);tileArt(cg,id,0,0,36,36,0,0);
d.appendChild(c);d.appendChild(document.createTextNode(TL[id-1].n));d.onclick=()=>{edTool=id;setMode('b');build()};car.appendChild(d)});
};
E('edtabs').querySelectorAll('button').forEach(b=>b.onclick=()=>{setMode(b.dataset.m);build()});
E('e_un').onclick=()=>{if(hist.length){redo.push(LG.slice());LG=hist.pop();save();draw()}};
E('e_re').onclick=()=>{if(redo.length){hist.push(LG.slice());LG=redo.pop();save();draw()}};
const act=(name,fn)=>{const b=document.createElement('button');b.className='et';b.style.flex='none';b.style.padding='0 12px';b.textContent=name;b.onclick=()=>{E('edmn').style.display='none';fn()};E('edmn').appendChild(b)};
const snap=()=>{hist.push(LG.slice());redo=[]};
act('РАМКА СТЕН',()=>{snap();for(let i=0;i<GC;i++)for(let j=0;j<GR;j++)if((i===0||j===0||i===GC-1||j===GR-1)&&!LG[j*GC+i])LG[j*GC+i]=1;save();draw()});
act('ПРИМЕР УРОВНЯ',()=>{snap();demo();save();draw()});
act('ОЧИСТИТЬ ВСЁ',()=>{snap();LG.fill(0);save();draw()});
act('СБРОС ВИДА',()=>{fit();draw()});
act('ИНФО',()=>toast(infoTxt()));
E('e_m').onclick=()=>{const m=E('edmn');m.style.display=m.style.display==='flex'?'none':'flex'};
const onr=()=>{size();draw()};addEventListener('resize',onr);
const close=()=>{removeEventListener('resize',onr);wr.remove()};
E('e_bk').onclick=()=>{close();lvMode=false;ov.style.display='flex';ov.innerHTML=menuHTML;bind()};
E('e_pl').onclick=()=>{if(!LG.some(t=>t===9||t===11||t===12)){toast('Добавь Финиш или хотя бы одного врага, чтобы начать тест');return}save();close();lvSrc=null;lvIdx=-1;lvMode=true;begin()};
size();fit();setMode('b');build();draw();toast('Два пальца — приближение и перемещение. Уровень сохраняется сам.');
}
const CH2={'.':0,'#':1,'~':2,'>':3,'!':4,'+':5,'T':6,'t':7,'$':8,'F':9,'S':10,'E':11,'B':12,'M':13,'G':14,'C':15,'D':16};
const mkL=rows=>{if(rows.length!==GR||rows.some(r=>r.length!==GC))throw new Error('bad level');return rows.join('').split('').map(c=>CH2[c]||0)};
const CMP=[
{n:'1. ПЕРВАЯ СМЕНА',d:'Заведи 2 генератора, открой дверь и дойди до финиша.',g:mkL(['############', '#....F.....#', '#..........#', '#####DD#####', '#..........#', '#.E......E.#', '#..........#', '#....##....#', '#....##....#', '#.......G..#', '#.E......E.#', '#..........#', '#..G.......#', '#..........#', '#.....+....#', '#..........#', '#....S.....#', '############'])},
{n:'2. ПРОЛОЖИ КАБЕЛЬ',d:'Два генератора и щиток с кабелем. Осторожно: враги!',g:mkL(['############', '#.....F....#', '#..........#', '#####DD#####', '#..E....E..#', '#........G.#', '#.#######..#', '#..........#', '#..#....#..#', '#.E......C.#', '#..........#', '#..>>..>>..#', '#..........#', '#.G........#', '#..........#', '#.....E....#', '#.....S....#', '############'])},
{n:'3. ЛАВОВЫЙ ЦЕХ',d:'Два генератора, щиток, лава и засада.',g:mkL(['############', '#.....F....#', '#..........#', '#####DD#####', '#~~~~..~~~~#', '#..........#', '#.C........#', '#..........#', '#~~~~..~~~~#', '#.E......E.#', '#....+.....#', '#........G.#', '#..........#', '#..G..!....#', '#..........#', '#.E......E.#', '#....S.....#', '############'])},
{n:'4. ПОДСТАНЦИЯ',d:'Два генератора, щиток, засады и мама-птица в клетке.',g:mkL(['############', '#....F.....#', '#.M........#', '####DDDD####', '#.........t#', '#.!......!.#', '#..........#', '#.#.#..#.#.#', '#..........#', '#.E..C..E..#', '#..........#', '#.#.#..#.#.#', '#T.........#', '#.......G..#', '#.G......E.#', '#..........#', '#....S.....#', '############'])},
{n:'5. ЭЛЕКТРОСТАНЦИЯ',d:'Финал: два генератора, щиток и босс ГИГА-VPN у двери.',g:mkL(['############', '#....F.....#', '#..........#', '#####DD#####', '#....B.....#', '#..........#', '#~~~~..~~~~#', '#.E......E.#', '#..........#', '#.C......G.#', '#..........#', '#..>>..>>..#', '#..........#', '#.M........#', '#....G.....#', '#.....+....#', '#....S.....#', '############'])}];
function objArrow(){
if(!lv&&!gn)return;let best=null,bd=1e9;
if(lv){const cw=W/GC,ch=(H-TOP)/GR;
lv.g.forEach((t,k)=>{if((t!==14&&t!==15)||lv.done[k])return;if(t===15&&lv.g.some((tt,kk)=>tt===14&&!lv.done[kk]))return;const X=(k%GC+.5)*cw,Y=TOP+(Math.floor(k/GC)+.5)*ch,d=Math.hypot(X-p.x,Y-p.y);if(d<bd){bd=d;best=[X,Y]}});
if(!best&&lv.open){const f=lv.g.indexOf(9);if(f>=0){best=[(f%GC+.5)*cw,TOP+(Math.floor(f/GC)+.5)*ch];bd=Math.hypot(best[0]-p.x,best[1]-p.y)}}}
else{best=[gn.x,gn.y];bd=Math.hypot(gn.x-p.x,gn.y-p.y)}
if(!best||bd<70)return;
const a=Math.atan2(best[1]-p.y,best[0]-p.x),pu=Math.sin(last/200)*4;
x.save();x.translate(sn(p.x+Math.cos(a)*(56+pu)),sn(p.y+Math.sin(a)*(56+pu)));x.rotate(a);x.fillStyle='#ffd23f';x.strokeStyle='#0b0b12';x.lineWidth=3;
x.beginPath();x.moveTo(12,0);x.lineTo(-9,-9);x.lineTo(-9,9);x.closePath();x.fill();x.stroke();x.restore();
}
function checkDoor(){let all=true,any=false;lv.g.forEach((t,k)=>{if(t===14||t===15){any=true;if(!lv.done[k])all=false}});if(any&&all&&!lv.open){lv.open=true;txt('ДВЕРЬ ОТКРЫТА!',p.x,p.y-80,'#7CFC9A');shake=Math.max(shake,10)}}
function campaign(){
let h='<h1>КАМПАНИЯ</h1><p><small>Проходи уровни по порядку. На уровнях ждут мини-игры: заведи генератор и проложи кабель, чтобы открыть дверь.</small></p>';
CMP.forEach((c,i)=>{const open=i<=cmp,dn=i<cmp;h+='<div class="it"><span>'+c.n+'<br><small>'+c.d+'</small></span><button class="go sm" data-l="'+i+'"'+(open?'':' disabled')+'>'+(dn?'ЕЩЁ РАЗ':open?'ИГРАТЬ':'ЗАКРЫТО')+'</button></div>'});
h+='<p>Тренировка мини-игр (+150 монет за победу)</p><div class="it"><span>Заведи генератор</span><button class="go sm" id="t1">ИГРАТЬ</button></div><div class="it"><span>Проложи кабель</span><button class="go sm" id="t2">ИГРАТЬ</button></div><button class="go" id="bk">Назад</button>';
ov.innerHTML=h;
ov.querySelectorAll('[data-l]').forEach(b=>b.onclick=()=>{lvIdx=+b.dataset.l;lvSrc=CMP[lvIdx].g;lvMode=true;begin()});
const tr=kind=>startMini(kind,ok=>{if(ok){coins+=150;save()}campaign()},cmp);
$('t1').onclick=()=>tr('gen');$('t2').onclick=()=>tr('cable');
$('bk').onclick=()=>{ov.innerHTML=menuHTML;bind()};
}
function startMini(kind,done,lvl){
mgOn=true;aim=joy=null;const ctl={alive:true};
const wr=document.createElement('div');
wr.style.cssText='position:fixed;inset:0;z-index:5;background:#0b0e16;display:flex;flex-direction:column;align-items:center;padding:calc(env(safe-area-inset-top,0px) + 10px) 12px calc(env(safe-area-inset-bottom,0px) + 10px);box-sizing:border-box;font-family:"Courier New",Courier,monospace;font-weight:700;color:#fff;touch-action:none;user-select:none;-webkit-user-select:none;overflow:hidden';
wr.innerHTML='<div id="mgt" style="font-size:22px;color:#ffd23f;margin-bottom:4px"></div><div id="mgh" style="font-size:13px;opacity:.85;text-align:center;margin-bottom:8px;max-width:360px;line-height:1.35"></div><canvas id="mgc" style="border:3px solid #fff;touch-action:none"></canvas><div id="mgm" style="margin:8px;min-height:20px;font-size:15px;text-align:center"></div><div style="display:flex;gap:8px"><button class="go sm" id="mgb" style="display:none">ДЁРНУТЬ!</button><button class="go sm" id="mgx">СДАТЬСЯ</button></div>';
document.body.appendChild(wr);
const fin=ok=>{if(!ctl.alive)return;ctl.alive=false;wr.remove();mgOn=false;last=performance.now();done(ok)};
wr.querySelector('#mgx').onclick=()=>fin(false);
(kind==='cable'?cableGame:genGame)(wr,fin,ctl,lvl||0);
}
function cableGame(wr,fin,ctl,lvl){
const T=wr.querySelector('#mgt'),Hh=wr.querySelector('#mgh'),M=wr.querySelector('#mgm'),cv=wr.querySelector('#mgc'),g=cv.getContext('2d');
T.textContent='ПРОЛОЖИ КАБЕЛЬ';Hh.textContent='Проведи пальцем от жёлтой вилки до зелёной розетки. Обходи сломанные блоки. Чтобы вернуться назад, веди по кабелю обратно.';
const cols=5+(lvl>=2?1:0),rows=7+(lvl>=2?1:0),cell=Math.max(28,Math.floor(Math.min((W-30)/cols,(H-280)/rows,64)));
cv.width=cell*cols;cv.height=cell*rows;
const nb=c=>{const a=c%cols,b=Math.floor(c/cols),r=[];if(a>0)r.push(c-1);if(a<cols-1)r.push(c+1);if(b>0)r.push(c-cols);if(b<rows-1)r.push(c+cols);return r};
let s0,s1,obs,path,tm=26-Math.min(lvl,4)*2,done=false,fail=false;
const solvable=()=>{const seen=new Set([s0]),qq=[s0];while(qq.length){const c=qq.shift();if(c===s1)return true;for(const n of nb(c))if(!seen.has(n)&&!obs.has(n)){seen.add(n);qq.push(n)}}return false};
for(let t=0;t<300;t++){obs=new Set();s0=Math.floor(Math.random()*cols);s1=(rows-1)*cols+Math.floor(Math.random()*cols);const n=Math.floor(cols*rows*(.25+.03*Math.min(lvl,4)));while(obs.size<n){const c=Math.floor(Math.random()*cols*rows);if(c!==s0&&c!==s1)obs.add(c)}if(solvable())break}
if(!solvable())obs=new Set();
path=[s0];
const ctr=c=>[(c%cols+.5)*cell,(Math.floor(c/cols)+.5)*cell];
const draw=()=>{
g.fillStyle='#10131a';g.fillRect(0,0,cv.width,cv.height);
for(let c=0;c<cols*rows;c++){const x0=(c%cols)*cell,y0=Math.floor(c/cols)*cell;g.fillStyle=((c%cols)+Math.floor(c/cols))%2?'#161b2b':'#12172a';g.fillRect(x0,y0,cell,cell);
if(obs.has(c)){g.fillStyle='#4b5563';g.fillRect(x0+3,y0+3,cell-6,cell-6);g.strokeStyle='#0b0b12';g.lineWidth=3;g.strokeRect(x0+3,y0+3,cell-6,cell-6);g.strokeStyle='#ef4444';g.lineWidth=4;g.beginPath();g.moveTo(x0+cell*.3,y0+cell*.3);g.lineTo(x0+cell*.7,y0+cell*.7);g.moveTo(x0+cell*.7,y0+cell*.3);g.lineTo(x0+cell*.3,y0+cell*.7);g.stroke()}}
const a=ctr(s0),b=ctr(s1);
g.fillStyle='#22c55e';g.fillRect(b[0]-cell*.34,b[1]-cell*.34,cell*.68,cell*.68);g.fillStyle='#0b0b12';g.fillRect(b[0]-cell*.18,b[1]-cell*.12,cell*.1,cell*.24);g.fillRect(b[0]+cell*.08,b[1]-cell*.12,cell*.1,cell*.24);
g.fillStyle='#fbbf24';g.fillRect(a[0]-cell*.34,a[1]-cell*.34,cell*.68,cell*.68);g.fillStyle='#0b0b12';g.fillRect(a[0]-cell*.18,a[1]-cell*.2,cell*.1,cell*.16);g.fillRect(a[0]+cell*.08,a[1]-cell*.2,cell*.1,cell*.16);g.fillRect(a[0]-cell*.12,a[1]-cell*.04,cell*.24,cell*.2);
if(path.length>1){g.lineCap='square';g.lineJoin='miter';g.beginPath();path.forEach((c,i)=>{const q2=ctr(c);i?g.lineTo(q2[0],q2[1]):g.moveTo(q2[0],q2[1])});g.strokeStyle='#0b0b12';g.lineWidth=cell*.42;g.stroke();g.strokeStyle=done?'#7CFC9A':'#f59e0b';g.lineWidth=cell*.26;g.stroke()}
const h2=ctr(path[path.length-1]);g.fillStyle='#fff';g.fillRect(h2[0]-cell*.15,h2[1]-cell*.15,cell*.3,cell*.3);
};
const cellAt=e=>{const r=cv.getBoundingClientRect(),x0=Math.floor((e.clientX-r.left-3)/cell),y0=Math.floor((e.clientY-r.top-3)/cell);return x0<0||y0<0||x0>=cols||y0>=rows?-1:y0*cols+x0};
const step=c=>{const L=path[path.length-1];if(c===L)return false;if(path.length>1&&c===path[path.length-2]){path.pop();return true}
if(obs.has(c)||path.includes(c)||nb(L).indexOf(c)<0)return false;path.push(c);
if(c===s1){done=true;M.textContent='ПОДКЛЮЧЕНО!';setTimeout(()=>fin(true),700)}return true};
const goTo=c=>{if(c<0||done||fail)return;for(let k=0;k<4;k++){const L=path[path.length-1];if(L===c)break;const lx=L%cols,ly=Math.floor(L/cols),tx=c%cols,ty=Math.floor(c/cols),nx=lx!==tx?lx+Math.sign(tx-lx):lx,ny=lx!==tx?ly:ly+Math.sign(ty-ly);if(!step(ny*cols+nx))break}};
let dn=false;cv.onpointerdown=e=>{cv.setPointerCapture(e.pointerId);dn=true;goTo(cellAt(e))};cv.onpointermove=e=>{if(dn)goTo(cellAt(e))};cv.onpointerup=cv.onpointercancel=()=>{dn=false};
let t0=performance.now();
const loop=()=>{if(!ctl.alive)return;const left=tm-(performance.now()-t0)/1000;
if(!done&&!fail){if(left<=0){fail=true;M.textContent='ВРЕМЯ ВЫШЛО!';setTimeout(()=>fin(false),800)}else M.textContent='Осталось: '+Math.ceil(left)+' с'}
draw();requestAnimationFrame(loop)};
requestAnimationFrame(loop);
}
function genGame(wr,fin,ctl,lvl){
const T=wr.querySelector('#mgt'),Hh=wr.querySelector('#mgh'),M=wr.querySelector('#mgm'),cv=wr.querySelector('#mgc'),g=cv.getContext('2d'),B=wr.querySelector('#mgb');
T.textContent='ЗАВЕДИ ГЕНЕРАТОР';Hh.textContent='Дёргай шнур, когда ползунок в зелёной зоне. Нужно 3 удачных рывка, ошибиться можно не больше 3 раз.';
cv.width=Math.min(W-30,340);cv.height=270;B.style.display='';M.textContent='Рывков: 0/3 · Попыток: 3';
let ok=0,tries=3,p=0,dir=1,spd=.8+lvl*.08,zw=.3,zx=.35,end=false,pull=0,sp=[],t0=performance.now(),lt=t0,runT=0;
const tap=()=>{if(end)return;const c=zx+zw/2;
if(Math.abs(p-c)<=zw/2){ok++;pull=1;spd*=1.22;zw=Math.max(.12,zw*.8);zx=.08+Math.random()*(.84-zw);for(let i=0;i<12;i++)sp.push({x:70,y:120,vx:(Math.random()-.5)*200,vy:-Math.random()*200,l:1});
if(ok>=3){end=true;M.textContent='ГЕНЕРАТОР ЗАВЁЛСЯ!';setTimeout(()=>fin(true),1100)}else M.textContent='Рывок удался! '+ok+'/3 · Попыток: '+tries}
else{tries--;pull=.5;if(tries<=0){end=true;M.textContent='Генератор заглох...';setTimeout(()=>fin(false),900)}else M.textContent='Мимо! Рывков: '+ok+'/3 · Попыток: '+tries}};
B.onpointerdown=e=>{e.preventDefault();tap()};cv.onpointerdown=e=>{e.preventDefault();tap()};
const loop=now=>{if(!ctl.alive)return;const dt=Math.min(.05,(now-lt)/1000||0);lt=now;
if(!end){p+=dir*spd*dt;if(p>1){p=1;dir=-1}if(p<0){p=0;dir=1}}else if(ok>=3)runT+=dt;
pull=Math.max(0,pull-dt*3);for(const s of sp){s.x+=s.vx*dt;s.y+=s.vy*dt;s.vy+=300*dt;s.l-=dt*1.4}sp=sp.filter(s=>s.l>0);
const w=cv.width;g.fillStyle='#10131a';g.fillRect(0,0,w,cv.height);
const sh=ok>=3?Math.sin(runT*60)*2:0;g.save();g.translate(sh,0);
g.fillStyle='#0b0b12';g.fillRect(24,64,124,98);g.fillStyle='#f59e0b';g.fillRect(28,68,116,90);g.fillStyle='#b45309';g.fillRect(28,130,116,28);
g.fillStyle='#0b0b12';g.fillRect(112,44,16,24);g.fillStyle='#6b7280';g.fillRect(115,47,10,18);
for(let i=0;i<3;i++){g.fillStyle='#0b0b12';g.fillRect(40+i*28,78,22,22);g.fillStyle=i<ok?'#7CFC9A':'#374151';g.fillRect(43+i*28,81,16,16)}
g.fillStyle='#0b0b12';g.fillRect(20,160,16,10);g.fillRect(136,160,16,10);
const hx=156+pull*34;g.strokeStyle='#d1d5db';g.lineWidth=4;g.beginPath();g.moveTo(148,112);g.lineTo(hx,112);g.stroke();g.fillStyle='#0b0b12';g.fillRect(hx,100,20,24);g.fillStyle='#ef4444';g.fillRect(hx+3,103,14,18);
if(ok>=3){g.fillStyle='rgba(180,180,180,.6)';for(let i=0;i<4;i++)g.fillRect(116+Math.sin(runT*8+i)*4,40-i*12-(runT*30%12),10,10)}
g.fillStyle='#ffd23f';for(const s of sp)g.fillRect(s.x,s.y,5,5);
g.restore();
const bx=20,by=205,bw=w-40,bh=30;g.fillStyle='#0b0b12';g.fillRect(bx-3,by-3,bw+6,bh+6);g.fillStyle='#374151';g.fillRect(bx,by,bw,bh);
g.fillStyle='#22c55e';g.fillRect(bx+zx*bw,by,zw*bw,bh);g.fillStyle='#fff';g.fillRect(bx+p*bw-4,by-8,8,bh+16);
requestAnimationFrame(loop)};
requestAnimationFrame(loop);
}
function settings(){
ov.innerHTML='<h1>НАСТРОЙКИ</h1><div class="it"><span>Джойстик прицела<br><small>Правый палец задаёт направление, атака идёт сама</small></span><button class="go sm" id="aj">'+(aimJoy?'ВКЛ':'ВЫКЛ')+'</button></div><p><small>Левый палец — движение. Если джойстик прицела выключен, цель выбирается автоматически.</small></p><button class="go" id="bk">Назад</button>';
$('aj').onclick=()=>{aimJoy=!aimJoy;save();settings()};
$('bk').onclick=()=>{ov.innerHTML=menuHTML;bind()};
}
function shop(){
let h='<h1>МАГАЗИН</h1><p>Монеты: <b>'+fmt(coins)+'</b></p><div class="it"><input id="pc" placeholder="Промокод"><button class="go sm" id="pb">ОК</button></div><p>'+msg+'</p>';
U.forEach((u,i)=>{const l=L[u.id],mx=l>=u.max,c=cost(u,l);
h+='<div class="it"><span>'+u.n+' '+l+'/'+u.max+'<br><small>'+u.d+'</small></span><button class="go sm" data-u="'+i+'"'+(mx||coins<c?' disabled':'')+'>'+(mx?'МАКС':fmt(c))+'</button></div>'});
h+='<p>Гаджеты</p>';GD.forEach((g,i)=>{h+='<div class="it"><span>'+g.n+'<br><small>'+CH[g.ch].n+': '+g.d+'</small></span><button class="go sm" data-g="'+i+'"'+(og[i]||coins<g.p?' disabled':'')+'>'+(og[i]?'КУПЛЕНО':fmt(g.p))+'</button></div>'});
h+='<p>Персонажи</p>';CH.forEach((c,i)=>{h+='<div class="it"><span>'+c.n+'<br><small>'+c.d+'</small></span><button class="go sm" data-c="'+i+'"'+(cs==i||(!oc[i]&&coins<c.p)?' disabled':'')+'>'+(cs==i?'ВЫБРАН':oc[i]?'ВЗЯТЬ':fmt(c.p))+'</button></div>'});
h+='<p>Скины <small>(молот Инспектора, бонусы у всех)</small></p>';
SK.forEach((k,i)=>{h+='<div class="it"><span style="color:'+(k.mango?'#ff9f1c':k.rb?'#ff5cf0':k.h)+'">'+k.n+(k.pk?'<br><small>'+k.pk+'</small>':'')+'</span><button class="go sm" data-s="'+i+'"'+(skin==i||(!owned[i]&&coins<SC[i])?' disabled':'')+'>'+(skin==i?'ВЫБРАН':owned[i]?'ВЗЯТЬ':fmt(SC[i]))+'</button></div>'});
h+='<p>Помощники</p>';HL.forEach((g,i)=>{h+='<div class="it"><span>'+g.n+'<br><small>'+g.d+'</small></span><button class="go sm" data-h="'+i+'"'+(!oh[i]&&coins<g.p?' disabled':'')+'>'+(oh[i]?(ha[i]?'ВКЛ':'ВЫКЛ'):fmt(g.p))+'</button></div>'});
h+='<p>Гаджеты мамы-птицы</p>';MG.forEach((g,i)=>{h+='<div class="it"><span>'+g.n+'<br><small>'+g.d+'</small></span><button class="go sm" data-m="'+i+'"'+(ms==i||(!om[i]&&coins<g.p)?' disabled':'')+'>'+(ms==i?'ВЫБРАН':om[i]?'ВЗЯТЬ':fmt(g.p))+'</button></div>'});
h+='<p>Облики персонажей <small>(с обликом парирование лечит полностью, окно шире)</small></p>';UK.forEach((u,i)=>{h+='<div class="it"><span>'+CH[i].n+': '+u.n+'<br><small>'+u.d+'</small></span><button class="go sm" data-u="'+i+'"'+(!uko[i]&&coins<u.p?' disabled':'')+'>'+(uko[i]?(ukon[i]?'ВКЛ':'ВЫКЛ'):fmt(u.p))+'</button></div>'});
h+='<p>Скины мамы-птицы</p>';BS.forEach((k,i)=>{h+='<div class="it"><span style="color:'+k.h+'">'+k.n+(k.pk?'<br><small>'+k.pk+'</small>':'')+'</span><button class="go sm" data-b="'+i+'"'+(bs==i||(!ob[i]&&coins<k.p)?' disabled':'')+'>'+(bs==i?'ВЫБРАН':ob[i]?'ВЗЯТЬ':fmt(k.p))+'</button></div>'});
h+='<button class="go" id="bk">Назад</button>';
ov.innerHTML=h;
$('bk').onclick=()=>{msg='';ov.innerHTML=menuHTML;bind()};
$('pb').onclick=()=>{const c=$('pc').value.trim().toLowerCase();
if(c==='кирилл'){if(used.includes(c))msg='Промокод уже использован';else{used.push(c);coins+=10000000000000000;msg='Активировано! +10 000 000 000 000 000 монет';save()}}else msg='Неверный промокод';shop()};
ov.querySelectorAll('[data-u]').forEach(b=>b.onclick=()=>{const u=U[b.dataset.u],c=cost(u,L[u.id]);if(coins>=c&&L[u.id]<u.max){coins-=c;L[u.id]++;msg='';save();shop()}});
ov.querySelectorAll('[data-u]').forEach(b=>b.onclick=()=>{const i=+b.dataset.u,u=UK[i];if(uko[i]){ukon[i]=!ukon[i]}else if(coins>=u.p){coins-=u.p;uko[i]=1;ukon[i]=true}else return;msg='';save();shop()});
ov.querySelectorAll('[data-h]').forEach(b=>b.onclick=()=>{const i=+b.dataset.h,g=HL[i];if(oh[i]){ha[i]=!ha[i]}else if(coins>=g.p){coins-=g.p;oh[i]=1;ha[i]=true}else return;msg='';save();shop()});
ov.querySelectorAll('[data-m]').forEach(b=>b.onclick=()=>{const i=+b.dataset.m,g=MG[i];if(om[i]){ms=i}else if(coins>=g.p){coins-=g.p;om[i]=1;ms=i}else return;msg='';save();shop()});
ov.querySelectorAll('[data-b]').forEach(b=>b.onclick=()=>{const i=+b.dataset.b,k=BS[i];if(ob[i]){bs=i}else if(coins>=k.p){coins-=k.p;ob[i]=1;bs=i}else return;msg='';save();shop()});
ov.querySelectorAll('[data-g]').forEach(b=>b.onclick=()=>{const i=+b.dataset.g,g=GD[i];if(!og[i]&&coins>=g.p){coins-=g.p;og[i]=1;msg='';save();shop()}});
ov.querySelectorAll('[data-c]').forEach(b=>b.onclick=()=>{const i=+b.dataset.c,c=CH[i];if(oc[i]){cs=i}else if(coins>=c.p){coins-=c.p;oc[i]=1;cs=i}else return;msg='';save();shop()});
ov.querySelectorAll('[data-s]').forEach(b=>b.onclick=()=>{const i=+b.dataset.s;if(owned[i]){skin=i}else if(coins>=SC[i]){coins-=SC[i];owned[i]=1;skin=i}else return;msg='';save();shop()});
}
let en=[],ps=[],tx=[],rg=[],p,score,combo,ct,wave,q,sq,run=false,shake=0,flash=0,banner=0,best=0,last=0,bt='';
try{best=+localStorage.getItem('rkn_best2')||0}catch(e){}
const keys={};let joy=null;
function nextWave(){
wave++;banner=2.2;q=[];const n=3+wave*2,pool=['tg','dc'];
if(wave>=2)pool.push('yt');if(wave>=3)pool.push('tt');if(wave>=4)pool.push('rb');
for(let i=0;i<n;i++)q.push(Math.random()<.1&&wave>=2?'vpn':pool[Math.random()*pool.length|0]);
if(wave%5==0)q.splice(q.length>>1,0,wave%10==0?'mon':'boss');
bt=wave%5==0?(wave%10==0?'БОСС: ГИГА-VPN':'БОСС: МЕГА-МЕССЕНДЖЕР'):'Волна '+wave;sq=1;spawnMama();spawnGen();
}
function reset(){p={x:W/2,y:H/2,gc:0,mc:0,pr:0,pc:0,ul:0,hp:100+20*L.hp,mh:100+20*L.hp,face:0,sw:-1,cd:0,inv:0,m:0,hit:0,vx:0,vy:0};en=[];ps=[];tx=[];rg=[];pr=[];ep=[];hm=null;mb=null;bd=null;mr=0;mbn=0;ck=[];dq=[];gn=null;pw=0;hl=oh[0]&&ha[0]?[{x:p.x,y:p.y,ph:0,cd:0},{x:p.x,y:p.y,ph:3.14,cd:0}]:[];gz=oh[1]&&ha[1]?{x:p.x,y:p.y,t:5,l:0,tx:0,ty:0}:null;score=0;runCoins=0;combo=0;ct=0;wave=0;nextWave();if(lv)levelInit()}
function spawn(k){
const s=Math.random()*4|0,t=ET[k];let X,Y;
if(s==0){X=-50;Y=Math.random()*H}else if(s==1){X=W+50;Y=Math.random()*H}else if(s==2){X=Math.random()*W;Y=-50}else{X=Math.random()*W;Y=H+50}
const hp=Math.ceil(t.hp*(1+wave*.06));
en.push({k,t,x:X,y:Y,hp,mx:hp,kx:0,ky:0,st:0,fl:0,ph:Math.random()*6,dt:2+Math.random()*2,dash:0,life:0});
}
function burst(X,Y,c,n){for(let i=0;i<n;i++){const a=Math.random()*6.28,v=120+Math.random()*320;ps.push({x:X,y:Y,vx:Math.cos(a)*v,vy:Math.sin(a)*v,c,z:S*(1+(Math.random()*2|0)),l:1})}}
function txt(s,X,Y,c){tx.push({s,x:X,y:Y,c,l:1})}
function near(){let b=null,bd=1e9;for(const e of en){if(e.t.flee)continue;const d=Math.hypot(e.x-p.x,e.y-p.y);if(d<bd){bd=d;b=e}}return b||en[0]}
function hurt(dmg,ux,uy){p.hp-=dmg;p.inv=.7;p.vx=ux*420;p.vy=uy*420;shake=Math.max(shake,10);flash=1;if(p.hp<=0)over()}
function kill(e){
if(e.t.zom&&!e.rv){e.rv=1;e.down=2.4;e.hp=Math.ceil(e.mx/2);burst(e.x,e.y,e.t.c,10);txt('ЗОМБИ ВОССТАНЕТ...',e.x,e.y-30,'#9be564');return}
e.dead=1;p.ul=Math.min(100,p.ul+3);if(SK[skin].hs){p.hp=Math.min(p.mh,p.hp+SK[skin].hs);txt('+'+SK[skin].hs,e.x,e.y-20,'#7CFC9A')}burst(e.x,e.y,e.t.c,e.t.boss?40:14);combo++;ct=3;
const m=Math.min(5,1+(combo/3|0)),pts=e.t.pts*m;score+=pts;const cg=Math.round(pts*(SK[skin].cm||1));coins+=cg;runCoins+=cg;save();p.m=Math.min(100,p.m+8*(1+.15*L.sp));
txt('ЗАБЛОКИРОВАН +'+pts,e.x,e.y,'#ffd166');
if(e.t.flee){p.hp=Math.min(p.mh,p.hp+20);txt('+20 HP',e.x,e.y-22,'#7CFC9A')}
if(e.t.boss)shake=26;
}
function dmg(e,d,ux,uy,kb){
if(pw>0)d*=1.5;
p.ul=Math.min(100,p.ul+.5);
{const K=SK[skin];if(K.crit&&Math.random()<K.crit){d*=2;txt('КРИТ!',e.x,e.y-e.t.r-14,'#ff2d2d');shake=Math.max(shake,9)}}
e.hp-=d;e.fl=1;e.st=e.t.boss?.08:.35;e.kx+=ux*kb;e.ky+=uy*kb;
p.m=Math.min(100,p.m+10*(1+.15*L.sp));burst(e.x,e.y,e.t.c,6);{const K=SK[skin];if(K.pc)for(let i=0;i<8;i++)burst(e.x,e.y,K.pc[i%K.pc.length],1)}shake=Math.max(shake,e.t.boss?9:6);
if(e.hp<=0)kill(e);else if(Math.random()<.4)txt('БАМ!',e.x,e.y-e.t.r,'#fff');
}
function strike(){
const C=CH[cs],R=RM(),K=SK[skin],col=K.pc||C.pc;
if(C.atk==='ram'){startDash(900,.45,0,0);return}
if(C.atk==='pull'){startPull();return}
if(C.atk==='vk'){pr.push({x:p.x,y:p.y,vx:Math.cos(p.face)*750,vy:Math.sin(p.face)*750,l:1.5,vk:1,p:1,dm:C.dm});for(let i=0;i<4;i++)burst(p.x+Math.cos(p.face)*40,p.y+Math.sin(p.face)*40,'#0077ff',1);return}
if(C.atk==='throw'){for(const o of[-.14,.14]){const a=p.face+o;pr.push({x:p.x,y:p.y,vx:Math.cos(a)*650,vy:Math.sin(a)*650,l:1.3})}return}
if(C.atk==='burp'){shake=Math.max(shake,12);txt('БУУУРП!',p.x+Math.cos(p.face)*90,p.y+Math.sin(p.face)*90,'#9be564');
for(let i=0;i<26;i++){const a=p.face+(Math.random()-.5)*1.1,v=250+Math.random()*450;ps.push({x:p.x+Math.cos(p.face)*30,y:p.y+Math.sin(p.face)*30,vx:Math.cos(a)*v,vy:Math.sin(a)*v,c:col[i%col.length],z:S*(2+(Math.random()*3|0)),l:1.2})}}
if(C.atk==='stomp'){rg.push({x:p.x,y:p.y,r:20,l:.6});shake=Math.max(shake,10)}
for(const b of ep){const dx=b.x-p.x,dy=b.y-p.y,d=Math.hypot(dx,dy);if(d>C.rng*R+14)continue;if(C.arc<3){let da=Math.atan2(dy,dx)-p.face;da=Math.atan2(Math.sin(da),Math.cos(da));if(Math.abs(da)>C.arc)continue}b.l=0;burst(b.x,b.y,'#ffd23f',8);txt('ПАРИРОВАЛ!',b.x,b.y,'#fff')}
for(const e of en){
const dx=e.x-p.x,dy=e.y-p.y,d=Math.hypot(dx,dy)||1;
if(e.down>0||d>C.rng*R+e.t.r)continue;
let da=Math.atan2(dy,dx)-p.face;da=Math.atan2(Math.sin(da),Math.cos(da));
if(Math.abs(da)>C.arc)continue;
dmg(e,C.dm+L.dmg+(K.db||0),dx/d,dy/d,e.t.boss?C.kb*.32:C.kb);
}
en=en.filter(e=>!e.dead);
}
function spawnGen(){
gn=null;if(lv||wave<3||wave%3!==0||wave%5===0)return;
let X,Y,i=0;do{X=80+Math.random()*(W-160);Y=140+Math.random()*(H-240);i++}while((Math.hypot(X-p.x,Y-p.y)<200||(mb&&Math.hypot(X-mb.x,Y-mb.y)<120))&&i<30);
gn={x:X,y:Y,cd:0};txt('ГЕНЕРАТОР! Заведи его — получишь энергию',W/2,H*.5,'#ffd23f');
}
function spawnMama(){
if(mb||bd||wave<2)return;
let X,Y,i=0;do{X=80+Math.random()*(W-160);Y=140+Math.random()*(H-240);i++}while(Math.hypot(X-p.x,Y-p.y)<200&&i<20);
mb={x:X,y:Y,pr:0};mbn=3.5;
}
function bAura(X,Y){
const K=BS[bs];
if(K.cape){
const t=last/200;
for(let i=0;i<10;i++){const cxp=sn(X-30+i*6),hh=36+Math.round(Math.sin(t+i*.7)*2)*3;x.fillStyle='#0b0b12';x.fillRect(cxp,sn(Y-9),6,hh+6);x.fillStyle=i%2?'#c0392b':'#a82a1f';x.fillRect(cxp,sn(Y-6),6,hh)}
x.fillStyle='#fff';[[-18,0],[0,12],[18,3],[-9,18],[9,24]].forEach(a=>x.fillRect(sn(X+a[0]),sn(Y+a[1]),3,3));
x.fillStyle='#ffd23f';x.fillRect(sn(X-27),sn(Y-9),6,6);x.fillRect(sn(X+21),sn(Y-9),6,6);
}
if(!K.au)return;
x.fillStyle=K.ag+(.2+.08*Math.sin(last/150))+')';x.fillRect(sn(X-33),sn(Y+12),66,15);x.fillRect(sn(X-24),sn(Y+6),48,27);
if(Math.random()<.25)burst(X+(Math.random()-.5)*40,Y+10,K.au[Math.random()*K.au.length|0],1);
}
function bDeco(K,X,Y){
x.strokeStyle='#0b0b12';x.lineWidth=3;const ro=(a,b,w,h)=>{x.fillRect(X+a,Y+b,w,h);x.strokeRect(X+a,Y+b,w,h)};
if(K.ls){const on=bd&&bd.ls>0;x.save();x.shadowColor='#ff2d2d';x.shadowBlur=on?12:6;x.fillStyle=on?'#fff':'#ff2d2d';x.fillRect(X-12,Y-12,3,3);x.fillRect(X+6,Y-12,3,3);x.restore();x.strokeStyle='#0b0b12';x.lineWidth=3}
switch(K.bd){
case'chain':x.fillStyle='#ffd23f';ro(-12,9,24,3);ro(-3,12,6,6);break;
case'flame':x.fillStyle='#ff5a1f';ro(-9,-39,6,9);ro(0,-45,6,15);ro(9,-39,6,9);x.fillStyle='#ffd23f';x.fillRect(X+1,Y-41,4,8);break;
case'ant':x.fillStyle='#c4b5fd';ro(-2,-42,4,12);x.fillStyle='#00e5ff';ro(-5,-48,10,6);break;
case'bow':x.fillStyle='#ff5cae';ro(9,-36,9,9);ro(21,-36,9,9);x.fillStyle='#fff';x.fillRect(X+18,Y-33,3,3);break;
case'drop':x.fillStyle='#c9f5dd';x.fillRect(X-30,Y-6+Math.round(Math.sin(last/200))*3,6,6);x.fillRect(X+27,Y+6+Math.round(Math.sin(last/230))*3,6,6);break;
}
}
function skinDeco(K,px,py){
x.strokeStyle='#0b0b12';x.lineWidth=3;const ro=(a,b,w,h)=>{x.fillRect(px+a,py+b,w,h);x.strokeRect(px+a,py+b,w,h)};
switch(K.hat){
case'crown':x.fillStyle='#ffd23f';ro(-12,-30,24,6);ro(-12,-39,6,9);ro(-3,-42,6,12);ro(6,-39,6,9);x.fillStyle='#ff2d2d';x.fillRect(px-2,py-39,3,3);break;
case'visor':x.fillStyle='rgba(57,255,20,.9)';ro(-18,-12,36,9);x.fillStyle='#fff';x.fillRect(px-12,py-9,6,3);break;
case'bow':x.fillStyle='#ff5cf0';ro(3,-36,9,9);ro(15,-36,9,9);x.fillStyle='#fff';x.fillRect(px+12,py-33,3,3);break;
case'horns':x.fillStyle='#ff5a1f';ro(-21,-39,6,15);ro(15,-39,6,15);break;
case'icec':x.fillStyle='#e6faff';ro(-12,-36,6,9);ro(-3,-42,6,15);ro(6,-36,6,9);break;
case'eyes':x.fillStyle='#a06bff';x.fillRect(px-12,py-9,3,3);x.fillRect(px+9,py-9,3,3);break;
case'halo':x.strokeStyle='hsl('+(last/4%360|0)+',90%,60%)';x.lineWidth=6;x.beginPath();x.ellipse(px,py-33,15,6,0,0,7);x.stroke();break;
case'glitch':if(Math.random()<.6){x.fillStyle=Math.random()<.5?'rgba(0,229,255,.4)':'rgba(255,45,111,.4)';x.fillRect(px-24+(Math.random()*6|0)*3,py-24+(Math.random()*16|0)*3,Math.round(12+Math.random()*30),3)}break;
case'butch':x.fillStyle='#c0392b';[[-9,9],[6,15],[-3,18],[9,6]].forEach(a=>x.fillRect(px+a[0],py+a[1],3,3));x.fillRect(px-12,py-3,3,6);break;
case'streamer':x.fillStyle='#e5383b';ro(-15,-33,30,9);ro(-24,-27,12,5);x.fillStyle='#ffd23f';ro(-24,-12,6,12);ro(18,-12,6,12);ro(-24,0,18,3);ro(-12,0,6,6);ro(-12,9,24,3);ro(-3,12,6,6);break;
}
}
function mgad(){
if(!run||!bd||ms<0||p.mc>0)return;
const g=MG[ms];p.mc=g.cd;
if(ms===0){for(let i=0;i<14;i++){const a=i/14*6.283;ck.push({x:bd.x,y:bd.y,vx:Math.cos(a)*420,vy:Math.sin(a)*420,l:6,cd:0,ph:Math.random()*6})}txt('ШТОРМ ПТЕНЦОВ!',bd.x,bd.y-50,'#ffd23f');shake=Math.max(shake,8)}
else if(ms===1){p.hp=Math.min(p.mh,p.hp+p.mh*.3);p.inv=3;rg.push({x:p.x,y:p.y,r:10,l:.6});burst(p.x,p.y,'#7CFC9A',16);txt('ТЁПЛОЕ ГНЕЗДО!',p.x,p.y-60,'#7CFC9A')}
else{const t=en.filter(e=>!e.dead&&!(e.down>0)&&!e.t.flee).sort(()=>Math.random()-.5).slice(0,8);for(const e of t)boom({x:e.x,y:e.y});txt('ЯИЧНЫЙ ЗАЛП!',bd.x,bd.y-50,'#fff3d6')}
}
function blast(X,Y,r,d,kb,col){
rg.push({x:X,y:Y,r:10,l:.5});shake=Math.max(shake,10);for(let i=0;i<14;i++)burst(X,Y,col,1);
for(const e of en){if(e.dead||e.down>0)continue;const dx=e.x-X,dy=e.y-Y,dd=Math.hypot(dx,dy)||1;if(dd<r+e.t.r)dmg(e,d+L.dmg,dx/dd,dy/dd,e.t.boss?kb*.3:kb)}
en=en.filter(e=>!e.dead);
}
function startPull(){
const t=near();
if(!t||Math.hypot(t.x-p.x,t.y-p.y)>650){startDash(700,.15,0,0);return}
p.face=Math.atan2(t.y-p.y,t.x-p.x);p.dash={t:.6,vx:0,vy:0,spd:1500,tg:t,hs:[],n:0,u:0};
}
function o1Glow(px,py){x.save();x.shadowColor='#4dc3ff';x.shadowBlur=8;x.fillStyle='rgba(120,215,255,.75)';x.fillRect(px-6,py-6,6,6);x.restore()}
function startDash(spd,dur,n,u){
const t=near(),a=t?Math.atan2(t.y-p.y,t.x-p.x):p.face;p.face=a;p.dash={t:dur,vx:Math.cos(a)*spd,vy:Math.sin(a)*spd,hs:[],n:n,u:u};
}
function parryHit(X,Y){
fz=p.up>0?.1:.28;pf=1;shake=Math.max(shake,20);p.pr=0;p.pc=.1;p.inv=Math.max(p.inv,.7);
p.hp=Math.min(p.mh,p.hp+p.mh*(ukA()?1:.5));p.ul=Math.min(100,p.ul+15);p.m=Math.min(100,p.m+25);score+=50;
burst(p.x,p.y,'#7fe7ff',24);burst(X,Y,'#fff',10);txt('ПАРИ!',p.x,p.y-65,'#7fe7ff');
}
function parryKill(e){
if(e.dead)return;
if(e.t.boss){if(e.pk&&last-e.pk<700)return;e.pk=last}
txt('ПАРИРОВАНИЕ! ВЗРЫВ!',e.x,e.y-e.t.r-10,'#7fe7ff');
if(e.t.boss){dmg(e,Math.max(10,Math.ceil(e.mx*.3)),0,0,0)}else{e.rv=1;dmg(e,99999,0,0,0)}
boom({x:e.x,y:e.y});shake=Math.max(shake,14);
}
function parry(){
if(!run||mgOn||p.pc>0||p.pr>0)return;
p.pr=ukA()?.2:.14;p.pc=.7;
}
function ult(){
if(!run||mgOn||p.ul<100)return;p.ul=0;
const db=SK[skin].db||0;shake=Math.max(shake,16);flash=Math.max(flash,.15);
txt(['МОЛОТОБОЙ!','МЕГАОТРЫЖКА!','ТАПКОПАД!','ЗЕМЛЕТРЯСЕНИЕ!','ЛАВИНА ВК!','АДСКИЙ ЗАЕЗД!','ПАРИРУЮЩАЯ ВОЛНА!'][cs],p.x,p.y-75,'#d8b4fe');
if(cs===0){blast(p.x,p.y,430,8+db,900,'#fff');for(const e of en)if(!e.dead)e.st=Math.max(e.st,1.5)}
else if(cs===1){blast(p.x,p.y,380,9+db,1000,'#9be564');for(let i=0;i<40;i++){const a=Math.random()*6.28,v=250+Math.random()*500;ps.push({x:p.x,y:p.y,vx:Math.cos(a)*v,vy:Math.sin(a)*v,c:['#9be564','#c8f169','#5aa02c'][i%3],z:S*(2+(Math.random()*3|0)),l:1.4})}}
else if(cs===2){for(let i=0;i<22;i++){const tg=en.length?en[Math.random()*en.length|0]:null,X=tg?tg.x+(Math.random()-.5)*60:Math.random()*W,Y=tg?tg.y+(Math.random()-.5)*60:TOP+Math.random()*(H-TOP);dq.push({t:i*.09,x:X,y:Y,r:70,d:4+db,kb:350,c:'#ffb703'})}}
else if(cs===3){[0,.35,.7].forEach((t,i)=>dq.push({t:t,x:p.x,y:p.y,r:170+i*110,d:6+db,kb:700,c:'#c9a26b'}))}
else if(cs===4){for(let k=0;k<2;k++)for(let i=0;i<24;i++){const a=i/24*6.283+k*.13;dq.push({t:k*.4,pr:{x:p.x,y:p.y,vx:Math.cos(a)*620,vy:Math.sin(a)*620,l:1.6,vk:1,p:2,dm:3+db}})}}
else if(cs===5){startDash(1100,.4,3,1)}
else if(cs===6){p.up=1.2;parryHit(p.x,p.y);for(const e of en)if(!e.dead&&Math.hypot(e.x-p.x,e.y-p.y)<300)parryKill(e);blast(p.x,p.y,300,6+db,900,'#4dc3ff')}
}
function uWings(px,py){
if(cs!==1)return;
x.strokeStyle='#0b0b12';x.lineWidth=3;
[-1,1].forEach(d=>{x.fillStyle='#fff7d6';[[-42,-18,18,6],[-36,-9,12,6],[-30,-27,12,6],[-45,-9,9,6]].forEach(a=>{const X=d<0?px+a[0]:px-a[0]-a[2];x.fillRect(X,py+a[1],a[2],a[3]);x.strokeRect(X,py+a[1],a[2],a[3])})});
}
function uDeco(px,py){
const cols=['#00e5ff','#4dc3ff','#ff2d2d','#ff7a1a','#00e5ff'],ey=cs===0?-9:-12,ex=cs===2?[-9,6]:[-12,9];
if(cs===6){x.save();x.shadowColor='#fff';x.shadowBlur=6;x.fillStyle='#fff';x.fillRect(px-9,py-6,3,3);x.fillRect(px+9,py-6,3,3);x.restore();return}
if(cs<5){x.save();x.shadowColor=cols[cs];x.shadowBlur=6;x.fillStyle=cols[cs];x.fillRect(px+ex[0],py+ey,3,3);x.fillRect(px+ex[1],py+ey,3,3);x.restore()}
if(cs===1){x.strokeStyle='#ffd23f';x.lineWidth=6;x.beginPath();x.ellipse(px,py-33,15,6,0,0,7);x.stroke()}
if(cs===5&&Math.random()<.4)burst(px+(Math.random()-.5)*20,py+18,'#ff7a1a',1);
}
function gad(){
if(!run||hm||p.gc>0||cg()<0)return;
const n=near();let a=p.face;if(aimOn())a=aim.a;else if(n)a=Math.atan2(n.y-p.y,n.x-p.x);
p.face=a;hm={x:p.x,y:p.y,vx:Math.cos(a)*800,vy:Math.sin(a)*800,d:0,max:380*RM(),ph:'out',hs:[],rot:0};shake=Math.max(shake,5);
}
function drawHam(K,ox){
x.strokeStyle='#0b0b12';x.lineWidth=3;
if(K.cb){
x.shadowColor='#ff2d2d';x.shadowBlur=5;x.fillStyle='#9ca3af';x.fillRect(10+ox,-5,118,10);x.shadowBlur=0;
x.fillStyle='#d1d5db';x.fillRect(10+ox,-5,118,3);
x.fillStyle='#7f1d1d';for(let i=0;i<5;i++)x.fillRect(18+ox+i*7,-5,4,10);
x.fillStyle='#9ca3af';x.fillRect(4+ox,-7,8,14);x.fillRect(122+ox,-5,12,29);x.fillRect(108+ox,18,26,6);
x.fillStyle='#0b0b12';x.fillRect(115+ox,18,6,3);
x.strokeRect(10+ox,-5,118,10);x.strokeRect(4+ox,-7,8,14);x.strokeRect(122+ox,-5,12,29);x.strokeRect(108+ox,18,26,6);
x.fillStyle='#c0392b';x.fillRect(126+ox,16,3,9);x.fillRect(112+ox,21,3,3);x.fillRect(118+ox,-3,3,3);
return;
}
if(K.mc){
x.fillStyle='#4b3621';x.fillRect(10+ox,-6,34,12);x.strokeRect(10+ox,-6,34,12);x.fillStyle='#7f1d1d';for(let i=0;i<3;i++)x.fillRect(16+ox+i*8,-6,3,12);
x.fillStyle='#0b0b12';x.fillRect(44+ox,-12,5,24);
x.shadowColor='#ff2d2d';x.shadowBlur=5;x.fillStyle='#cbd5e1';x.fillRect(49+ox,-9,84,18);x.shadowBlur=0;x.strokeRect(49+ox,-9,84,18);
x.fillStyle='#e2e8f0';x.fillRect(49+ox,-9,84,5);x.fillStyle='#b91c1c';x.fillRect(70+ox,-3,5,12);x.fillRect(104+ox,-9,4,10);x.fillRect(126+ox,0,6,9);
return;
}
x.fillStyle=K.s;x.fillRect(10+ox,-6,90,12);x.strokeRect(10+ox,-6,90,12);
if(K.mango){['#ff5a36','#ff9f1c','#ffd23f','#9ad64a'].forEach((c,i)=>{x.fillStyle=c;x.fillRect(90+ox+i*12,-30,i==3?9:12,60)});x.fillStyle='#2f9e44';x.fillRect(100+ox,-42,15,12);x.fillStyle='rgba(255,255,255,.6)';x.fillRect(96+ox,-22,6,15)}
else{
x.shadowColor=K.gl||'transparent';x.shadowBlur=K.gl?6:0;
x.fillStyle=K.rb?'hsl('+(last/4%360|0)+',90%,60%)':K.h;x.fillRect(90+ox,-30,45,60);x.shadowBlur=0;
x.fillStyle='rgba(0,0,0,.25)';x.fillRect(90+ox,-9,45,18);
if(K.dc==='gem'){x.fillStyle='#ff2d2d';x.fillRect(106+ox,-6,12,12);x.fillStyle='#fff';x.fillRect(108+ox,-4,3,3)}
if(K.dc==='str'){x.fillStyle='#0b0b12';x.fillRect(96+ox,-30,4,60);x.fillRect(125+ox,-30,4,60);x.fillStyle='#fff';x.fillRect(110+ox,-30,6,60)}
if(K.dc==='heart'){x.fillStyle='#fff';x.fillRect(101+ox,-12,9,9);x.fillRect(113+ox,-12,9,9);x.fillRect(101+ox,-6,21,9);x.fillRect(104+ox,3,15,6);x.fillRect(110+ox,9,3,3)}
if(K.dc==='crk'){x.fillStyle='#ffd23f';x.fillRect(100+ox,-30,4,18);x.fillRect(104+ox,-12,4,8);x.fillRect(112+ox,6,4,24);x.fillRect(116+ox,-3,4,9)}
if(K.dc==='spk'){x.fillStyle='#e6faff';[96,108,120].forEach(X=>{x.fillRect(X+ox,-42,8,12);x.fillRect(X+ox,30,8,12)})}
if(K.dc==='eye'){x.fillStyle='#a06bff';x.fillRect(104+ox,-9,18,18);x.fillStyle='#fff';x.fillRect(110+ox,-3,6,6);x.fillStyle='#0b0b12';x.fillRect(112+ox,-1,3,3)}
if(K.dc==='cross'){x.fillStyle='#e5383b';x.fillRect(106+ox,-15,12,30);x.fillRect(97+ox,-6,30,12)}
if(K.dc==='live'){x.fillStyle='#ff2d2d';x.fillRect(100+ox,-18,9,9);x.fillStyle='#fff';x.fillRect(112+ox,-18,16,3);x.fillRect(112+ox,-12,12,3);x.fillRect(112+ox,-6,14,3)}
}
x.strokeRect(90+ox,-30,45,60);
}
function atk(){if(!run||mgOn||hm||p.dash||p.sw>=0||p.cd>0)return;const n=near();if(aimOn())p.face=aim.a;else if(n)p.face=Math.atan2(n.y-p.y,n.x-p.x);p.sw=0;p.hit=0;p.cd=CH[cs].cd*(1-.07*L.cd)}
function spc(){
if(!run||p.m<100)return;p.m=0;rg.push({x:p.x,y:p.y,r:20,l:1});shake=24;
for(const e of en){const dx=e.x-p.x,dy=e.y-p.y,d=Math.hypot(dx,dy)||1;if(d<240+e.t.r&&!(e.down>0))dmg(e,5,dx/d,dy/d,800)}
en=en.filter(e=>!e.dead);txt('БАН!',p.x,p.y-60,'#f59e0b');
}
function begin(){const src=lvSrc||LG;lv=lvMode?{g:src.slice(),done:{},n0:0,nf:!src.includes(9)}:null;reset();run=true;ov.style.display='none';aim=joy=null;$('atk').style.display=aimJoy?'none':'flex';$('spc').style.display='flex';$('prb').style.display='flex';$('ult').style.display='flex';$('spc').style.right=aimJoy?'20px':'';$('gdg').style.display=cg()>=0?'flex':'none';$('gdg').style.right=aimJoy?'96px':'';$('mgd').style.right=aimJoy?'172px':'';last=performance.now()}
function over(w){
if(w&&lvMode&&lvIdx>=0&&run){cmp=Math.max(cmp,lvIdx+1);const rw=3000*(lvIdx+1);coins+=rw;runCoins+=rw;save()}
run=false;aim=joy=null;$('atk').style.display=$('spc').style.display=$('gdg').style.display=$('mgd').style.display=$('prb').style.display=$('ult').style.display='none';
if(score>best){best=score;try{localStorage.setItem('rkn_best2',best)}catch(e){}}
ov.innerHTML='<div class="stamp">'+(w?'УРОВЕНЬ ПРОЙДЕН!':'ДОСТУП ОГРАНИЧЕН')+'</div><p>Очки: <b>'+score+'</b> · Волна: <b>'+wave+'</b></p><p>Рекорд: '+best+'</p><p>Монеты за бой: +'+fmt(runCoins)+'</p><p>Спасено мам-птиц: '+mr+'</p>'+(w&&lvIdx>=0&&lvIdx<CMP.length-1?'<button class="go" id="nx">Следующий уровень</button>':'')+'<button class="go" id="go">Ещё раз</button><button class="go" id="shp">МАГАЗИН</button><button class="go" id="set">НАСТРОЙКИ</button><button class="go" id="edb">РЕДАКТОР</button><button class="go" id="cmb">КАМПАНИЯ</button>'+(lvMode?'<button class="go" id="nm">Обычный режим</button>':'');
menuHTML=ov.innerHTML;ov.style.display='flex';bind();
}
let menuHTML=ov.innerHTML;function bind(){$('go').onclick=begin;$('shp').onclick=shop;$('set').onclick=settings;$('edb').onclick=editor;$('cmb').onclick=campaign;if($('nx'))$('nx').onclick=()=>{lvIdx++;lvSrc=CMP[lvIdx].g;lvMode=true;begin()};if($('nm'))$('nm').onclick=()=>{lvMode=false;begin()}}bind();
for(const [id,f] of [['atk',atk],['spc',spc],['gdg',gad],['mgd',mgad],['prb',parry],['ult',ult]])$(id).addEventListener('pointerdown',e=>{e.preventDefault();f()});
cv.addEventListener('pointerdown',e=>{
if(e.pointerType==='mouse'){atk();return}
if(aimJoy&&e.clientX>=W*.5&&!aim){aim={id:e.pointerId,ox:e.clientX,oy:e.clientY,cx:e.clientX,cy:e.clientY,a:p?p.face:0,len:0};cv.setPointerCapture(e.pointerId);return}
if(!joy&&e.clientX<W*(aimJoy?.5:.65)){joy={id:e.pointerId,ox:e.clientX,oy:e.clientY,cx:e.clientX,cy:e.clientY};cv.setPointerCapture(e.pointerId)}
});
cv.addEventListener('pointermove',e=>{if(joy&&e.pointerId===joy.id){joy.cx=e.clientX;joy.cy=e.clientY}if(aim&&e.pointerId===aim.id){aim.cx=e.clientX;aim.cy=e.clientY;const dx=aim.cx-aim.ox,dy=aim.cy-aim.oy;aim.len=Math.hypot(dx,dy);if(aim.len>12)aim.a=Math.atan2(dy,dx)}});
const up=e=>{if(joy&&e.pointerId===joy.id)joy=null;if(aim&&e.pointerId===aim.id)aim=null};
cv.addEventListener('pointerup',up);cv.addEventListener('pointercancel',up);
addEventListener('keydown',e=>{if(e.target.tagName==='INPUT')return;keys[e.code]=1;if(e.code==='Space'){e.preventDefault();atk()}if(e.code==='KeyE')spc();if(e.code==='KeyF')gad();if(e.code==='KeyG')mgad();if(e.code==='KeyQ')parry();if(e.code==='KeyR')ult()});
addEventListener('keyup',e=>{keys[e.code]=0});
const M='oaaaaaaaaaaaaaao',BODY=['..oooooooooooo..','.oaaaaaaaaaaaao.','oaakkaaaaaakkaao','oaaakkaaaakkaaao','oaaawkaaaakwaaao','oaaawwaaaawwaaao',M,M,M,M,M,M,M,M,'.oaaaaaaaaaaaao.','..oooooooooooo..'];
const DEMB=BODY.slice();DEMB[0]='.e.oooooooooo.e.';
const GL={tg:['....ww','.wwwww','wwwww.','..ww..','...w..'],yt:['ww....','wwww..','wwwwww','wwww..','ww....'],dc:['.wwww.','wwwwww','w.ww.w','wwwwww','.w..w.'],tt:['.wwww.','wwwwww','w.ww.w','.wwww.','.w..w.'],rb:['wwwww.','w...w.','w.w.w.','w...w.','wwwww.'],vpn:['wwwwww','wwwwww','wwwwww','.wwww.','..ww..'],boss:['w.ww.w','wwwwww','ww..ww','wwwwww','.w..w.']};
const PL=['....oooooooo....','...obbbbbbbbo...','..obbbbbbbbbbo..','..oyyyyyyyyyyo..','..osssssssssso..','..osksssssskso..','..osssssssssso..','..osssmmmmssso..','..oobbbbbbbboo..','.obbbbbbbbbbbbo.','.obbbyyyybbbbbo.','.obbbbbbbbbbbbo.','..obbbbbbbbbbo..','...oppo..oppo...','...oppo..oppo...','..oooooo.oooooo.'];
function mk(rows,pal,gl){
const c=document.createElement('canvas');c.width=c.height=16;const g=c.getContext('2d');
rows.forEach((r,j)=>[...r].forEach((ch,i)=>{if(pal[ch]){g.fillStyle=pal[ch];g.fillRect(i,j,1,1)}}));
if(gl)gl.forEach((r,j)=>[...r].forEach((ch,i)=>{if(ch=='w'){g.fillStyle='#fff';g.fillRect(i+5,j+8,1,1)}}));
const f=document.createElement('canvas');f.width=f.height=16;const h=f.getContext('2d');
h.drawImage(c,0,0);h.globalCompositeOperation='source-in';h.fillStyle='#fff';h.fillRect(0,0,16,16);return[c,f];
}
const SP={};for(const k in ET)SP[k]=mk(k=='rb'?DEMB:BODY,{o:'#0b0b12',a:ET[k].c,w:k=='tt'?'#d8ff5a':k=='rb'?'#ffeb3b':'#fff',k:'#0b0b12',e:'#e8d8b0'},GL[k]);
const PLB=['....oooooooo....', '...okkkkkkkko...', '..okkkkkkkkkko..', '..okksssssskko..', '..osssssssssso..', '..osksssssskso..', '..osddddddddso..', '..osddmmmmddso..', '..oocwwwwwwcoo..', '.occcwwrrwwccco.', '.occcccrrccccco.', '.occcccrrccccco.', '..occcccccccco..', '..occcccccccco..', '...oppo..oppo...', '..oooo....oooo..'];
const SPL=SK.map(k=>k.rows?mk(k.rows,k.pal):k.cb?mk(PLB,{o:'#0b0b12',c:'#2f2f38',w:'#e8e8e8',r:'#c0392b',k:'#1b130d',d:'#2e2018',s:'#e0b890',m:'#6a1010',p:'#1a1a22'}):mk(PL,{o:'#0b0b12',b:k.b,y:k.y||'#f2c14e',s:'#f1c9a0',k:'#0b0b12',m:'#b03030',p:k.pp||'#1d2f66'}));
const ADM=['....oooooooo....','...okkkkkkkko...','..okkkkkkkkkko..','..osssssssssso..','..osksssssskso..','..osssssssssso..','..osmmmmmmmmso..','..osmmmmmmmmso..','..ooossssssooo..','.obbbbbbbbbbbbo.','obbbbbbbbbbbbbbo','obbbbbbbbbbbbbbo','obbbbbbbbbbbbbbo','.obbbbbbbbbbbbo.','..oppo....oppo..','..oooo....oooo..'];
const VAL=['....oooooooo....','...orrrrrrrro...','..orrrrrrrrrro..','..orssssssssro..','..orskssssksro..','..orssssssssro..','..orssmmmmssro..','..osssssssssso..','..oobbbbbbbboo..','.obbbwbbbbwbbbo.','.obbbbbbbbbbbbo.','.obbwbbbbbbwbbo.','..obbbbbbbbbbo..','...osso..osso...','...osso..osso...','..oppppo.oppppo.'];
const GEN=['....oooooooo....','...osssssssso...','..osssssssssso..','..oskksssskkso..','..osksssssskso..','..osssssssssso..','..ossmmmmmssso..','...osssssssso...','osssbbbbbbbbssso','osssbbbbbbbbssso','osssbbbbbbbbssso','.ossbbbbbbbbsso.','..obbbbbbbbbbo..','...opppoopppo...','...opppoopppo...','..oooooooooooo..'];
const FND=['....oooooooo....','...okkkkkkkko...','..okkkkkkkkkko..','..osssssssssso..','..osksssssskso..','..osssssssssso..','..osssssssssso..','..osdddmmdddso..','..oohhhhhhhhoo..','.ohhhhhhhhhhhho.','.ohhhhvvvvhhhho.','.ohhhhvvvvhhhho.','..ohhhhhhhhhho..','...opppoopppo...','...opppoopppo...','..ooooo..ooooo..'];
const VKF=[['110','101','110','101','110'],['101','101','110','101','101']];
const STA=['....oooooooo....','...orrrrrrrro...','..orrrrrrrrrro..','..ovvvvvvvvvvo..','..orrrrrrrrrro..','..oojjjjjjjjoo..','ohhojjyyyyjjohho','.oooojjjjjjoooo.','....oggggggo....','...oggyyyyggo...','....oggggggo....','...oooooooooo...','...okkkkkkkko...','...okkwwwwkko...','...okkkkkkkko...','....oooooooo....'];
const O1=['.....oooooo.....', '...ooHHHHHHoo...', '..oHHHHHHHHHHo..', '.oHHHHHHHHHHHHo.', '.oHHffffffffHHo.', '.oHffffffffffHo.', '.oHffffWBffffHo.', '.oHffffBBffffHo.', '.oHHffffffffHHo.', '..oHHHHHHHHHHo..', '.oHHHHHHHHHHHHo.', '.oHHHcHHHHcHHHo.', '.oHHHHHHHHHHHHo.', '..oHHHHHHHHHHo..', '...oHHo..oHHo...', '...oooo..oooo...'];
const JD=['....oooooooo....', '...okkkkkkkko...', '..okkkkkkkkkko..', '..okssssssssko..', '..ossscsssssso..', '..osXXssssXXso..', '..osXwssssXwso..', '..osssssscssso..', '..osssmmmmssso..', '..oobbbbbbbboo..', '.obbbbbbbbbbbbo.', '.obbsbbbbbbsbbo.', '.obbbbbbbbbbbbo.', '..obbbbbbbbbbo..', '...opppoopppo...', '..ooooo..ooooo..'];
const UKS=[];
const SPC=[null,mk(ADM,{o:'#0b0b12',b:'#5fb84a',k:'#2a1a10',m:'#8a1a1a',p:'#2a3a6a',s:'#f1c9a0'}),mk(VAL,{o:'#0b0b12',b:'#3a6ea5',w:'#fff',r:'#d23c3c',m:'#b03030',k:'#0b0b12',p:'#ffb703',s:'#f1c9a0'}),mk(GEN,{o:'#0b0b12',b:'#e5e5e5',k:'#0b0b12',m:'#802020',p:'#2a2a2a',s:'#e0a070'}),mk(FND,{o:'#0b0b12',k:'#1a1208',s:'#f1c9a0',d:'#4a3428',m:'#8a1a1a',h:'#20242e',v:'#0077ff',p:'#2b4c9b'}),mk(STA,{o:'#0b0b12',r:'#e5383b',v:'#142033',j:'#2b4c9b',y:'#ffd23f',h:'#9ca3af',g:'#6b7280',k:'#1a1a22',w:'#cfd3da'}),mk(O1,{o:'#07080c',H:'#2a2d3d',f:'#0b0c12',W:'#ffffff',B:'#4dc3ff',c:'#4dc3ff'})];
UKS.push(mk(PL,{o:'#0b0b12',b:'#2a2a30',y:'#e5383b',s:'#c9ced6',k:'#00e5ff',m:'#e5383b',p:'#1a1a22'}),
mk(ADM,{o:'#0b0b12',b:'#f2f2f2',k:'#ffd23f',m:'#7a5a00',p:'#ffd23f',s:'#fde68a'}),
mk(VAL,{o:'#0b0b12',r:'#7a1018',s:'#c9ced6',k:'#ff2d2d',m:'#e5383b',b:'#2a2a30',w:'#e5383b',p:'#ffd23f'}),
mk(GEN,{o:'#0b0b12',s:'#9aa0a6',k:'#ff7a1a',m:'#7a1018',b:'#3a3a42',p:'#1a1a22'}),
mk(FND,{o:'#0b0b12',k:'#0b0b12',s:'#c9ced6',d:'#6b7280',m:'#00e5ff',h:'#111827',v:'#00e5ff',p:'#111827'}),
mk(STA,{o:'#0b0b12',r:'#1a1a22',v:'#ff7a1a',j:'#7a1018',y:'#ffd23f',h:'#9ca3af',g:'#4b5563',k:'#1a1a22',w:'#ff7a1a'}),
mk(JD,{o:'#07080c',k:'#0b0b12',s:'#b9bcc4',c:'#6b7280',X:'#000000',w:'#ffffff',m:'#3a3a44',b:'#262230',p:'#15131c'}));
function mkMango(f){
const N=28,c=document.createElement('canvas');c.width=c.height=N;const g=c.getContext('2d');
const r=(X,Y,w,h,col)=>{g.fillStyle=col;g.fillRect(X,Y,w,h)};
const crown=(ox,oy,col)=>{r(13+ox,0+oy,2,3,col);r(9+ox,1+oy,2,2,col);r(17+ox,1+oy,2,2,col);r(9+ox,3+oy,10,2,col)};
[[-1,0],[1,0],[0,-1],[0,1]].forEach(o=>crown(o[0],o[1],'#0b0b12'));
for(let Y=4;Y<26;Y++)for(let X=0;X<N;X++){
const dx=X+.5-14+(Y-14)*.1,dy=Y+.5-14.5,v=dx*dx/144+dy*dy/100;
if(v>1)continue;
if(v>.82){r(X,Y,1,1,'#0b0b12');continue}
const q=dx/12*.6+dy/10*.8;
r(X,Y,1,1,q<-.55?'#9ad64a':q<-.2?'#ffd23f':q<.35?'#ff9f1c':'#ff5a36');
}
r(0,14,5,5,'#0b0b12');r(1,15,3,3,'#ff9f1c');r(23,14,5,5,'#0b0b12');r(24,15,3,3,'#ff9f1c');
r(7,25,6,3,'#0b0b12');r(8,25,4,2,'#b34a1a');r(15,25,6,3,'#0b0b12');r(16,25,4,2,'#b34a1a');
r(5,12,2,2,'#ff7a7a');r(21,12,2,2,'#ff7a7a');
r(19,4,4,2,'#2f9e44');r(22,3,2,1,'#57c25b');r(21,6,2,1,'#57c25b');
crown(0,0,'#ffd23f');r(9,4,10,1,'#e0a800');
r(10,3,1,1,'#4dc3ff');r(13,3,2,1,'#ff2d2d');r(17,3,1,1,'#4dc3ff');
for(let X=5;X<=22;X++){const t=(X-13.5)/8.5,Y=15+Math.round(3*(1-t*t));r(X,Y,1,2,X%2?'#ffd23f':'#e0a800');r(X,Y+2,1,1,'#0b0b12')}
r(5,18,18,7,'#0b0b12');r(6,19,16,5,'#ffd23f');r(6,23,16,1,'#e0a800');
const FN={A:['010','101','111','101','101'],U:['101','101','101','101','111'],R:['110','101','110','101','101']};
'AURA'.split('').forEach((ch,i)=>FN[ch].forEach((row,j)=>[...row].forEach((v,k)=>{if(v=='1')r(6+i*4+k,19+j,1,1,'#0b0b12')})));
r(4,9,2,1,'#ffd23f');r(22,9,2,1,'#ffd23f');r(12,9,4,1,'#ffd23f');
r(6,8,6,4,'#ffd23f');r(16,8,6,4,'#ffd23f');r(7,9,4,2,'#0b0b12');r(17,9,4,2,'#0b0b12');
r(7,9,1,1,'#7fe7ff');r(17,9,1,1,'#7fe7ff');r(10,10,1,1,'#2a4a9a');r(20,10,1,1,'#2a4a9a');
if(f==1){r(8,7,1,5,'#fff');r(6,9,5,1,'#fff')}
if(f==2){r(6,6,3,1,'#0b0b12');r(9,7,3,1,'#0b0b12');r(19,6,3,1,'#0b0b12');r(16,7,3,1,'#0b0b12')}
if(f==2){r(11,14,6,2,'#3a0a0a');r(12,16,4,1,'#ff6b8a')}
else{r(10,14,1,1,'#0b0b12');r(17,14,1,1,'#0b0b12');r(11,15,6,1,'#0b0b12')}
return c;
}
const BIRD=['....oooooooo....', '...oCCCCCCCCo...', '..oCCCCCCCCCCo..', '.occcccccccccco.', '.oBGsGGBBGsGGBo.', '.oBGGGGBBGGGGBo.', '.oBBBBOOOOBBBBo.', '.oBBBBBOOBBBBBo.', '.oBWWBwwwwBWWBo.', '.oBWWwwwwwwWWBo.', '.oBBwwwwwwwwBBo.', '..oBBwwwwwwBBo..', '...oBBBBBBBBo...', '....oooooooo....', '.....OO..OO.....', '................'];
const BIRDM=BIRD.slice();BIRDM[0]='....o.o..o.o....';BIRDM[1]='...oCCoCCoCCo...';
const BIRDP=BIRD.slice();BIRDP[0]='....oooooooo....';BIRDP[1]='...oCCCCCCCCo...';BIRDP[2]='..oCCCCCCCCCCo..';BIRDP[3]='.o'+'C'.repeat(12)+'o.';BIRDP[4]='.oBBqRBBBBRqBBo.';BIRDP[5]='.oBBBBBBBBBBBBo.';BIRDP[8]='.oBWWBBBBBBWWBo.';BIRDP[9]='.oBWWBBwwBBWWBo.';BIRDP[10]='.oBBBBBwwBBBBBo.';BIRDP[11]='..o'+'B'.repeat(10)+'o..';BIRDP[12]='...o'+'r'.repeat(8)+'o...';
const SBS=BS.map(k=>mk(k.ls?BIRDP:k.mg?BIRDM:BIRD,{o:'#0b0b12',B:k.B,W:k.W,w:k.w||'#fff3d6',O:'#ff9f1c',C:k.C,c:k.c,G:k.G,s:'#7fe7ff',R:'#ff2d2d',q:'#ffffff',r:'#c0392b'}));
const SCH=mk(['...oo...','..oSSo..','..oGGo..','.oGGGGo.','.okGGko.','.oGwwGo.','.oGGGGo.','..oooo..'],{o:'#0b0b12',S:'#cfd3da',G:'#7fd6a8',w:'#fff',k:'#0b0b12'});
const SGZ=mk(['.oooooo.','oBBBBBBo','oBwwwwBo','oBkwwkBo','oBwwwwBo','oBwmmwBo','oBBBBBBo','.oooooo.'],{o:'#0b0b12',B:'#2563eb',w:'#fff3d6',k:'#0b0b12',m:'#c0392b'});
const CK=['..oooo..','.oYYYYo.','oYkYYkYo','oYYOOYYo','oYYYYYYo','.oYYYYo.','..oO.Oo.','........'];
const SCK=BS.map(k=>mk(CK,{o:'#0b0b12',Y:k.y,k:'#0b0b12',O:'#ff9f1c'}));
const SPM=[0,1,2].map(mkMango);
function mkMon(f){
const N=20,c=document.createElement('canvas');c.width=c.height=N;const g=c.getContext('2d');
const r=(X,Y,w,h,col)=>{g.fillStyle=col;g.fillRect(X,Y,w,h)};
const B='#e8d8b0';r(3,4,2,2,B);r(2,2,2,2,B);r(2,1,1,1,B);r(15,4,2,2,B);r(16,2,2,2,B);r(17,1,1,1,B);
for(let Y=2;Y<19;Y++){const hw=Y<11?8.5:8.5*(1-(Y-10.5)/9);for(let X=0;X<N;X++){const dx=Math.abs(X+.5-10);if(dx>=hw)continue;r(X,Y,1,1,(dx>hw-1||Y==2)?'#0b0b12':Y>12?'#4c1d95':Y>7?'#7c3aed':'#a78bfa')}}
r(4,5,1,4,'#c4b5fd');
r(6,5,8,6,'#0b0b12');r(7,6,6,4,'#fff');r(9,6,3,4,'#e5383b');r(10,7,1,2,'#0b0b12');r(7,6,6,1,'#0b0b12');r(7,6,1,2,'#0b0b12');r(12,6,1,2,'#0b0b12');
const mh=f?5:4;r(6,12,8,mh,'#2a0a1a');
for(let X=6;X<14;X+=2){r(X,12,1,2,'#fff');r(X+1,12+mh-2,1,2,'#fff')}
if(f)r(8,14,4,2,'#ff6b8a');
return c;
}
function wh(c){const w=document.createElement('canvas');w.width=w.height=c.width;const h=w.getContext('2d');h.drawImage(c,0,0);h.globalCompositeOperation='source-in';h.fillStyle='#fff';h.fillRect(0,0,c.width,c.height);return w}
{const a=mkMon(0);SP.mon=[a,wh(a),mkMon(1)]}
function drawBaz(X,Y,a){x.save();x.translate(sn(X),sn(Y));x.rotate(a);x.fillStyle='#0b0b12';x.fillRect(4,-9,46,18);x.fillStyle='#5a6b4a';x.fillRect(7,-6,40,12);x.fillStyle='#3a4630';x.fillRect(44,-7,6,14);x.fillStyle='#a855f7';x.fillRect(50,-5,4,10);x.fillStyle='#7CFC9A';x.fillRect(-6,-4,10,8);x.restore()}
function boom(b){
rg.push({x:b.x,y:b.y,r:10,l:.6});shake=Math.max(shake,12);
for(let i=0;i<24;i++)burst(b.x,b.y,i%2?'#a855f7':'#7CFC9A',1);
for(const e of en){if(e.dead||e.down>0)continue;const dx=e.x-b.x,dy=e.y-b.y,d=Math.hypot(dx,dy)||1;if(d<95+e.t.r)dmg(e,(b.bd||4)+L.dmg,dx/d,dy/d,e.t.boss?150:600)}
en=en.filter(e=>!e.dead);
}
function drawE(e){
const sc=e.t.boss?2:1,z=e.t.zz||16*S*sc,b=Math.round(Math.sin(e.ph))*S,s=SP[e.k];
x.fillStyle='rgba(0,0,0,.35)';x.fillRect(sn(e.x-z/2+6),sn(e.y+z/2-9),z-12,9);
const dn=e.down>0;if(dn)x.globalAlpha=.5;
x.drawImage(e.fl>.5?s[1]:(e.roar>0&&s[2]?s[2]:s[0]),sn(e.x-z/2),sn(e.y-z/2)+b+(dn?z*.4:0),z,dn?z*.6:z);x.globalAlpha=1;
if(e.k==='tg'){const a=Math.atan2(p.y-e.y,p.x-e.x);x.save();x.translate(sn(e.x),sn(e.y+3));x.rotate(a);x.fillStyle='#0b0b12';x.fillRect(4,-8,36,16);x.fillStyle='#5a6b4a';x.fillRect(7,-5,30,10);x.fillStyle='#3a4630';x.fillRect(34,-6,6,12);x.restore()}
if(e.dash>.5){x.strokeStyle='#ff3b3b';x.lineWidth=6;x.strokeRect(sn(e.x-z/2),sn(e.y-z/2),z,z)}
x.fillStyle='#000';x.fillRect(sn(e.x-z/2),sn(e.y+z/2+6),z,6);
x.fillStyle='#e5383b';x.fillRect(sn(e.x-z/2),sn(e.y+z/2+6),z*Math.max(0,e.hp)/e.mx,6);
if(e.t.boss){x.fillStyle='#fff';x.font='bold 21px "Courier New",monospace';x.textAlign='center';x.fillText(e.t.n,e.x,e.y+z/2+34)}
}
function drawP(){
const C=CH[cs],K=SK[skin],sw=p.sw>=0?p.sw/.28:0,ease=sw*sw*(3-2*sw),ang=p.face-1.4+(p.sw>=0?ease*2.8:0),R=RM();
x.fillStyle='rgba(0,0,0,.35)';x.fillRect(sn(p.x-(K.mango?36:21)),sn(p.y+(K.mango?26:15)),K.mango?72:42,9);
if(K.mango){x.fillStyle='rgba(255,159,28,'+(.18+.08*Math.sin(last/150))+')';x.fillRect(sn(p.x-33),sn(p.y+9),66,15);x.fillRect(sn(p.x-24),sn(p.y+3),48,27)}
if(C.atk==='burp'&&p.sw>=0){x.fillStyle='rgba(155,229,100,.28)';x.beginPath();x.moveTo(p.x,p.y);x.arc(p.x,p.y,C.rng*R*(.4+.6*sw),p.face-C.arc,p.face+C.arc);x.closePath();x.fill()}
if(C.atk==='hammer'&&!hm){
if(p.sw>=0){const tc=K.pc||['#fff'];tc.forEach((c,i)=>{x.strokeStyle=c;x.globalAlpha=.55;x.lineWidth=K.pc?9:15;x.beginPath();x.arc(p.x,p.y,(115-i*9)*R,p.face-1.4,ang);x.stroke()});x.globalAlpha=1}
x.save();x.translate(sn(p.x),sn(p.y));x.rotate(ang);x.scale(R,R);
drawHam(K,0);
x.restore();
}
if(!(p.inv>0&&(p.inv*20|0)%2)){
const jy=C.atk==='stomp'&&p.sw>=0?-Math.round(Math.sin(sw*Math.PI)*15/S)*S:0,ox=C.atk==='burp'&&p.sw>=0?-Math.round(Math.cos(p.face)*6/S)*S:0;
if(K.mango){const fr=p.sw>=0?2:((last/1000)%3<.14?1:0),bb=Math.round(Math.sin(last/220))*S;x.drawImage(SPM[fr],sn(p.x-42)+ox,sn(p.y-50)+jy+bb,84,84)}
else{const ua=ukA();if(ua)uWings(sn(p.x)+ox,sn(p.y)+jy);x.drawImage((ua?UKS[cs]:cs?SPC[cs]:SPL[skin])[0],sn(p.x-24)+ox,sn(p.y-24)+jy,48,48);if(ua)uDeco(sn(p.x)+ox,sn(p.y)+jy);else if(cs===0)skinDeco(K,sn(p.x)+ox,sn(p.y)+jy);if(cs===6&&!ua)o1Glow(sn(p.x)+ox,sn(p.y)+jy)}}
}
function loop(now){
requestAnimationFrame(loop);
const dt=Math.min((now-last)/1000||0,.05);last=now;
fz=Math.max(0,fz-dt);pf=Math.max(0,pf-dt*2);
if(run&&!mgOn&&fz<=0){
let mx=(keys.KeyD||keys.ArrowRight?1:0)-(keys.KeyA||keys.ArrowLeft?1:0),my=(keys.KeyS||keys.ArrowDown?1:0)-(keys.KeyW||keys.ArrowUp?1:0);
if(joy){mx=(joy.cx-joy.ox)/50;my=(joy.cy-joy.oy)/50}
const ml=Math.hypot(mx,my);if(ml>1){mx/=ml;my/=ml}
const sv=220*(1+.06*L.spd)*(lv?spBoost:1)*(cs===5?1.35:1);p.x+=(mx*sv+p.vx)*dt;p.y+=(my*sv+p.vy)*dt;p.vx*=Math.pow(.01,dt);p.vy*=Math.pow(.01,dt);
p.x=Math.max(22,Math.min(W-22,p.x));p.y=Math.max(70,Math.min(H-22,p.y));if(lv)wallPush(p,16);
if(p.dash){const d=p.dash;d.t-=dt;p.inv=Math.max(p.inv,.15);
if(d.tg){if(d.tg.dead){d.t=0;d.n=0}else{const hx=d.tg.x-p.x,hy=d.tg.y-p.y,hl=Math.hypot(hx,hy)||1;d.vx=hx/hl*d.spd;d.vy=hy/hl*d.spd;if(hl<d.tg.t.r+34){blast(p.x,p.y,100,3+(SK[skin].db||0),500,'#4dc3ff');dmg(d.tg,2+L.dmg,hx/hl,hy/hl,300);txt('ПРИТЯНУЛСЯ!',p.x,p.y-50,'#4dc3ff');d.t=0;d.n=0}}}
p.x+=d.vx*dt;p.y+=d.vy*dt;p.x=Math.max(22,Math.min(W-22,p.x));p.y=Math.max(70,Math.min(H-22,p.y));if(lv)wallPush(p,16);burst(p.x,p.y+16,'#ffd23f',1);
for(const e of en){if(e.dead||e.down>0||d.hs.includes(e))continue;if(Math.hypot(e.x-p.x,e.y-p.y)<e.t.r+26){d.hs.push(e);const ex=e.x-p.x,ey=e.y-p.y,el=Math.hypot(ex,ey)||1;txt('ДАВИТ!',e.x,e.y-e.t.r,'#ffd23f');dmg(e,(d.u?5:3)+L.dmg+(SK[skin].db||0),ex/el,ey/el,e.t.boss?120:520)}}
en=en.filter(e=>!e.dead);
if(d.t<=0){if(d.n>1)startDash(1100,.4,d.n-1,1);else p.dash=null}}
p.inv-=dt;p.cd-=dt;p.gc-=dt;p.mc-=dt;p.pr-=dt;p.up=(p.up||0)-dt;p.pc-=dt;p.ul=Math.min(100,p.ul+dt*1.5);if(lv)lvTick(dt);if(aimOn())atk();
if(p.sw>=0){p.sw+=dt;{const K=SK[skin];if(K.pc&&CH[cs].atk==='hammer'){const w=Math.min(1,p.sw/.28),a=p.face-1.4+w*w*(3-2*w)*2.8;burst(p.x+Math.cos(a)*112*RM(),p.y+Math.sin(a)*112*RM(),K.pc[Math.random()*K.pc.length|0],K.mango?3:1)}}if(!p.hit&&p.sw>.13){p.hit=1;strike()}if(p.sw>.28)p.sw=-1}
else{const n=near();if(aimOn())p.face=aim.a;else if(n)p.face=Math.atan2(n.y-p.y,n.x-p.x);else if(ml>.1)p.face=Math.atan2(my,mx)}
ct-=dt;if(ct<=0)combo=0;{const K4=SK[skin];if(K4.pc&&Math.random()<(K4.mango?.2:.06))burst(p.x+(Math.random()-.5)*40,p.y+20,K4.mango?'#ffd23f':K4.pc[Math.random()*K4.pc.length|0],1)}
for(const e of en){
e.life+=dt;e.ph+=dt*8;e.fl=Math.max(0,e.fl-dt*5);if(e.roar>0)e.roar-=dt;if(e.down>0){e.down-=dt;continue}
const dx=p.x-e.x,dy=p.y-e.y,d=Math.hypot(dx,dy)||1,fx=dx/d,fy=dy/d;
if(e.st>0)e.st-=dt;
else{
let sp=e.t.sp*(1+wave*.02),ux=fx,uy=fy;
if(e.t.flee){if(d<300){ux=-fx-fy*.6;uy=-fy+fx*.6}else{ux=-fy*.5;uy=fx*.5}}
if(e.t.dash){e.dt-=dt;if(e.dt<0&&e.dash<=0){e.dash=.9;e.dt=3+Math.random()*2}
if(e.dash>0){e.dash-=dt;sp=e.dash>.5?0:sp*4}}
if(e.t.baz){if(d<170)sp=-sp*.6;else if(d<260)sp=0;e.dt-=dt;if(e.dt<=0){e.dt=2.6+Math.random();ep.push({x:e.x,y:e.y,vx:fx*280,vy:fy*280,l:3,k:'rk',o:e});burst(e.x+fx*30,e.y+fy*30,'#ffd23f',5)}}
if(e.t.demon){e.dt-=dt;if(e.dt<=0){e.dt=4+Math.random()*1.5;burst(e.x,e.y,'#ff2d2d',12);const a=Math.random()*6.28;e.x=Math.max(30,Math.min(W-30,p.x+Math.cos(a)*190));e.y=Math.max(80,Math.min(H-30,p.y+Math.sin(a)*190));burst(e.x,e.y,'#ff2d2d',12);const a2=Math.atan2(p.y-e.y,p.x-e.x);for(const o of[-.3,0,.3])ep.push({x:e.x,y:e.y,vx:Math.cos(a2+o)*300,vy:Math.sin(a2+o)*300,l:2.5,k:'fb',o:e})}}
if(e.t.mon){e.dt-=dt;if(e.dt<=0){e.dt=3.2;e.roar=.5;for(let i=0;i<10;i++){const a=i/10*6.283+e.life;ep.push({x:e.x,y:e.y,vx:Math.cos(a)*230,vy:Math.sin(a)*230,l:3.5,k:'fb',o:e})}shake=Math.max(shake,8)}
e.tp=(e.tp===undefined?6:e.tp)-dt;if(e.tp<=0){e.tp=6.5;burst(e.x,e.y,'#a78bfa',20);e.x=80+Math.random()*(W-160);e.y=120+Math.random()*(H-200);burst(e.x,e.y,'#a78bfa',20);txt('VPN: ТЕЛЕПОРТ!',e.x,e.y-70,'#a78bfa')}
e.sm=(e.sm===undefined?5:e.sm)-dt;if(e.sm<=0){e.sm=9;e.roar=.5;txt('ПРИЗЫВ!',e.x,e.y-70,'#e5383b');spawn('tg');spawn('dc');spawn('dc')}}
e.x+=ux*sp*dt;e.y+=uy*sp*dt;
}
e.x+=e.kx*dt;e.y+=e.ky*dt;const k=Math.pow(.02,dt);e.kx*=k;e.ky*=k;if(lv)wallPush(e,e.t.r*.7);
if(e.t.flee){e.x=Math.max(20,Math.min(W-20,e.x));e.y=Math.max(70,Math.min(H-20,e.y));if(e.life>10)e.dead=1}
if(((p.pr>0&&d<e.t.r+44)||(p.up>0&&d<e.t.r+260))&&!(e.down>0)){parryHit(e.x,e.y);parryKill(e)}
else if(cs===5&&ml>.3&&d<e.t.r+26&&!(e.down>0)){e.rt=(e.rt||0)-dt;if(e.rt<=0){e.rt=.3;dmg(e,2+L.dmg+(SK[skin].db||0),-fx,-fy,e.t.boss?80:360);burst(e.x,e.y,'#ffd23f',5);if(Math.random()<.3)txt('ДАВИТ!',e.x,e.y-e.t.r,'#ffd23f')}}
else if(e.t.dmg&&d<e.t.r+16&&p.inv<=0&&e.st<=0)hurt(e.t.dmg,fx,fy);
}
for(let i=0;i<en.length;i++)for(let j=i+1;j<en.length;j++){
const a=en[i],b=en[j],dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||1,m=a.t.r+b.t.r;
if(d<m){const f=(m-d)/2/d;a.x-=dx*f;a.y-=dy*f;b.x+=dx*f;b.y+=dy*f}
}
if(hm){const h=hm,K=SK[skin];h.rot+=dt*18;
if(h.ph==='out'){h.x+=h.vx*dt;h.y+=h.vy*dt;h.d+=Math.hypot(h.vx,h.vy)*dt;if(h.d>=h.max||h.x<10||h.x>W-10||h.y<60||h.y>H-10){h.ph='back';h.hs=[]}}
else{const dx=p.x-h.x,dy=p.y-h.y,d=Math.hypot(dx,dy)||1;h.x+=dx/d*950*dt;h.y+=dy/d*950*dt;if(d<28){hm=null;p.gc=GD[cg()>=0?cg():0].cd;burst(p.x,p.y,'#fff',8);txt('ЛОВЛЮ!',p.x,p.y-50,'#fff')}}
if(hm){if(Math.random()<.4)burst(h.x,h.y,K.pc?K.pc[Math.random()*K.pc.length|0]:'#fff',1);
for(const b of ep)if(Math.hypot(b.x-h.x,b.y-h.y)<45)b.l=0;
for(const e of en){if(e.dead||e.down>0||h.hs.includes(e))continue;if(Math.hypot(e.x-h.x,e.y-h.y)<e.t.r+34){h.hs.push(e);const dx=e.x-h.x,dy=e.y-h.y,d=Math.hypot(dx,dy)||1;dmg(e,2+L.dmg+(SK[skin].db||0),dx/d,dy/d,e.t.boss?100:380)}}
en=en.filter(e=>!e.dead)}}
{const me=$('mgd'),show=bd&&ms>=0,d2=show?'flex':'none';if(me.style.display!==d2)me.style.display=d2;if(show){const gt=p.mc>0?Math.ceil(p.mc)+'с':MG[ms].sh;if(me.textContent!==gt)me.textContent=gt;me.className='b'+(p.mc>0?' cd':'')}}
{const pe=$('prb'),t2=p.pc>0?Math.ceil(p.pc)+'с':'ПАРИР';if(pe.textContent!==t2)pe.textContent=t2;pe.className='b'+(p.pc>0?' cd':'');const ue=$('ult'),rd=p.ul>=100,t3=rd?'УЛЬТА!':Math.floor(p.ul)+'%';if(ue.textContent!==t3)ue.textContent=t3;ue.className='b'+(rd?' rdy':'')}
const gl=cg();if(gl>=0){const gt=hm?'…':p.gc>0?Math.ceil(p.gc)+'с':GD[gl].sh,ge=$('gdg');if(ge.textContent!==gt)ge.textContent=gt;ge.className='b'+(hm||p.gc>0?' cd':'')}
for(const q2 of dq){q2.t-=dt;if(q2.t<=0){q2.done=1;if(q2.pr)pr.push(q2.pr);else blast(q2.x,q2.y,q2.r,q2.d,q2.kb,q2.c)}}dq=dq.filter(q2=>!q2.done);
pw=Math.max(0,pw-dt);
if(gn){gn.cd-=dt;if(gn.cd<=0&&!mgOn&&Math.hypot(p.x-gn.x,p.y-gn.y)<48){gn.cd=3;startMini('gen',ok=>{if(ok&&gn){pw=20;p.hp=Math.min(p.mh,p.hp+p.mh*.2);burst(gn.x,gn.y,'#ffd23f',24);txt('ЭНЕРГИЯ! Урон ×1.5 на 20 с',p.x,p.y-60,'#ffd23f');gn=null}else if(gn)gn.cd=3},Math.min(4,Math.floor(wave/3)))}}
if(mb){if(Math.hypot(p.x-mb.x,p.y-mb.y)<66)mb.pr+=dt/2;else mb.pr=Math.max(0,mb.pr-dt*.5);
if(mb.pr>=1){const gain=200*wave;coins+=gain;runCoins+=gain;score+=100;mr++;save();p.hp=Math.min(p.mh,p.hp+40);burst(mb.x,mb.y,'#ffd23f',24);burst(mb.x,mb.y,'#4aa3df',14);txt('МАМА СПАСЕНА! +'+gain,mb.x,mb.y-50,'#7CFC9A');bd={x:mb.x,y:mb.y,cd:.5,a:0};mb=null}}
if(bd){bd.cd-=dt;bd.ls=Math.max(0,(bd.ls||0)-dt);let tg=null,td=1e9;
for(const e of en){if(e.dead||e.down>0||e.t.flee)continue;const d=Math.hypot(e.x-bd.x,e.y-bd.y);if(d<td){td=d;tg=e}}
const tx2=p.x+Math.cos(last/500)*60,ty2=p.y-55+Math.sin(last/300)*14,dx=tx2-bd.x,dy=ty2-bd.y,d=Math.hypot(dx,dy)||1;
bd.x+=dx/d*Math.min(300*dt,d);bd.y+=dy/d*Math.min(300*dt,d);
bd.a=tg?Math.atan2(tg.y-bd.y,tg.x-bd.x):p.face;
if(tg&&td<520&&bd.cd<=0){bd.cd=2;const K2=BS[bs],nn=K2.v||2;for(let i=0;i<nn;i++){const a=bd.a+(i-(nn-1)/2)*.35;ck.push({x:bd.x+Math.cos(a)*50,y:bd.y+Math.sin(a)*50,vx:Math.cos(a)*420,vy:Math.sin(a)*420,l:5,cd:0,ph:Math.random()*6})}burst(bd.x+Math.cos(bd.a)*54,bd.y+Math.sin(bd.a)*54,K2.y,6);if(K2.ls){bd.ls=.3;const ca=Math.cos(bd.a),sa=Math.sin(bd.a);for(const e of en){if(e.dead||e.down>0)continue;const rx=e.x-bd.x,ry=e.y-bd.y,al=rx*ca+ry*sa;if(al<0||al>460)continue;if(Math.abs(-rx*sa+ry*ca)<e.t.r+8){burst(e.x,e.y,'#ff2d2d',8);burst(e.x,e.y,'#fff',3);dmg(e,4+L.dmg,ca,sa,e.t.boss?40:260)}}en=en.filter(e=>!e.dead)}if(Math.random()<.4)txt('ПТЕНЦЫ, В АТАКУ!',bd.x,bd.y-40,'#ffd23f')}
en=en.filter(e=>!e.dead)}
if(oh[0]&&ha[0]){hl.forEach((h,i)=>{h.cd-=dt;h.ph+=dt*3;let tg=null,td=230;
for(const e of en){if(e.dead||e.down>0||e.t.flee)continue;const d=Math.hypot(e.x-p.x,e.y-p.y);if(d<td){td=d;tg=e}}
const tx2=tg?tg.x:p.x+Math.cos(h.ph+i*3.14)*70,ty2=tg?tg.y:p.y+Math.sin(h.ph+i*3.14)*70,dx=tx2-h.x,dy=ty2-h.y,d=Math.hypot(dx,dy)||1,sp=tg?420:300;
h.x+=dx/d*Math.min(sp*dt,d);h.y+=dy/d*Math.min(sp*dt,d);
if(tg&&Math.hypot(tg.x-h.x,tg.y-h.y)<tg.t.r+14&&h.cd<=0){h.cd=.5;burst(h.x,h.y,'#7fd6a8',4);dmg(tg,1+L.dmg,dx/d,dy/d,tg.t.boss?40:200)}});en=en.filter(e=>!e.dead)}
if(gz){gz.l=Math.max(0,gz.l-dt);gz.x+=(p.x-45-gz.x)*Math.min(1,dt*5);gz.y+=(p.y-60+Math.sin(last/300)*6-gz.y)*Math.min(1,dt*5);gz.t-=dt;
if(gz.t<=0){let tg=null;for(const e of en){if(e.dead||e.down>0||e.t.flee)continue;if(!tg||e.hp>tg.hp)tg=e}
if(tg){gz.t=7;gz.l=.3;gz.tx=tg.x;gz.ty=tg.y;txt('ГДЗ: ОТВЕТ '+(10+Math.random()*90|0)+'!',tg.x,tg.y-tg.t.r-10,'#7fe7ff');dmg(tg,Math.max(4,Math.min(12,Math.ceil(tg.hp*.25)))+L.dmg,0,-1,tg.t.boss?30:160);en=en.filter(e=>!e.dead)}else gz.t=1}}
for(const c of ck){c.l-=dt;c.cd-=dt;c.ph+=dt*14;let tg=null,td=1e9;
for(const e of en){if(e.dead||e.down>0||e.t.flee)continue;const d=Math.hypot(e.x-c.x,e.y-c.y);if(d<td){td=d;tg=e}}
const tx2=tg?tg.x:p.x+Math.cos(c.ph*.1)*70,ty2=tg?tg.y:p.y+Math.sin(c.ph*.1)*70,dx=tx2-c.x,dy=ty2-c.y,d=Math.hypot(dx,dy)||1,sp=tg?380:240;
c.vx+=(dx/d*sp-c.vx)*Math.min(1,dt*6);c.vy+=(dy/d*sp-c.vy)*Math.min(1,dt*6);c.x+=c.vx*dt;c.y+=c.vy*dt;if(BS[bs].wb){c.vx+=(Math.random()-.5)*900*dt;c.vy+=(Math.random()-.5)*900*dt}{const K3=BS[bs];if(K3.au&&Math.random()<.35)burst(c.x,c.y,K3.au[Math.random()*K3.au.length|0],1)}
if(tg&&td<tg.t.r+16&&c.cd<=0){c.cd=.35;burst(c.x,c.y,BS[bs].y,3);if(Math.random()<.2)txt('КЛЁВ!',tg.x,tg.y-tg.t.r,'#ffd23f');dmg(tg,1+L.dmg+(BS[bs].dm||0),dx/d,dy/d,tg.t.boss?30:90)}}
ck=ck.filter(c=>c.l>0);en=en.filter(e=>!e.dead);
for(const b of ep){b.x+=b.vx*dt;b.y+=b.vy*dt;b.l-=dt;if(lv&&lvCell(b.x,b.y)===1){b.l=0;continue}const sv=Math.hypot(b.vx,b.vy),rk=b.k=='rk';
if((p.pr>0&&Math.hypot(b.x-p.x,b.y-p.y)<95)||(p.up>0&&Math.hypot(b.x-p.x,b.y-p.y)<300)){b.l=0;parryHit(b.x,b.y);if(b.o&&!b.o.dead){const dx=b.o.x-p.x,dy=b.o.y-p.y,dd=Math.hypot(dx,dy)||1;pr.push({x:p.x,y:p.y,vx:dx/dd*900,vy:dy/dd*900,l:2.5,bm:1,bd:b.o.t.boss?14:30,home:b.o,rfl:1})}}
else if(Math.hypot(b.x-p.x,b.y-p.y)<(rk?24:18)){b.l=0;if(rk){rg.push({x:b.x,y:b.y,r:10,l:.5});burst(b.x,b.y,'#ff8a3d',14);shake=Math.max(shake,10)}else burst(b.x,b.y,'#ff5a1f',6);if(p.inv<=0)hurt(rk?14:8,b.vx/sv,b.vy/sv)}}
ep=ep.filter(b=>b.l>0&&b.x>-60&&b.x<W+60&&b.y>-60&&b.y<H+60);
for(const b of pr){b.x+=b.vx*dt;b.y+=b.vy*dt;b.l-=dt;if(b.home&&!b.home.dead){const dx=b.home.x-b.x,dy=b.home.y-b.y,dd=Math.hypot(dx,dy)||1,sp=Math.hypot(b.vx,b.vy);b.vx+=(dx/dd*sp-b.vx)*Math.min(1,dt*8);b.vy+=(dy/dd*sp-b.vy)*Math.min(1,dt*8)}
if(lv&&lvCell(b.x,b.y)===1){b.l=0;continue}for(const e of en){if(e.dead||e.down>0||(b.hs&&b.hs.includes(e)))continue;if(Math.hypot(e.x-b.x,e.y-b.y)<e.t.r+12){if(b.bm){boom(b);b.l=0;break}const d=Math.hypot(b.vx,b.vy);dmg(e,(b.dm||2)+L.dmg+(SK[skin].db||0),b.vx/d,b.vy/d,e.t.boss?100:350);if(b.p>0){b.p--;(b.hs=b.hs||[]).push(e)}else{b.l=0;break}}}}
pr=pr.filter(b=>b.l>0&&b.x>-40&&b.x<W+40&&b.y>-40&&b.y<H+40);
en=en.filter(e=>!e.dead);
if(q.length&&(sq-=dt)<=0){spawn(q.shift());sq=Math.max(.35,.9-wave*.03)}
if(lv&&lv.nf&&lv.n0>0&&!en.some(e=>!e.t.flee)){over(true)}
if(!lv&&!q.length&&!en.some(e=>!e.t.flee)){en=[];p.hp=Math.min(p.mh,p.hp+15);nextWave()}
$('spc').className='b'+(p.m>=100?' rdy':'');
}
for(const s of ps){s.x+=s.vx*dt;s.y+=s.vy*dt;s.vx*=.96;s.vy*=.96;s.l-=dt*1.6}
ps=ps.filter(s=>s.l>0);
for(const t of tx){t.y-=40*dt;t.l-=dt*.9}tx=tx.filter(t=>t.l>0);
for(const r of rg){r.r+=700*dt;r.l-=dt*2}rg=rg.filter(r=>r.l>0);
shake=Math.max(0,shake-dt*45);flash=Math.max(0,flash-dt*2.5);banner=Math.max(0,banner-dt);mbn=Math.max(0,mbn-dt);
x.save();
if(shake>0)x.translate((Math.random()-.5)*shake,(Math.random()-.5)*shake);
for(let j=0;j*48<H+48;j++)for(let i=0;i*48<W+48;i++){x.fillStyle=(i+j)%2?'#161b2b':'#12172a';x.fillRect(i*48,j*48,48,48);if((i*7+j*13)%5==0){x.fillStyle='#1f2640';x.fillRect(i*48+18,j*48+18,6,6)}}
if(p){
if(lv)drawLevel();
for(const r of rg){x.strokeStyle='rgba(245,158,11,'+r.l+')';x.lineWidth=12;x.beginPath();x.arc(r.x,r.y,r.r,0,7);x.stroke()}
if(mb){const bb=Math.round(Math.sin(last/200))*S,cx=sn(mb.x),cy=sn(mb.y);
x.fillStyle='rgba(0,0,0,.35)';x.fillRect(cx-30,cy+30,60,9);bAura(cx,cy);x.drawImage(SBS[bs][0],cx-24,cy-24+bb,48,48);bDeco(BS[bs],cx,cy+bb);drawBaz(cx+2,cy+10+bb,-.5);
x.fillStyle='#8a8f9c';for(let i=0;i<5;i++)x.fillRect(cx-27+i*13,cy-30,4,57);
x.fillStyle='#5b6070';x.fillRect(cx-30,cy-33,60,6);x.fillRect(cx-30,cy+24,60,6);x.strokeStyle='#0b0b12';x.lineWidth=3;x.strokeRect(cx-30,cy-33,60,63);
if((last/400|0)%2){x.fillStyle='#ffd166';x.font='bold 21px "Courier New",monospace';x.textAlign='center';x.fillText('СПАСИ!',cx,cy-42)}
if(mb.pr>0){x.strokeStyle='#7CFC9A';x.lineWidth=9;x.beginPath();x.arc(mb.x,mb.y,46,-1.5708,-1.5708+6.2832*mb.pr);x.stroke()}
else{x.strokeStyle='rgba(255,255,255,.25)';x.lineWidth=3;x.beginPath();x.arc(mb.x,mb.y,66,0,7);x.stroke()}}
if(gn){const gx2=sn(gn.x-27),gy2=sn(gn.y-27)+Math.round(Math.sin(last/200))*S;tileArt(x,14,gx2,gy2,54,54,last,0);x.strokeStyle='#ffd23f';x.lineWidth=3;x.strokeRect(gx2,gy2,54,54);if((last/400|0)%2){x.fillStyle='#ffd166';x.font='bold 21px "Courier New",monospace';x.textAlign='center';x.fillText('ЗАВЕДИ!',gn.x,gn.y-38)}}
for(const e of en.slice().sort((a,b)=>a.y-b.y))drawE(e);
for(const s of ps){x.globalAlpha=Math.max(0,s.l);x.fillStyle=s.c;x.fillRect(s.x,s.y,s.z,s.z)}
if(hm){x.save();x.translate(sn(hm.x),sn(hm.y));x.rotate(hm.rot);x.scale(RM(),RM());drawHam(SK[skin],-72);x.restore()}
for(const b of ep){x.save();x.translate(sn(b.x),sn(b.y));if(b.k=='rk'){x.rotate(Math.atan2(b.vy,b.vx));x.fillStyle='#0b0b12';x.fillRect(-16,-7,32,14);x.fillStyle='#b8bcc6';x.fillRect(-14,-5,20,10);x.fillStyle='#e5383b';x.fillRect(6,-5,8,10);x.fillStyle='#ffb703';x.fillRect(-26,-4,10+(Math.random()*6|0),8)}else{x.fillStyle='#0b0b12';x.fillRect(-11,-11,22,22);x.fillStyle='#ff5a1f';x.fillRect(-9,-9,18,18);x.fillStyle='#ffd23f';x.fillRect(-4,-4,8,8)}x.restore()}
for(const b of pr){x.save();x.translate(sn(b.x),sn(b.y));if(b.rfl){x.rotate(b.l*20);x.fillStyle='#0b0b12';x.fillRect(-14,-14,28,28);x.fillStyle='#7fe7ff';x.fillRect(-11,-11,22,22);x.fillStyle='#fff';x.fillRect(-5,-5,10,10);x.restore();continue}if(b.bm){x.rotate(b.l*12);x.fillStyle='#0b0b12';x.fillRect(-13,-13,26,26);x.fillStyle='#7c3aed';x.fillRect(-10,-10,20,20);x.fillStyle='#7CFC9A';x.fillRect(-6,-6,12,12);x.fillStyle='#fff';x.fillRect(-2,-2,4,4);x.restore();continue}if(b.vk){x.fillStyle='#0b0b12';x.fillRect(-16,-13,32,26);x.fillStyle='#0077ff';x.fillRect(-13,-10,26,20);x.fillStyle='#fff';VKF.forEach((L2,i)=>L2.forEach((row,j)=>[...row].forEach((v,k)=>{if(v=='1')x.fillRect(-10+i*11+k*3,-8+j*3,3,3)})));x.restore();continue}x.rotate(b.l*20);x.fillStyle='#ffb703';x.fillRect(-12,-6,24,12);x.fillStyle='#d97706';x.fillRect(-12,-6,24,4);x.strokeStyle='#0b0b12';x.lineWidth=3;x.strokeRect(-12,-6,24,12);x.restore()}
hl.forEach(h=>{if(oh[0]&&ha[0])x.drawImage(SCH[0],0,0,8,8,sn(h.x-12),sn(h.y-12)+Math.round(Math.sin(h.ph*3))*S,24,24)});
if(gz){if(gz.l>0){x.strokeStyle='#7fe7ff';x.lineWidth=6;x.beginPath();x.moveTo(gz.x,gz.y);x.lineTo(gz.tx,gz.ty);x.stroke()}x.drawImage(SGZ[0],0,0,8,8,sn(gz.x-12),sn(gz.y-12),24,24)}
for(const c of ck){const j=Math.round(Math.sin(c.ph))*S;x.drawImage(SCK[bs][0],0,0,8,8,sn(c.x-12),sn(c.y-12)+j,24,24)}
if(bd&&bd.ls>0){const al=Math.min(1,bd.ls/.3),ex1=bd.x-9+Math.cos(bd.a)*460,ey1=bd.y-9+Math.sin(bd.a)*460,ex2=bd.x+9+Math.cos(bd.a)*460,ey2=bd.y-9+Math.sin(bd.a)*460;
x.save();x.shadowColor='#ff2d2d';x.shadowBlur=10;x.globalAlpha=al;x.strokeStyle='#ff2d2d';x.lineWidth=15;x.beginPath();x.moveTo(bd.x-9,bd.y-9);x.lineTo(ex1,ey1);x.moveTo(bd.x+9,bd.y-9);x.lineTo(ex2,ey2);x.stroke();
x.shadowBlur=0;x.strokeStyle='#fff';x.lineWidth=5;x.beginPath();x.moveTo(bd.x-9,bd.y-9);x.lineTo(ex1,ey1);x.moveTo(bd.x+9,bd.y-9);x.lineTo(ex2,ey2);x.stroke();x.restore()}
if(bd){bAura(bd.x,bd.y);x.drawImage(SBS[bs][0],sn(bd.x-24),sn(bd.y-24)+Math.round(Math.sin(last/120))*S,48,48);bDeco(BS[bs],sn(bd.x),sn(bd.y)+Math.round(Math.sin(last/120))*S);drawBaz(bd.x,bd.y+6,bd.a)}
if(p.up>0){const q4=p.up/1.2;x.strokeStyle='rgba(77,195,255,'+Math.min(1,q4+.2)+')';x.lineWidth=14;x.beginPath();x.arc(p.x,p.y,60+(1-q4)*260,0,7);x.stroke()}
if(p.pr>0){const q3=p.pr/(ukA()?.2:.14);x.strokeStyle='rgba(127,231,255,'+Math.min(1,q3+.3)+')';x.lineWidth=12;x.beginPath();x.arc(p.x,p.y,40+(1-q3)*34,0,7);x.stroke()}
if(p.dash&&p.dash.tg&&!p.dash.tg.dead){x.strokeStyle='#4dc3ff';x.lineWidth=6;x.beginPath();x.moveTo(p.x,p.y);x.lineTo(p.dash.tg.x,p.dash.tg.y);x.stroke()}
x.globalAlpha=1;drawP();
x.font='bold 21px "Courier New",monospace';x.textAlign='center';
for(const t of tx){x.globalAlpha=Math.max(0,t.l);x.fillStyle=t.c;x.fillText(t.s,Math.min(W-90,Math.max(90,t.x)),t.y)}
x.globalAlpha=1;
if(joy){x.strokeStyle='#fff5';x.lineWidth=3;x.beginPath();x.arc(joy.ox,joy.oy,50,0,7);x.stroke();
const a=Math.atan2(joy.cy-joy.oy,joy.cx-joy.ox),l=Math.min(50,Math.hypot(joy.cx-joy.ox,joy.cy-joy.oy));
x.fillStyle='#fff6';x.beginPath();x.arc(joy.ox+Math.cos(a)*l,joy.oy+Math.sin(a)*l,22,0,7);x.fill()}
objArrow();
if(aim){x.strokeStyle='rgba(229,56,59,.7)';x.lineWidth=3;x.beginPath();x.arc(aim.ox,aim.oy,50,0,7);x.stroke();const l=Math.min(50,aim.len),a=aim.a;x.fillStyle='rgba(229,56,59,.6)';x.beginPath();x.arc(aim.ox+Math.cos(a)*l,aim.oy+Math.sin(a)*l,22,0,7);x.fill();if(aimOn()){x.strokeStyle='rgba(229,56,59,.55)';x.lineWidth=6;x.beginPath();x.moveTo(p.x,p.y);x.lineTo(p.x+Math.cos(a)*150,p.y+Math.sin(a)*150);x.stroke()}}
const T=44;x.textAlign='left';
x.fillStyle='#0008';x.fillRect(14,T,160,14);x.fillStyle=p.hp>p.mh*.3?'#3ddc84':'#e5383b';x.fillRect(14,T,160*Math.max(0,p.hp)/p.mh,14);
x.fillStyle='#0008';x.fillRect(14,T+18,160,8);x.fillStyle='#f59e0b';x.fillRect(14,T+18,160*p.m/100,8);x.fillStyle='#0008';x.fillRect(14,T+30,160,6);x.fillStyle='#a855f7';x.fillRect(14,T+30,160*p.ul/100,6);
x.fillStyle='#ffd166';x.font='bold 21px "Courier New",monospace';x.textAlign='left';x.fillText('$'+fmt(coins),14,T+52);
if(lv){let gt=0,gd=0,pt=0,pd=0,dr=0;lv.g.forEach((t,k)=>{if(t===14){gt++;if(lv.done[k])gd++}if(t===15){pt++;if(lv.done[k])pd++}if(t===16)dr=1});
x.fillStyle='#ffd23f';if(gt||pt)x.fillText((gt?'ГЕН '+gd+'/'+gt+' ':'')+(pt?'ЩИТ '+pd+'/'+pt:''),14,T+76);
if(dr){x.fillStyle=lv.open?'#7CFC9A':'#ff9b9b';x.fillText(lv.open?'ДВЕРЬ ОТКРЫТА':'ДВЕРЬ ЗАКРЫТА',14,T+100)}}
if(pw>0){x.fillStyle='#ffd23f';x.fillText('ЭНЕРГИЯ '+Math.ceil(pw)+'с',14,T+(lv?124:76))}x.fillStyle='#fff';x.textAlign='right';
x.fillText('Очки:'+score,W-14,T+16);x.fillText('Волна '+wave,W-14,T+40);
if(combo>1){x.fillStyle='#ffd166';x.fillText('Комбо ×'+Math.min(5,1+(combo/3|0)),W-14,T+64)}
if(banner>0&&run){x.globalAlpha=Math.min(1,banner);x.fillStyle='#e5383b';x.font='bold '+Math.max(21,Math.min(45,Math.floor((W-20)/(bt.length*.6)/3)*3))+'px "Courier New",monospace';x.textAlign='center';x.fillText(bt,W/2,H*.3);x.globalAlpha=1}
if(mbn>0&&run){const m='СПАСИ МАМУ-ПТИЦУ!';x.globalAlpha=Math.min(1,mbn);x.fillStyle='#ffd166';x.font='bold '+Math.max(21,Math.min(45,Math.floor((W-20)/(m.length*.6)/3)*3))+'px "Courier New",monospace';x.textAlign='center';x.fillText(m,W/2,H*.42);x.globalAlpha=1}
}
if(flash>0){x.fillStyle='rgba(229,56,59,'+flash*.35+')';x.fillRect(-30,-30,W+60,H+60)}
if(pf>0){x.fillStyle='rgba(127,231,255,'+pf*.55+')';x.fillRect(-30,-30,W+60,H+60)}
x.restore();
}
requestAnimationFrame(t=>{last=t;loop(t)});
</script></body></html>Game Source: Молот Роскомнадзора: Драка · АЛЬФА 1.0
Creator: EpicKoala43
Libraries: none
Complexity: complex (904 lines, 109.2 KB)
The full source code is displayed above on this page.
Remix Instructions
To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: game-epickoala43" to link back to the original. Then publish at arcadelab.ai/publish.