Files
mini-browser-games/comet-weaver.html
2026-07-22 22:26:03 +08:00

109 lines
28 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>彗尾织者:星幕远征</title>
<style>
:root{--ink:#f7f7ee;--muted:#b9c8d3;--panel:#172638;--panel2:#20344a;--line:#506b7e;--cyan:#77e0d4;--gold:#f2c361;--red:#ed6c76;--violet:#c18cf0}
*{box-sizing:border-box}body{margin:0;min-height:100vh;background:radial-gradient(circle at 15% 0,#244b67 0,transparent 32%),radial-gradient(circle at 88% 8%,#50385e 0,transparent 30%),linear-gradient(145deg,#09131e,#101f31 62%,#111522);color:var(--ink);font-family:system-ui,"Microsoft YaHei",sans-serif}.app{width:min(1450px,calc(100% - 22px));margin:11px auto}.top,.panel{border:1px solid var(--line);border-radius:15px;background:rgba(23,38,56,.96);box-shadow:0 18px 48px rgba(0,0,0,.35)}.top{display:flex;align-items:center;justify-content:space-between;gap:15px;padding:15px 18px}.eyebrow{margin:0 0 4px;color:var(--cyan);font-size:12px;font-weight:950;letter-spacing:.15em}.top h1{margin:0;font-size:clamp(26px,4vw,43px);line-height:1}.sub{margin:7px 0 0;color:var(--muted);font-size:13px}.actions,.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}button,textarea{font:inherit}.btn{min-height:42px;padding:0 13px;border:1px solid #607f91;border-radius:9px;background:#2e5f70;color:white;font-weight:900;cursor:pointer}.btn.gold{border-color:#9b7632;background:#79551d}.btn.red{border-color:#9d4550;background:#843642}.btn.ghost{background:#273a51}.btn:disabled{opacity:.45;filter:saturate(.3);cursor:not-allowed}.layout{display:grid;grid-template-columns:minmax(0,1fr) 360px;gap:12px;margin-top:12px;align-items:start}.stage{position:relative;overflow:hidden;min-height:650px}.stage canvas{display:block;width:100%;height:650px;touch-action:none}.side{padding:12px;display:grid;gap:10px;max-height:calc(100vh - 105px);overflow:auto}.hud{position:absolute;left:10px;right:10px;top:10px;display:grid;grid-template-columns:repeat(6,1fr);gap:6px;pointer-events:none}.stat{padding:7px 8px;border:1px solid rgba(255,255,255,.28);border-radius:8px;background:rgba(5,16,27,.78);text-shadow:0 1px #000}.stat b{display:block;font-size:19px}.stat small{color:#c7d9e2;font-size:10px;font-weight:850}.meters{position:absolute;left:12px;right:12px;bottom:12px;display:grid;grid-template-columns:1.4fr 1fr 1fr;gap:7px;pointer-events:none}.meter{padding:7px;border:1px solid rgba(255,255,255,.28);border-radius:8px;background:rgba(5,16,27,.82);font-size:11px;font-weight:850}.bar{height:9px;margin-top:4px;border-radius:99px;overflow:hidden;background:rgba(255,255,255,.14)}.bar i{display:block;height:100%;background:linear-gradient(90deg,var(--red),var(--gold))}.bar.charge i{background:linear-gradient(90deg,#5fbacb,var(--cyan))}.bar.blink i{background:linear-gradient(90deg,#8d62c9,var(--violet))}.overlay{position:absolute;inset:0;display:grid;place-items:center;padding:20px;background:rgba(4,14,24,.65)}.overlay.hidden{display:none}.dialog{width:min(520px,100%);padding:20px;border:1px solid #718a99;border-radius:14px;background:#172638;box-shadow:0 25px 60px rgba(0,0,0,.42)}.dialog h2{margin:0 0 8px}.dialog p{color:var(--muted);line-height:1.6}.flash{position:absolute;inset:0;background:white;opacity:0;pointer-events:none}.flash.on{animation:flash .35s}@keyframes flash{30%{opacity:.55}100%{opacity:0}}.block{padding:11px;border:1px solid #465f72;border-radius:11px;background:#111e2d}.block h2,.block h3{margin:0 0 8px}.block h2{font-size:20px}.block h3{font-size:14px;color:var(--cyan)}.route{display:grid;grid-template-columns:repeat(4,1fr);gap:5px}.node{min-height:49px;padding:4px;border:1px solid #496276;border-radius:8px;background:#20354a;color:white;cursor:pointer}.node.active{outline:3px solid var(--cyan)}.node:disabled{opacity:.38}.node b{display:block}.stars{color:var(--gold);font-size:10px}.goals{display:grid;gap:6px}.goal{display:flex;justify-content:space-between;padding:7px;border:1px solid #40596c;border-radius:8px;color:var(--muted);font-size:12px}.goal.pass{color:#dffbe8;border-color:#438562;background:#173326}.modules{display:grid;grid-template-columns:1fr 1fr;gap:6px}.module{padding:7px;border:1px solid #496075;border-radius:8px;background:#1c2e42;color:white;text-align:left;cursor:pointer}.module.active{outline:3px solid var(--violet)}.module:disabled{opacity:.4}.module b,.module small{display:block}.module small{min-height:31px;color:var(--muted);font-size:10px;margin-top:3px}.career{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}.career div{padding:7px;border:1px solid #465e72;border-radius:8px;background:#1c2c3e;text-align:center}.career b{display:block;font-size:19px}.career small{font-size:10px;color:var(--muted)}.pad{display:grid;grid-template-columns:repeat(3,58px);gap:6px;justify-content:center}.pad button{width:58px;height:46px;border:1px solid #607789;border-radius:8px;background:#263e55;color:white;font-size:18px;font-weight:900}.pad .blank{visibility:hidden}.tip{margin:7px 0 0;color:var(--muted);font-size:12px;line-height:1.5}.archive{position:fixed;inset:0;z-index:7;display:grid;place-items:center;padding:18px;background:rgba(2,10,18,.82)}.archive.hidden{display:none}.archive .dialog{width:min(610px,100%)}textarea{width:100%;min-height:125px;padding:10px;border:1px solid #60798c;border-radius:8px;background:#0c1723;color:white;resize:vertical}.feedback{min-height:20px;margin-top:7px;color:var(--gold);font-size:12px;font-weight:850}
@media(max-width:1000px){.layout{grid-template-columns:1fr}.side{max-height:none;grid-template-columns:repeat(2,minmax(0,1fr))}.side .wide{grid-column:1/-1}.stage,.stage canvas{height:590px;min-height:590px}}
@media(max-width:650px){.app{width:min(100% - 10px,1450px);margin:5px auto}.top{display:block;padding:12px}.actions{margin-top:11px}.actions .btn{flex:1}.stage,.stage canvas{height:550px;min-height:550px}.hud{grid-template-columns:repeat(3,1fr)}.meters{grid-template-columns:1fr;gap:4px}.side{grid-template-columns:1fr}.side .wide{grid-column:auto}.sub{line-height:1.45}}
</style>
</head>
<body>
<main class="app">
<header class="top"><div><p class="eyebrow">COMET VEIL EXPEDITION V2</p><h1>彗尾织者</h1><p class="sub">十二幕可学习弹幕、擦弹充能与双槽星械。闪现穿幕,满能量释放彗核冲击。</p></div><div class="actions"><button class="btn" id="startBtn">开始穿梭</button><button class="btn gold" id="novaBtn">彗核冲击</button><button class="btn red" id="blinkBtn">相位闪现</button><button class="btn ghost" id="archiveBtn">远征档案</button></div></header>
<section class="layout">
<div class="panel stage"><canvas id="gameCanvas" aria-label="彗尾织者星幕远征画面"></canvas>
<div class="hud"><div class="stat"><b id="timeText">0:00</b><small>用时</small></div><div class="stat"><b id="bossText">100%</b><small>星幕核心</small></div><div class="stat"><b id="shieldText">3</b><small>护盾</small></div><div class="stat"><b id="grazeText">0</b><small>擦弹</small></div><div class="stat"><b id="scoreText">0</b><small>分数</small></div><div class="stat"><b id="patternText">待机</b><small>弹幕预告</small></div></div>
<div class="meters"><div class="meter">核心耐久<div class="bar"><i id="bossBar"></i></div></div><div class="meter">彗能 <span id="chargeText">0%</span><div class="bar charge"><i id="chargeBar"></i></div></div><div class="meter">相位 <span id="blinkText">就绪</span><div class="bar blink"><i id="blinkBar"></i></div></div></div>
<div class="flash" id="flash"></div><div class="overlay" id="overlay"><div class="dialog"><h2 id="overlayTitle">选择星幕</h2><p id="overlayBody">擦过弹幕外缘会积攒彗能;满能量释放冲击可清弹并重创核心。相位闪现沿当前移动方向穿越危险区。</p><button class="btn" id="overlayBtn">开始穿梭</button></div></div>
</div>
<aside class="panel side">
<section class="block wide"><h3 id="chapterText">第一章</h3><h2 id="stageName"></h2><div class="tip" id="stageBrief"></div><div class="goals" id="goals"></div></section>
<section class="block wide"><h3>十二幕航线</h3><div class="route" id="route"></div></section>
<section class="block"><h3>远征记录</h3><div class="career"><div><b id="careerStars">0</b><small>星章</small></div><div><b id="careerWins">0</b><small>通关</small></div><div><b id="bestGraze">0</b><small>最高擦弹</small></div></div></section>
<section class="block"><h3>触屏操纵</h3><div class="pad"><button class="blank"></button><button data-dir="up">↑</button><button class="blank"></button><button data-dir="left">←</button><button data-dir="down">↓</button><button data-dir="right">→</button></div><p class="tip">WASD / 方向键或拖动画面移动;Space 闪现,Q 释放彗核冲击。</p></section>
<section class="block wide"><h3>双槽星械 <span id="slotText"></span></h3><div class="modules" id="modules"></div></section>
</aside>
</section>
</main>
<div class="archive hidden" id="archiveModal"><div class="dialog"><h2>跨设备远征档案</h2><p class="tip">档案包含星幕星级、已解锁节点、星械配置、通关次数和最高擦弹。</p><textarea id="archiveText" spellcheck="false"></textarea><div class="row" style="justify-content:flex-end"><button class="btn ghost" id="closeArchiveBtn">关闭</button><button class="btn" id="importBtn">导入</button><button class="btn gold" id="exportBtn">生成并复制</button></div><div class="feedback" id="archiveFeedback"></div></div></div>
<script>
(() => {
"use strict";
const KEY="miniCometWeaverV2",$=id=>document.getElementById(id),canvas=$("gameCanvas"),ctx=canvas.getContext("2d");
const STAGES=[
{chapter:"第一章 · 近星层",name:"环雨初航",brief:"规律圆环从核心向外扩散,寻找环与环之间的呼吸间隙。",patterns:["ring","aim"],hp:150,graze:14,par:34,rate:1},
{chapter:"第一章 · 近星层",name:"扇面追光",brief:"扇形弹幕锁定发射瞬间的位置,持续侧移比慌乱折返更安全。",patterns:["fan","aim"],hp:170,graze:18,par:36,rate:1.05},
{chapter:"第一章 · 近星层",name:"裂隙车道",brief:"平行弹墙留下会移动的缺口,预判下一条安全车道。",patterns:["lanes","ring"],hp:190,graze:20,par:38,rate:1.08},
{chapter:"第一章 · 近星层",name:"双旋风眼",brief:"顺逆两股螺旋交替出现,贴近弹流内缘可以快速充能。",patterns:["spiral","ring"],hp:215,graze:24,par:40,rate:1.12},
{chapter:"第二章 · 彗尾带",name:"折返彗片",brief:"彗片越过左界后会折返一次,不要把退路留在身后。",patterns:["return","fan"],hp:235,graze:27,par:42,rate:1.15},
{chapter:"第二章 · 彗尾带",name:"引力花冠",brief:"花瓣弹会缓慢弯向你,短促换向比长距离逃离更有效。",patterns:["curve","ring"],hp:255,graze:30,par:44,rate:1.18},
{chapter:"第二章 · 彗尾带",name:"交叉星桥",brief:"横纵弹列同时切割战场,用闪现跨越交叉封锁。",patterns:["cross","lanes"],hp:280,graze:32,par:46,rate:1.22},
{chapter:"第二章 · 彗尾带",name:"镜像猎手",brief:"两枚追踪核心从上下夹击,先诱导再穿过中线。",patterns:["hunters","fan"],hp:305,graze:35,par:48,rate:1.26},
{chapter:"第三章 · 星幕心",name:"脉冲王冠",brief:"快慢圆环交错形成假缺口,观察颜色分辨速度。",patterns:["crown","aim"],hp:330,graze:38,par:50,rate:1.3},
{chapter:"第三章 · 星幕心",name:"坠星瀑布",brief:"上方弹雨与核心扇面叠加,横向移动必须保留回转空间。",patterns:["rain","fan"],hp:355,graze:42,par:52,rate:1.34},
{chapter:"第三章 · 星幕心",name:"静默迷宫",brief:"弹墙逐段闭合,预告线消失后仍要记住安全入口。",patterns:["maze","spiral"],hp:380,graze:46,par:54,rate:1.38},
{chapter:"第三章 · 星幕心",name:"终焉织机",brief:"所有弹幕规则轮转登场;主动擦弹、清屏与闪现缺一不可。",patterns:["ring","fan","lanes","spiral","return","cross","rain"],hp:430,graze:55,par:58,rate:1.44}
];
const MODULES=[
{name:"宽域感应",need:0,desc:"擦弹半径 +7,彗能获取 +20%",key:"graze"},{name:"聚焦棱镜",need:3,desc:"自动织光伤害 +22%",key:"damage"},
{name:"双相电容",need:7,desc:"彗核冲击所需能量 -18",key:"charge"},{name:"余烬回收",need:12,desc:"受击后立刻获得 32 彗能",key:"recycle"},
{name:"相位余量",need:18,desc:"闪现冷却 -1.3 秒",key:"blink"},{name:"星壳阵列",need:25,desc:"每幕额外 1 层护盾",key:"shield"}
];
const PATTERN_NAMES={ring:"扩散圆环",aim:"三连狙击",fan:"追光扇面",lanes:"裂隙车道",spiral:"双旋风眼",return:"折返彗片",curve:"引力花冠",cross:"交叉星桥",hunters:"镜像猎手",crown:"脉冲王冠",rain:"坠星瀑布",maze:"静默迷宫"};
let career=load(),selected=Math.min(career.unlocked,11),state=makeState(),w=900,h=650,dpr=1,last=0,token=0,keys=new Set(),pointer=null;
function defaults(){return {v:2,unlocked:0,stars:Array(12).fill(0),bestGraze:0,wins:0,equipped:[0]};}
function load(){try{const v=JSON.parse(localStorage.getItem(KEY)||"null");if(v&&v.v===2)return Object.assign(defaults(),v,{stars:Array.from({length:12},(_,i)=>v.stars?.[i]||0),equipped:Array.isArray(v.equipped)?v.equipped.filter(i=>Number.isInteger(i)&&i>=0&&i<MODULES.length).slice(0,2):[0]});}catch(_){}return defaults();}
function save(){localStorage.setItem(KEY,JSON.stringify(career));}
function totalStars(){return career.stars.reduce((a,b)=>a+b,0);}function has(key){return career.equipped.some(i=>MODULES[i]?.key===key);}
function makeState(){const stage=STAGES[selected]||STAGES[0],maxCharge=has?.("charge")?82:100;return {mode:"menu",time:0,boss:stage.hp,maxBoss:stage.hp,shield:3+(has?.("shield")?1:0),graze:0,hits:0,score:0,charge:0,maxCharge,player:{x:150,y:325,vx:0,vy:0,inv:0,blink:0},bullets:[],shots:[],particles:[],nextShot:0,nextPattern:.8,patternIndex:0,current:"待机",seed:0x9e3779b9+selected*7919};}
function random(){state.seed^=state.seed<<13;state.seed^=state.seed>>>17;state.seed^=state.seed<<5;return (state.seed>>>0)/4294967296;}
function clamp(v,a,b){return Math.max(a,Math.min(b,v));}function resize(){const r=canvas.getBoundingClientRect();w=Math.max(320,r.width);h=Math.max(520,r.height);dpr=Math.max(1,Math.min(2,devicePixelRatio||1));canvas.width=Math.floor(w*dpr);canvas.height=Math.floor(h*dpr);ctx.setTransform(dpr,0,0,dpr,0,0);draw();}
function selectStage(i){if(i>career.unlocked||state.mode==="running")return;selected=i;state=makeState();overlayTitle.textContent=`${i+1}. ${STAGES[i].name}`;overlayBody.textContent=`${STAGES[i].brief} 擦弹目标 ${STAGES[i].graze},三星参考 ${STAGES[i].par} 秒内或零受击。`;overlayBtn.textContent="开始穿梭";overlay.classList.remove("hidden");renderSide();updateHud();draw();}
function start(){token++;state=makeState();state.mode="running";state.player.x=w*.18;state.player.y=h*.52;overlay.classList.add("hidden");last=performance.now();renderSide();updateHud();requestAnimationFrame(t=>loop(t,token));}
function input(){let x=0,y=0;if(keys.has("ArrowLeft")||keys.has("KeyA"))x--;if(keys.has("ArrowRight")||keys.has("KeyD"))x++;if(keys.has("ArrowUp")||keys.has("KeyW"))y--;if(keys.has("ArrowDown")||keys.has("KeyS"))y++;if(pointer){x=(pointer.x-state.player.x)/70;y=(pointer.y-state.player.y)/70;}const n=Math.hypot(x,y)||1;return {x:x/n,y:y/n,on:Math.hypot(x,y)>.05};}
function add(x,y,vx,vy,r,color,type="normal",extra={}){state.bullets.push({x,y,vx,vy,r,color,type,grazed:false,age:0,...extra});}
function aimed(x,y,speed,spread=0){const a=Math.atan2(state.player.y-y,state.player.x-x)+spread;add(x,y,Math.cos(a)*speed,Math.sin(a)*speed,6,"#ee7180");}
function spawnPattern(){const st=STAGES[selected],type=st.patterns[state.patternIndex++%st.patterns.length],bx=w-105,by=h*.5+Math.sin(state.time*.8)*h*.22,s=st.rate;state.current=PATTERN_NAMES[type];
if(type==="ring"||type==="crown"){const rings=type==="crown"?2:1;for(let k=0;k<rings;k++)for(let i=0;i<18+k*4;i++){const a=i/(18+k*4)*Math.PI*2+state.time*.5+k*.12,sp=(95+k*48)*s;add(bx,by,Math.cos(a)*sp,Math.sin(a)*sp,6+k,"#f1c467");}}
else if(type==="aim"){for(let k=-1;k<=1;k++)aimed(bx,by,170*s,k*.1);}
else if(type==="fan"){const base=Math.atan2(state.player.y-by,state.player.x-bx);for(let k=-5;k<=5;k++){const a=base+k*.105;add(bx,by,Math.cos(a)*155*s,Math.sin(a)*155*s,6,"#ee7180");}}
else if(type==="lanes"||type==="maze"){const gap=(state.patternIndex*2)%7;for(let row=0;row<9;row++)if(Math.abs(row-gap)>1)add(w+10,95+row*(h-150)/8,-175*s,0,8,type==="maze"?"#c18cf0":"#75dcca");}
else if(type==="spiral"){for(let i=0;i<13;i++){const a=state.time*1.8+i/13*Math.PI*2,sp=120*s;add(bx,by,Math.cos(a)*sp,Math.sin(a)*sp,6,"#c18cf0");}}
else if(type==="return"){for(let i=0;i<10;i++)add(w+10,70+i*(h-120)/9,-170*s,(random()-.5)*35,7,"#73d4d0","return");}
else if(type==="curve"){for(let i=0;i<14;i++){const a=i/14*Math.PI*2;add(bx,by,Math.cos(a)*115*s,Math.sin(a)*115*s,7,"#e5a1ef","curve",{turn:(i%2?1:-1)*.55});}}
else if(type==="cross"){for(let i=0;i<8;i++){add(w+10,110+i*(h-180)/7,-180*s,0,7,"#7ee0d1");add(120+i*(w-220)/7,-10,0,155*s,7,"#f0bf65");}}
else if(type==="hunters"){add(w-80,80,-80*s,35*s,12,"#f28b79","hunter");add(w-80,h-80,-80*s,-35*s,12,"#f28b79","hunter");}
else if(type==="rain"){for(let i=0;i<14;i++)add(40+i*(w-80)/13,-10,(random()-.5)*30,140*s+random()*70,7,"#79cfea");}
state.nextPattern=state.time+Math.max(.42,1.05/st.rate);}
function blink(){if(state.mode!=="running"||state.player.blink>0)return;const d=input(),dx=d.on?d.x:1,dy=d.on?d.y:0;state.player.x=clamp(state.player.x+dx*105,20,w-20);state.player.y=clamp(state.player.y+dy*105,20,h-20);state.player.inv=.7;state.player.blink=4.3-(has("blink")?1.3:0);pop(state.player.x,state.player.y,"相位","#aeeeff");}
function nova(){if(state.mode!=="running"||state.charge<state.maxCharge)return;state.charge=0;state.boss=Math.max(0,state.boss-state.maxBoss*.18);const cleared=state.bullets.length;state.score+=cleared*12;state.bullets=[];flash.classList.remove("on");void flash.offsetWidth;flash.classList.add("on");pop(state.player.x,state.player.y,`清除 ${cleared}`,"#fff3a4");}
function finish(win){if(state.mode!=="running")return;state.mode="over";token++;let stars=0;if(win){stars=1;if(state.graze>=STAGES[selected].graze){stars=2;if(state.hits===0||state.time<=STAGES[selected].par)stars=3;}career.stars[selected]=Math.max(career.stars[selected],stars);career.unlocked=Math.max(career.unlocked,Math.min(11,selected+1));career.bestGraze=Math.max(career.bestGraze,state.graze);career.wins++;save();}overlayTitle.textContent=win?`${'★'.repeat(stars)} 星幕击穿`:"星梭失联";overlayBody.innerHTML=`用时 ${state.time.toFixed(1)} 秒,擦弹 ${state.graze},受击 ${state.hits}。${win&&selected<11?'下一幕已经解锁。':''}`;overlayBtn.textContent="再次穿梭";overlay.classList.remove("hidden");renderSide();updateHud();}
function update(dt){const st=STAGES[selected],p=state.player,d=input();state.time+=dt;state.score+=Math.floor(dt*20);state.boss=Math.max(0,state.boss-dt*(st.hp/st.par*.78)*(has("damage")?1.22:1));if(state.boss<=0)return finish(true);if(d.on){p.vx+=d.x*680*dt;p.vy+=d.y*680*dt;}p.vx*=Math.pow(.045,dt);p.vy*=Math.pow(.045,dt);p.x=clamp(p.x+p.vx*dt,18,w-18);p.y=clamp(p.y+p.vy*dt,18,h-18);p.inv=Math.max(0,p.inv-dt);p.blink=Math.max(0,p.blink-dt);if(state.time>=state.nextPattern)spawnPattern();
if(state.time>=state.nextShot){state.shots.push({x:p.x+12,y:p.y,vx:520});state.nextShot=state.time+.15;}for(let i=state.shots.length-1;i>=0;i--){const shot=state.shots[i];shot.x+=shot.vx*dt;if(shot.x>w-135){state.boss=Math.max(0,state.boss-.16);state.shots.splice(i,1);}}
for(let i=state.bullets.length-1;i>=0;i--){const b=state.bullets[i];b.age+=dt;if(b.type==="curve"){const cs=Math.cos(b.turn*dt),sn=Math.sin(b.turn*dt),vx=b.vx*cs-b.vy*sn;b.vy=b.vx*sn+b.vy*cs;b.vx=vx;}if(b.type==="hunter"&&b.age<4){const a=Math.atan2(p.y-b.y,p.x-b.x);b.vx+=Math.cos(a)*20*dt;b.vy+=Math.sin(a)*20*dt;}b.x+=b.vx*dt;b.y+=b.vy*dt;if(b.type==="return"&&b.x<-15&&!b.returned){b.returned=true;b.vx=Math.abs(b.vx)*.82;}if(b.x<-50||b.x>w+50||b.y<-50||b.y>h+50){state.bullets.splice(i,1);continue;}const dist=Math.hypot(b.x-p.x,b.y-p.y),grazeRadius=31+(has("graze")?7:0);if(dist<b.r+8&&p.inv<=0){state.bullets.splice(i,1);state.shield--;state.hits++;p.inv=1.05;if(has("recycle"))state.charge=Math.min(state.maxCharge,state.charge+32);pop(p.x,p.y,"护盾受击","#ff8791");if(state.shield<=0)return finish(false);}else if(!b.grazed&&dist<b.r+grazeRadius){b.grazed=true;state.graze++;state.score+=45;state.charge=Math.min(state.maxCharge,state.charge+5*(has("graze")?1.2:1));pop(b.x,b.y,"擦","#f6d36f");}}
state.particles=state.particles.filter(x=>(x.y-=dt*34,x.life-=dt*.85,x.life>0));updateHud();}
function loop(now,id){if(id!==token||state.mode!=="running")return;const dt=Math.min(.045,(now-last)/1000||.016);last=now;update(dt);draw();if(state.mode==="running")requestAnimationFrame(t=>loop(t,id));}
function pop(x,y,text,color){state.particles.push({x,y,text,color,life:1});}
function draw(){const grad=ctx.createLinearGradient(0,0,0,h);grad.addColorStop(0,"#0b1726");grad.addColorStop(1,selected>7?"#352143":"#173450");ctx.fillStyle=grad;ctx.fillRect(0,0,w,h);ctx.fillStyle="rgba(255,255,255,.18)";for(let i=0;i<85;i++){const x=(i*97+state.time*22)%w,y=(i*53+selected*11)%h;ctx.fillRect(x,y,i%7?1.5:2.5,i%7?1.5:2.5);}const bx=w-105,by=h*.5+Math.sin(state.time*.8)*h*.22;ctx.fillStyle="#3c4d64";ctx.beginPath();ctx.arc(bx,by,43,0,Math.PI*2);ctx.fill();ctx.strokeStyle="#f0c665";ctx.lineWidth=4;ctx.beginPath();ctx.arc(bx,by,25+Math.sin(state.time*3)*4,0,Math.PI*2);ctx.stroke();for(const s of state.shots){ctx.fillStyle="#8ff1df";ctx.fillRect(s.x,s.y-2,16,4);}for(const b of state.bullets){ctx.fillStyle=b.color;ctx.beginPath();ctx.arc(b.x,b.y,b.r,0,Math.PI*2);ctx.fill();if(b.grazed){ctx.strokeStyle="rgba(255,255,255,.45)";ctx.stroke();}}
const p=state.player;ctx.globalAlpha=p.inv>0?.5:1;ctx.fillStyle="#73e0d2";ctx.beginPath();ctx.moveTo(p.x+14,p.y);ctx.lineTo(p.x-10,p.y-9);ctx.lineTo(p.x-6,p.y);ctx.lineTo(p.x-10,p.y+9);ctx.closePath();ctx.fill();ctx.strokeStyle="white";ctx.lineWidth=2;ctx.stroke();ctx.globalAlpha=1;for(const x of state.particles){ctx.globalAlpha=x.life;ctx.fillStyle=x.color;ctx.font="900 17px system-ui";ctx.textAlign="center";ctx.fillText(x.text,x.x,x.y);ctx.globalAlpha=1;}}
function currentRating(){if(state.mode!=="over"&&state.boss>0)return 0;let s=1;if(state.graze>=STAGES[selected].graze){s=2;if(state.hits===0||state.time<=STAGES[selected].par)s=3;}return s;}
function updateHud(){timeText.textContent=`${Math.floor(state.time/60)}:${String(Math.floor(state.time%60)).padStart(2,'0')}`;bossText.textContent=`${Math.max(0,Math.round(state.boss/state.maxBoss*100))}%`;shieldText.textContent=state.shield;grazeText.textContent=state.graze;scoreText.textContent=state.score;patternText.textContent=state.current;bossBar.style.width=`${Math.max(0,state.boss/state.maxBoss*100)}%`;chargeText.textContent=`${Math.round(state.charge)}/${state.maxCharge}`;chargeBar.style.width=`${state.charge/state.maxCharge*100}%`;blinkText.textContent=state.player.blink>0?`${state.player.blink.toFixed(1)}s`:"就绪";blinkBar.style.width=`${state.player.blink>0?(1-state.player.blink/(4.3-(has("blink")?1.3:0)))*100:100}%`;startBtn.disabled=state.mode==="running";novaBtn.disabled=state.mode!=="running"||state.charge<state.maxCharge;blinkBtn.disabled=state.mode!=="running"||state.player.blink>0;renderGoals();}
function renderGoals(){const st=STAGES[selected],won=state.mode==="over"&&state.boss<=0,items=[["击穿星幕核心",won],[`擦弹 ${st.graze} 次`,state.graze>=st.graze],[`零受击或 ${st.par} 秒内`,state.hits===0||state.time<=st.par]];goals.innerHTML=items.map(([t,p])=>`<div class="goal ${p?'pass':''}"><span>${p?'✓':'○'} ${t}</span><b>${p?'完成':'进行中'}</b></div>`).join('');}
function renderSide(){const st=STAGES[selected];chapterText.textContent=st.chapter;stageName.textContent=`${selected+1}. ${st.name}`;stageBrief.textContent=st.brief;route.innerHTML=STAGES.map((s,i)=>`<button class="node ${i===selected?'active':''}" data-stage="${i}" ${i>career.unlocked||state.mode==='running'?'disabled':''}><b>${i+1}</b><span class="stars">${'★'.repeat(career.stars[i])}${'☆'.repeat(3-career.stars[i])}</span></button>`).join('');route.querySelectorAll('[data-stage]').forEach(b=>b.onclick=()=>selectStage(+b.dataset.stage));careerStars.textContent=totalStars();careerWins.textContent=career.wins;bestGraze.textContent=career.bestGraze;slotText.textContent=`${career.equipped.length}/2`;modules.innerHTML=MODULES.map((m,i)=>`<button class="module ${career.equipped.includes(i)?'active':''}" data-module="${i}" ${totalStars()<m.need||state.mode==='running'?'disabled':''}><b>${m.name}</b><small>${m.desc}</small><span>${totalStars()>=m.need?'点击装配':m.need+' 星解锁'}</span></button>`).join('');modules.querySelectorAll('[data-module]').forEach(b=>b.onclick=()=>toggleModule(+b.dataset.module));renderGoals();}
function toggleModule(i){if(totalStars()<MODULES[i].need||state.mode==="running")return;const at=career.equipped.indexOf(i);if(at>=0)career.equipped.splice(at,1);else{if(career.equipped.length>=2)career.equipped.shift();career.equipped.push(i);}save();state=makeState();renderSide();updateHud();}
function checksum(s){let h=2166136261;for(let i=0;i<s.length;i++){h^=s.charCodeAt(i);h=Math.imul(h,16777619);}return (h>>>0).toString(36).toUpperCase();}
function encode(){const p=btoa(unescape(encodeURIComponent(JSON.stringify({v:2,u:career.unlocked,s:career.stars,g:career.bestGraze,w:career.wins,e:career.equipped}))));return `COMET2.${p}.${checksum(p)}`;}
function decode(code){const p=code.trim().split('.');if(p.length!==3||p[0]!=="COMET2"||checksum(p[1])!==p[2])throw Error('远征档案校验失败');const v=JSON.parse(decodeURIComponent(escape(atob(p[1]))));if(v.v!==2||!Array.isArray(v.s))throw Error('档案版本不兼容');return {v:2,unlocked:clamp(+v.u||0,0,11),stars:Array.from({length:12},(_,i)=>clamp(+v.s[i]||0,0,3)),bestGraze:Math.max(0,+v.g||0),wins:Math.max(0,+v.w||0),equipped:(v.e||[]).filter(i=>Number.isInteger(i)&&i>=0&&i<MODULES.length).slice(0,2)};}
startBtn.onclick=start;overlayBtn.onclick=start;novaBtn.onclick=nova;blinkBtn.onclick=blink;archiveBtn.onclick=()=>{archiveModal.classList.remove('hidden');archiveText.value=encode();archiveFeedback.textContent='';};closeArchiveBtn.onclick=()=>archiveModal.classList.add('hidden');exportBtn.onclick=async()=>{archiveText.value=encode();archiveText.select();try{await navigator.clipboard.writeText(archiveText.value);archiveFeedback.textContent='远征档案已复制。';}catch(_){archiveFeedback.textContent='档案已生成,请手动复制。';}};importBtn.onclick=()=>{try{career=decode(archiveText.value);save();selected=Math.min(career.unlocked,11);state=makeState();renderSide();updateHud();archiveFeedback.textContent='导入成功。';}catch(e){archiveFeedback.textContent=e.message;}};
document.querySelectorAll('[data-dir]').forEach(b=>{const code={up:'ArrowUp',down:'ArrowDown',left:'ArrowLeft',right:'ArrowRight'}[b.dataset.dir];b.onpointerdown=e=>{e.preventDefault();keys.add(code);};b.onpointerup=b.onpointerleave=b.onpointercancel=()=>keys.delete(code);});canvas.onpointerdown=e=>{const r=canvas.getBoundingClientRect();pointer={x:e.clientX-r.left,y:e.clientY-r.top};canvas.setPointerCapture?.(e.pointerId);};canvas.onpointermove=e=>{if(pointer){const r=canvas.getBoundingClientRect();pointer={x:e.clientX-r.left,y:e.clientY-r.top};}};canvas.onpointerup=canvas.onpointercancel=()=>pointer=null;document.addEventListener('keydown',e=>{keys.add(e.code);if(e.code==='Space'){e.preventDefault();blink();}if(e.code==='KeyQ')nova();});document.addEventListener('keyup',e=>keys.delete(e.code));window.addEventListener('resize',resize);
window.__cometWeaver={STAGES,MODULES,career:()=>career,state:()=>state,selectStage,start,finish,encode,decode,currentRating};
resize();renderSide();selectStage(selected);draw();
})();
</script>
</body>
</html>