diff --git a/README.md b/README.md index 2bab0b4..59637fb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ npm run test:browser npm run test:results npm run test:interactions npm run test:container +npm run test:swipes ``` 浏览器测试目前默认使用 macOS 已安装的 Google Chrome,路径见 `tests/browser.mjs`。构建要求 Python 3,以及官方 [minitool-zip-builder 1.8.0 Skill](https://fe-static.xhscdn.com/minitool/20261015161653/minitool-zip-builder-1.8.0.skill)。克隆后需将 Skill 解压到本地 `.codex/skills/minitool-zip-builder/`,该目录应直接包含 `SKILL.md`、`references/` 和 `scripts/`。本地工具、依赖、构建输出和报告均已忽略,不推送到代码库。所有运行依赖与地图随最终 ZIP 提供,无联网运行逻辑。 @@ -36,9 +37,9 @@ npm run test:container ## 玩法与得分 -进入页选择省级 / 地级版、地区、四档下落速度和三档弹性,点击“开启这局旅程”后开局。独立的整屏游戏页底部提供“左晃 / 上晃 / 右晃”:左右支持按住,向上点击轻颠,也支持键盘 ← ↑ →。操作的是整个框和其中所有组合,没有单片拖动、旋转或加速。弹跳和倾斜有上限,松手后自动回正。 +进入页选择省级 / 地级版、地区、四档下落速度和三档弹性,点击“开启这局旅程”后开局。在容器内快速轻划并松手,给容器一次惯性晃动;划过位置附近的地块反应更强。每次轻划只在松手时触发一次,地块获得带少量方向、力度差异的冲量后自由运动,手指只能决定大致方向。慢拖、按住、取消触摸或暂停不会持续施力,也不会抓取、牵引或瞬移单块碎片。底部只有一个无文字的圆形暂停图标,统一查看本局旅程、继续、结束或重开;电脑保留方向键辅助。弹跳、倾斜和速度有上限。 -只有真实相邻关系、正确地理位置接近时才自动吸合。全部落下后仍可晃动,直到通关、稳定堆过红线超过 2.4 秒,或主动结束。顶部暂停 / 返回都打开暂停页,可继续、结束旅程、重新开局。结束旅程会保留成绩,即使零分或未通关也会生成图片;通关和判负自动生成。 +只有真实相邻关系、正确地理位置接近时才自动吸合。全部落下后仍可晃动,直到通关、稳定堆过红线超过 2.4 秒,或主动结束。底部圆形暂停图标打开旅程菜单,可继续、结束旅程、重新开局。结束旅程会保留成绩,即使零分或未通关也会生成图片;通关和判负自动生成。 省级海岛使用明确标注的“跨海连接”;地级版中因海域、未纳入本关的省直辖县等产生的间隔,使用明确标注的“隔区连接”。这两种连接都是游戏规则,不能当作陆地邻接关系。入口地图保留相对地理位置。 @@ -49,7 +50,7 @@ npm run test:container | 一路狂飙 | 4 秒 | 0.7 | ×2 | | 山河起飞 | 2.5 秒 | 1 | ×3 | -每次合并分数 = `(100 + 40 × (合并后块数 − 2)) × 连合系数 × 速度倍率 × 特殊连接系数`,四舍五入到整数。8.5 秒内再次合并视为连合,系数每次增加 0.25,从 1 起、最高 2;跨海和隔区连接额外乘 0.8。通关再奖 `1000 × 速度倍率`。三向晃动不限次数、不扣分。弹性不改变得分倍率。 +每次合并分数 = `(100 + 40 × (合并后块数 − 2)) × 连合系数 × 速度倍率 × 特殊连接系数`,四舍五入到整数。8.5 秒内再次合并视为连合,系数每次增加 0.25,从 1 起、最高 2;跨海和隔区连接额外乘 0.8。通关再奖 `1000 × 速度倍率`。轻划不限次数、不扣分。弹性不改变得分倍率。 弹性三档为“轻轻弹 / 蹦蹦跳 / 弹力全开”,碰撞恢复系数分别为 0.65 / 0.82 / 0.96,同时调整空气阻力、横向冲量和上抛上限。现在最低档对应上一版最高档;默认推荐“蹦蹦跳”,便于腾挪,“弹力全开”需要更好地控制节奏。省级、地级碎片均在上一版基础上线性再缩小 10%;地级仍比相同地图基准额外小 30%;组合过大时仍会全局等比缩放。 @@ -66,8 +67,8 @@ npm run test:container ## 代码与数据 - `src/core.js`:相邻关系、地理位置与角度吸合判断、计分、纪录清洗。 -- `src/game.js`:Matter.js 刚体、出片、组合、胜负、速度、弹性、三向容器晃动、得分时间点和尺寸变化。 -- `src/app.js`:入口 / 游戏 / 成绩页切换、Canvas 绘制、三向输入、暂停与结束、原生 Storage、发笔记和相册导出。 +- `src/game.js`:Matter.js 刚体、出片、组合、胜负、速度、弹性、容器滑动与上晃、得分时间点和尺寸变化。 +- `src/app.js`:入口 / 游戏 / 成绩页切换、Canvas 绘制、容器手势与键盘输入、暂停与结束、原生 Storage、发笔记和相册导出。 - `src/result.js`:真实结局快照与得分曲线的成绩图绘制。 - `src/index.html`、`src/style.css`:单入口、响应式布局、安全区和 Chrome 61 样式基线。 - `src/maps.js`:构建期简化的省级 / 地级真实轮廓与预计算连接图。 @@ -88,7 +89,7 @@ npm run test:container 棋盘改为较窄的开口实体容器,侧壁和底边清晰可见,红色警戒线位于顶部 78px。以 320×435 逻辑尺寸为例,全国开局缩放约 0.4995,相对最初约 0.215 的版本仍明显更大,本轮比上一版的0.555再缩小10%。保持各省之间真实比例,微小地区保持真实相对比例,同样通过框体晃动参与拼接。 -晃动采用阻尼弹簧模型:容器位移和施加给所有碎片的惯性来自同一状态,并有 14px 的视觉位移限制。左右按钮和键盘左右键均可以持续按住,松开即停止继续施力。无需加速度计或设备运动 API。 +晃动采用阻尼弹簧模型:容器位移和施加给所有碎片的惯性来自同一状态,并有 14px 的视觉位移限制。在容器内滑动可朝任意方向施加冲量,力度随滑速增加,按与手指的距离平滑衰减;所有组合都受影响,近处更强。移动时只采集手势,在松手时识别一次轻划;使用最近约180ms轨迹,位移至少18px、平均速度至少0.16px/ms,慢拖和按住不触发。触发间隔至少240ms,系统取消或暂停清理尚未触发的手势。键盘左右键仍支持长按。无需加速度计或设备运动 API。 较大组合超出容器可用空间时,全体碎片按相同比例缩小,保持地理相对比例、分数与队列,继续容纳完整地图。难度和拥堵由关卡形状、晃动、速度及弹性共同影响;本地模拟只用于排查物理问题,不能推断真机性能或玩家通关难度。 @@ -110,8 +111,10 @@ npm run test:container 入口和游戏页均按可见视口及安全区排版:在320×568、375×667、390×844以及740×390横屏检查一屏显示;小屏会缩减装饰地图和冗余文案,保留所有主要选择与开局按钮。省区选择采用27项网格,不再使用原生长下拉框,弹窗注明无地级数据的范围。 -四档名称为“佛系看山 / 说走就走 / 一路狂飙 / 山河起飞”,速度与倍率参数保持原值。三个晃动按钮居中排版,成绩页同样一屏显示。游戏地图先绘制全部形状,再统一绘制标签;名称采用独立布局、边距约束、避让,以及小地区标签底色 / 引线,防止名称贴底被裁或被其他省份覆盖。 +四档名称为“佛系看山 / 说走就走 / 一路狂飙 / 山河起飞”,速度与倍率参数保持原值。底部仅保留无文字的圆形暂停图标,合并全部旅程操作,容器顶部说明标签已移除,成绩页同样一屏显示。游戏地图先绘制全部形状,再统一绘制标签;名称采用独立布局、边距约束、避让,以及小地区标签底色 / 引线,防止名称贴底被裁或被其他省份覆盖。 构建补回源数据的小离岛外环及独立海域线层,34省级代码、名称及外环数量均与保存的原始数据对比。台湾省14个源外环、香港9个、澳门2个、海南133个全部保留。详见`artifacts/MAP_AUDIT.md`,这不是标准地图审图结论。 `npm run test:container`在现代浏览器模拟平台顶部按钮与四组手机尺寸/安全区,逐页点击并检查布局,不替代小红书真机验证。 + +`tests/swipes.mjs` 使用真实触摸事件验证单次轻划松手触发、移动中不施力、慢拖和按住过滤、松手后的惯性运动、系统取消、滑动中暂停和恢复、圆形无文字菜单;物理单测另检查附近力度更强、远处仍动、快速更有力和三档边界限制。 diff --git a/package.json b/package.json index 6e1433a..ac50889 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "test:browser": "node tests/browser.mjs", "test:results": "node tests/results.mjs", "test:interactions": "node tests/interactions.mjs", - "test:container": "node tests/container-layout.mjs" + "test:container": "node tests/container-layout.mjs", + "test:swipes": "node tests/swipes.mjs" }, "dependencies": { "matter-js": "0.20.0", diff --git a/src/app.js b/src/app.js index 37541d1..64b5bdb 100644 --- a/src/app.js +++ b/src/app.js @@ -5,7 +5,7 @@ var colors=['#c3d4b4','#e3c78f','#d2b5a5','#b5cbd0','#d2c69d','#b1c5a0','#d9bca6 var provinceCode='330000',mode='province',speed=0,bounce=1,result=null,level=data.levels[0],game=null,screen='entry',records={},pausedByModal=false,toastTimer=null; var canvas=$('board'),ctx=canvas.getContext('2d'),w=0,h=0,dpr=1,miniTool=null,storageNative=false,storeReady=false,saveChain=Promise.resolve(); var reducedMotion=typeof window.matchMedia==='function'?window.matchMedia('(prefers-reduced-motion: reduce)'):null,modeGesture=null,suppressModeClickUntil=0; -var holdTimer=null,inputDirection=0,pointerDirection=0,keys={left:false,right:false},rafId=0,last=0,uiAt=0,lastLabelBoxes=[],labelObstacles=[]; +var holdTimer=null,inputDirection=0,tankGesture=null,swipeTrace=null,keys={left:false,right:false},rafId=0,last=0,uiAt=0,lastLabelBoxes=[],labelObstacles=[]; function motionAllowed(){return !reducedMotion||!reducedMotion.matches;} function pulseButton(button,kind){if(!button||button.disabled||!motionAllowed())return;button.classList.remove('tap-pop','bounce-pop');void button.offsetWidth;button.classList.add(kind||'tap-pop');} document.addEventListener('animationend',function(e){if(e.target.classList){e.target.classList.remove('tap-pop','bounce-pop');}}); @@ -30,7 +30,7 @@ function layout(){ if(screen==='entry'){fitEntryMap();drawReference();return;}if(screen==='result'){fitCard();return;} var r=canvas.getBoundingClientRect(),nw=Math.round(r.width),nh=Math.round(r.height); if(nw<1||nh<1)return; - var changed=w!==nw||h!==nh;w=nw;h=nh;sizeCanvas(canvas,w,h);labelObstacles=['board-name','board-status'].map(function(id){var box=$(id).getBoundingClientRect();return {x:box.left-r.left-3,y:box.top-r.top-2,w:box.width+6,h:box.height+4};});var danger=document.querySelector('.danger-label').getBoundingClientRect();labelObstacles.push({x:danger.left-r.left-3,y:danger.top-r.top-2,w:danger.width+6,h:danger.height+4}); + var changed=w!==nw||h!==nh;w=nw;h=nh;sizeCanvas(canvas,w,h);labelObstacles=['board-status'].map(function(id){var box=$(id).getBoundingClientRect();return {x:box.left-r.left-3,y:box.top-r.top-2,w:box.width+6,h:box.height+4};});var danger=document.querySelector('.danger-label').getBoundingClientRect();labelObstacles.push({x:danger.left-r.left-3,y:danger.top-r.top-2,w:danger.width+6,h:danger.height+4}); if(game&&changed)game.resize(w,h);drawNext();if(game)draw(); } function fitEntryMap(){ @@ -49,12 +49,11 @@ function closeModal(resume){$('province-picker').classList.remove('expanded');va $('modal').addEventListener('cancel',function(e){e.preventDefault();closeModal();});$('close-modal').addEventListener('click',function(){closeModal();}); function start(){ stopInput();result=null;lastLabelBoxes=[];if(game)game.destroy();game=null;screen='game';document.body.classList.add('is-playing');$('entry-screen').hidden=true;$('result-screen').hidden=true;$('game-screen').hidden=false;window.scrollTo(0,0); - $('board-status').textContent='左右轻摇 / 向上轻颠,晃动整个框';$('tank').style.transform='translateX(0px)';layout(); + $('board-status').textContent='轻划后松手,让山河随惯性相遇';$('tank').style.transform='translateX(0px)';layout(); game=new Engine.Game(level,w,h,speed,onGameEvent,null,bounce);game.start();last=0;drawNext();updateUI();schedule(); } function showEntry(){stopInput();cancelAnimationFrame(rafId);rafId=0;if(game)game.destroy();game=null;lastLabelBoxes=[];screen='entry';document.body.classList.remove('is-playing');$('game-screen').hidden=true;$('result-screen').hidden=true;$('entry-screen').hidden=false;result=null;$('tank').style.transform='translateX(0px)';window.scrollTo(0,0);updateUI();layout();} function finishJourney(){closeModal(false);if(game)game.finish();} -function askBack(){pause();} function pause(){if(!game||screen!=='game'||$('modal').hasAttribute('open'))return;if(game.endReason){showResult();return;}openModal('TAKE A BREATH','

山河等你回来

'+level.name+' · '+Engine.SPEEDS[speed].name+' · '+Engine.BOUNCES[bounce].name+'

暂停不计时。随时结束,也能带走这一程的成绩图。

',[{label:'继续游戏',primary:true,action:function(){closeModal();}},{label:'结束旅程',action:finishJourney},{label:'重新开局',action:function(){closeModal(false);start();}}]);} function onGameEvent(type,detail){ if(type==='spawn'){drawNext();if(game.queue.length===0)$('board-status').textContent='碎片已全部落下 · 继续晃动容器';} @@ -69,16 +68,12 @@ function updateUI(){ $('city-select-panel').hidden=mode!=='city';$('city-note').textContent='27 个省区可选 · 仅拼地级市、自治州、地区、盟'; $('multiplier').textContent='得分 ×'+config.multiplier;var comments=['慢慢来,也能看见山河','找到自己的拼图节奏','眼疾手快,山河相逢','留给地理高手的挑战'];$('speed-note').textContent=config.interval/1000+' 秒落下一块 · '+comments[speed]; document.querySelectorAll('[data-mode]').forEach(function(b){var selected=b.getAttribute('data-mode')===mode;b.classList.toggle('selected',selected);b.setAttribute('aria-pressed',String(selected));}); - var modeTabs=document.querySelector('.mode-tabs'); -modeTabs.addEventListener('pointerdown',function(e){if(screen==='entry'&&e.isPrimary!==false)modeGesture={x:e.clientX,y:e.clientY,id:e.pointerId};}); -document.addEventListener('pointerup',function(e){if(!modeGesture||modeGesture.id!==e.pointerId)return;var dx=e.clientX-modeGesture.x,dy=e.clientY-modeGesture.y;modeGesture=null;if(screen==='entry'&&Math.abs(dx)>35&&Math.abs(dx)>Math.abs(dy)*1.3){mode=dx<0?'city':'province';suppressModeClickUntil=performance.now()+350;selectLevel();}}); -document.addEventListener('pointercancel',function(){modeGesture=null;}); document.querySelectorAll('[data-speed]').forEach(function(b){var selected=Number(b.getAttribute('data-speed'))===speed;b.classList.toggle('selected',selected);b.setAttribute('aria-pressed',String(selected));}); document.querySelectorAll('[data-bounce]').forEach(function(b){var selected=Number(b.getAttribute('data-bounce'))===bounce;b.classList.toggle('selected',selected);b.setAttribute('aria-pressed',String(selected));}); - var playable=!!game&&game.status==='playing';$('left').disabled=!playable;$('right').disabled=!playable;$('up').disabled=!playable;$('pause').disabled=!game; + $('pause').disabled=!game; if(!game)return; $('score').textContent=game.score.toLocaleString('zh-CN');$('merged').textContent=game.groups.reduce(function(n,g){return Math.max(n,g.ids.length);},0);$('total').textContent=level.regions.length; - $('game-title').textContent=level.name+(mode==='city'?' · 地级拼图':'');$('game-speed').textContent=config.name+' · '+Engine.BOUNCES[bounce].name+' · ×'+config.multiplier;$('board-name').textContent='山河容器 · 碰撞后自动回正'; + $('game-title').textContent=level.name+(mode==='city'?' · 地级拼图':'');$('game-speed').textContent=config.name+' · '+Engine.BOUNCES[bounce].name+' · ×'+config.multiplier; $('progress-label').textContent='已落下 '+game.dropped+' / '+level.regions.length+' 块'+(game.maxChain>1?' · 最佳 '+game.maxChain+' 连合':''); } function polygon(context,ring,transform){context.beginPath();ring.forEach(function(p,i){var q=transform(p);if(i===0)context.moveTo(q.x,q.y);else context.lineTo(q.x,q.y);});context.closePath();} @@ -107,19 +102,42 @@ function contactTransform(g){ } function draw(){if(!game)return;ctx.clearRect(0,0,w,h);ctx.fillStyle='#f1f2e9';ctx.fillRect(0,0,w,h);ctx.fillStyle='#d8decd';for(var x=15;x0?'#bd3e42':'#d46e70';ctx.setLineDash([4,5]);ctx.beginPath();ctx.moveTo(0,Engine.DANGER_Y);ctx.lineTo(w,Engine.DANGER_Y);ctx.stroke();ctx.setLineDash([]); var labels=[];game.groups.forEach(function(g){var trans=contactTransform(g);g.ids.forEach(function(i){var r=level.regions[i];drawPiece(ctx,r,i,trans,{label:false,physical:true,impact:motionAllowed()&&g.hitUntil>game.clock});var points=r.rings[0].map(trans),xs=points.map(function(p){return p.x;}),ys=points.map(function(p){return p.y;}),rw=Math.max.apply(null,xs)-Math.min.apply(null,xs),rh=Math.max.apply(null,ys)-Math.min.apply(null,ys);labels.push({name:mode==='province'?shortName(r.name):r.name,anchor:trans(r.label||r.center),tiny:rw<32||rh<25});});if(g.ids.length===level.regions.length)drawDecorations(ctx,trans);}); + if(swipeTrace&&swipeTrace.until>game.clock&&motionAllowed()){var life=(swipeTrace.until-game.clock)/280;ctx.save();ctx.globalAlpha=life*.30;ctx.strokeStyle='#9b8b62';ctx.lineWidth=1.5;ctx.beginPath();ctx.arc(swipeTrace.x,swipeTrace.y,9+(1-life)*12,0,Math.PI*2);ctx.moveTo(swipeTrace.x,swipeTrace.y);var length=Math.max(1,Math.hypot(swipeTrace.dx,swipeTrace.dy));ctx.lineTo(swipeTrace.x+swipeTrace.dx/length*19,swipeTrace.y+swipeTrace.dy/length*19);ctx.stroke();ctx.restore();} lastLabelBoxes=renderLabels(ctx,labels,w,h,Math.max(9,Math.min(12,12*Math.sqrt(game.zoom))),labelObstacles); if(motionAllowed())game.impacts.forEach(function(f){var life=Math.max(0,(f.until-game.clock)/Engine.SPARK_MS),radius=1.5+(1-life)*(2+f.strength*2);ctx.save();ctx.globalAlpha=life*.38;ctx.strokeStyle='#b8a779';ctx.lineWidth=1;ctx.beginPath();ctx.arc(f.x,f.y,radius,0,Math.PI*2);ctx.stroke();for(var i=0;i<2;i++){var angle=i*Math.PI+.7;ctx.beginPath();ctx.moveTo(f.x+Math.cos(angle)*(radius+1),f.y+Math.sin(angle)*(radius+1));ctx.lineTo(f.x+Math.cos(angle)*(radius+3),f.y+Math.sin(angle)*(radius+3));ctx.stroke();}ctx.restore();}); game.fx.forEach(function(f){ctx.save();ctx.globalAlpha=Math.min(1,(f.until-game.clock)/500);ctx.textAlign='center';ctx.font='500 12px sans-serif';ctx.fillStyle='#557642';ctx.fillText(f.text,Math.max(70,Math.min(w-70,f.x)),f.y-28-(1600-f.until+game.clock)*.018);ctx.restore();}); } function schedule(){if(!rafId&&!document.hidden&&game)rafId=requestAnimationFrame(frame);} function frame(t){rafId=0;if(!game||screen!=='game')return;if(!last)last=t;game.tick(t-last);last=t;if(screen!=='game')return;$('tank').style.transform='translate('+game.shake.offset.toFixed(2)+'px,'+game.shake.y.toFixed(2)+'px)';$('tank').classList.toggle('impact',game.wallHitUntil>game.clock);draw();if(t-uiAt>120){uiAt=t;updateUI();}if(game.status==='playing')schedule();} -function stopInput(){if(game)game.groups.forEach(function(g){g.pendingHopUntil=-1;});clearInterval(holdTimer);holdTimer=null;inputDirection=0;pointerDirection=0;keys.left=false;keys.right=false;$('left').classList.remove('pressed');$('right').classList.remove('pressed');} -function refreshInput(){var direction=pointerDirection||((keys.right?1:0)-(keys.left?1:0));if(!game||game.status!=='playing')direction=0;if(direction===inputDirection)return;clearInterval(holdTimer);holdTimer=null;inputDirection=direction;$('left').classList.toggle('pressed',direction<0);$('right').classList.toggle('pressed',direction>0);if(direction){game.nudge(direction);holdTimer=setInterval(function(){if(game&&game.status==='playing')game.nudge(direction);else stopInput();},150);}} -function bindDirection(id,direction){var b=$(id);b.addEventListener('pointerdown',function(e){if(b.disabled)return;e.preventDefault();pointerDirection=direction;if(typeof b.setPointerCapture==='function')b.setPointerCapture(e.pointerId);refreshInput();});function release(){if(pointerDirection===direction){pointerDirection=0;refreshInput();}}['pointerup','pointercancel','lostpointercapture'].forEach(function(type){b.addEventListener(type,release);});b.addEventListener('click',function(e){if(e.detail===0&&game&&game.status==='playing')game.nudge(direction);});} -bindDirection('left',-1);bindDirection('right',1);$('up').addEventListener('click',function(){if(game)game.nudgeUp();}); -document.addEventListener('keydown',function(e){if(screen!=='game'||$('modal').hasAttribute('open'))return;if(e.key===' '){e.preventDefault();if(!e.repeat)pause();return;}if(e.key==='ArrowUp'){e.preventDefault();if(!e.repeat&&game){if(game.nudgeUp())pulseButton($('up'),'bounce-pop');}return;}if(e.key!=='ArrowLeft'&&e.key!=='ArrowRight')return;e.preventDefault();if(e.repeat)return;keys[e.key==='ArrowLeft'?'left':'right']=true;refreshInput();}); +function endTankGesture(){var gesture=tankGesture;tankGesture=null;$('tank').classList.remove('swiping');if(gesture&&typeof canvas.hasPointerCapture==='function'&&canvas.hasPointerCapture(gesture.id))canvas.releasePointerCapture(gesture.id);} +function stopInput(){if(game)game.groups.forEach(function(g){g.pendingHopUntil=-1;});endTankGesture();swipeTrace=null;clearInterval(holdTimer);holdTimer=null;inputDirection=0;keys.left=false;keys.right=false;} +function refreshInput(){var direction=(keys.right?1:0)-(keys.left?1:0);if(!game||game.status!=='playing')direction=0;if(direction===inputDirection)return;clearInterval(holdTimer);holdTimer=null;inputDirection=direction;if(direction){game.nudge(direction);holdTimer=setInterval(function(){if(game&&game.status==='playing')game.nudge(direction);else stopInput();},150);}} +// Collect a short flick, then emit exactly one impulse on release. Pointer +// movement itself never applies force, sets a body position or selects a piece. +function sampleTankGesture(e){ + var g=tankGesture,now=performance.now();g.x=e.clientX;g.y=e.clientY;g.active=Math.hypot(g.x-g.startX,g.y-g.startY)>=18; + g.samples.push({x:g.x,y:g.y,t:now});while(g.samples.length>2&&g.samples[1].t24)g.samples.splice(1,1); +} +function releaseTankFlick(e){ + var g=tankGesture;if(!g||g.id!==e.pointerId)return; + sampleTankGesture(e);var samples=g.samples,end=samples[samples.length-1],first=samples[0],dx=end.x-first.x,dy=end.y-first.y,elapsed=end.t-first.t,distance=Math.hypot(dx,dy); + // A slow drag or a held finger is not a flick. Pauses/cancellations discard it. + if(game&&game.status==='playing'&&distance>=18&&elapsed<=350&&distance/Math.max(16,elapsed)>=.16){ + var rect=canvas.getBoundingClientRect(),point={x:Math.max(0,Math.min(w,((first.x+end.x)/2-rect.left)*w/rect.width)),y:Math.max(0,Math.min(h,((first.y+end.y)/2-rect.top)*h/rect.height))}; + if(game.swipe(point,{x:dx,y:dy},elapsed))swipeTrace={x:point.x,y:point.y,dx:dx,dy:dy,until:game.clock+280}; + } + endTankGesture(); +} +canvas.addEventListener('pointerdown',function(e){ + if(screen!=='game'||!game||game.status!=='playing'||$('modal').hasAttribute('open')||tankGesture||e.isPrimary===false||(e.pointerType==='mouse'&&e.button!==0))return; + e.preventDefault();var now=performance.now();tankGesture={id:e.pointerId,startX:e.clientX,startY:e.clientY,x:e.clientX,y:e.clientY,active:false,samples:[{x:e.clientX,y:e.clientY,t:now}]};if(typeof canvas.setPointerCapture==='function')canvas.setPointerCapture(e.pointerId); +}); +canvas.addEventListener('pointermove',function(e){if(!tankGesture||tankGesture.id!==e.pointerId)return;e.preventDefault();sampleTankGesture(e);}); +canvas.addEventListener('pointerup',releaseTankFlick); +['pointercancel','lostpointercapture'].forEach(function(type){canvas.addEventListener(type,function(e){if(tankGesture&&tankGesture.id===e.pointerId)endTankGesture();});}); +document.addEventListener('keydown',function(e){if(screen!=='game'||$('modal').hasAttribute('open'))return;if(e.key===' '){e.preventDefault();if(!e.repeat)pause();return;}if(e.key==='ArrowUp'){e.preventDefault();if(!e.repeat&&game)game.nudgeUp();return;}if(e.key!=='ArrowLeft'&&e.key!=='ArrowRight')return;e.preventDefault();if(e.repeat)return;keys[e.key==='ArrowLeft'?'left':'right']=true;refreshInput();}); document.addEventListener('keyup',function(e){if(e.key==='ArrowLeft'||e.key==='ArrowRight'){keys[e.key==='ArrowLeft'?'left':'right']=false;refreshInput();}}); -document.addEventListener('pointerdown',function(){document.body.classList.add('using-pointer');});document.addEventListener('keydown',function(e){if(e.key==='Tab')document.body.classList.remove('using-pointer');});$('start').addEventListener('click',start);$('pause').addEventListener('click',pause);$('back').addEventListener('click',askBack); +document.addEventListener('pointerdown',function(){document.body.classList.add('using-pointer');});document.addEventListener('keydown',function(e){if(e.key==='Tab')document.body.classList.remove('using-pointer');});$('start').addEventListener('click',start);$('pause').addEventListener('click',pause); function openProvincePicker(){ openModal('PICK A DESTINATION','

这局,拼哪里?

直辖市、港澳没有地级关卡;台湾省暂缺地级轮廓数据。省级版包含全部 34 个省级行政区。

');$('modal').classList.add('province-picker-modal');$('province-picker').classList.add('expanded'); data.levels.slice(1).forEach(function(l){var button=document.createElement('button');button.type='button';button.textContent=shortName(l.name);button.setAttribute('data-province',l.id);button.setAttribute('aria-pressed',String(l.id===provinceCode));button.className=l.id===provinceCode?'selected':'';button.addEventListener('click',function(){provinceCode=l.id;selectLevel();closeModal();});$('province-grid').appendChild(button);}); @@ -131,7 +149,7 @@ modeTabs.addEventListener('pointerdown',function(e){if(screen==='entry'&&e.isPri document.addEventListener('pointerup',function(e){if(!modeGesture||modeGesture.id!==e.pointerId)return;var dx=e.clientX-modeGesture.x,dy=e.clientY-modeGesture.y;modeGesture=null;if(screen==='entry'&&Math.abs(dx)>35&&Math.abs(dx)>Math.abs(dy)*1.3){mode=dx<0?'city':'province';suppressModeClickUntil=performance.now()+350;selectLevel();}}); document.addEventListener('pointercancel',function(){modeGesture=null;}); document.querySelectorAll('[data-speed]').forEach(function(b){b.addEventListener('click',function(){if(screen!=='entry')return;speed=Number(b.getAttribute('data-speed'));updateUI();});});document.querySelectorAll('[data-bounce]').forEach(function(b){b.addEventListener('click',function(){if(screen!=='entry')return;bounce=Number(b.getAttribute('data-bounce'));updateUI();});});$('province-picker').addEventListener('click',openProvincePicker); -$('rules-button').addEventListener('click',function(){openModal('HOW TO PLAY','

轻摇轻颠,拼一片山河

  1. 先选旅程,再开一局。选择省级 / 地级版、地区、下落速度和弹性,点击开始。
  2. 晃动整个框。按住左晃或右晃,点击中间上晃轻颠,也可使用键盘 ← ↑ →;框体左右晃动,所有碎片受到惯性影响。
  3. 相邻的边自动吸合。碎片碰撞时会轻微弹跳、翻动,停稳后自动回正;只有真实相邻地区按正确方位接触时才合并。把所有碎片拼为一个整体即可通关。
合并基础分:100 + 40 ×(合并后块数 − 2)
8.5 秒内连合,每次系数 +0.25,最高 ×2。
速度倍率:佛系看山 ×1 / 说走就走 ×1.5 / 一路狂飙 ×2 / 山河起飞 ×3。
跨海 / 隔区连接 ×0.8;通关再奖 1000 × 速度倍率。
三向晃动不限次数、不扣分;弹性不改变得分倍率,最佳纪录按速度和弹性分别保存。

弹性推荐“蹦蹦跳”,方便腾挪;“轻轻弹”偏沉稳,“弹力全开”需要控制节奏。稳定堆过顶部红线超过 2.4 秒,本局结束;也可随时从暂停页结束并生成成绩图。省级离岛和地级间隔分别标记为跨海、隔区连接。

');}); +$('rules-button').addEventListener('click',function(){openModal('HOW TO PLAY','

轻摇轻颠,拼一片山河

  1. 先选旅程,再开一局。选择省级 / 地级版、地区、下落速度和弹性,点击开始。
  2. 晃动整个框。在容器内快速轻划并松手,触发一次晃动。划过位置附近更剧烈,所有地块随后自由运动;手指只给出大致方向,不能牵引地块。慢拖或按住不触发,点击底部圆形暂停图标可查看本局、结束或重开;电脑也可使用方向键。
  3. 相邻的边自动吸合。碎片碰撞时会轻微弹跳、翻动,停稳后自动回正;只有真实相邻地区按正确方位接触时才合并。把所有碎片拼为一个整体即可通关。
合并基础分:100 + 40 ×(合并后块数 − 2)
8.5 秒内连合,每次系数 +0.25,最高 ×2。
速度倍率:佛系看山 ×1 / 说走就走 ×1.5 / 一路狂飙 ×2 / 山河起飞 ×3。
跨海 / 隔区连接 ×0.8;通关再奖 1000 × 速度倍率。
轻划不限次数、不扣分;弹性不改变得分倍率,最佳纪录按速度和弹性分别保存。

弹性推荐“蹦蹦跳”,方便腾挪;“轻轻弹”偏沉稳,“弹力全开”需要控制节奏。稳定堆过顶部红线超过 2.4 秒,本局结束;也可随时从暂停页结束并生成成绩图。省级离岛和地级间隔分别标记为跨海、隔区连接。

');}); $('data-button').addEventListener('click',function(){openModal('MAP NOTES','

关于这片山河

轮廓来源:阿里云 DataV.GeoAtlas 公开行政区数据,2026-10-16 下载,随包离线提供。轮廓已为游戏做简化,所有源数据外环及独立海域线段随包保留。

省级版包含 34 块;地级版提供 27 个省区关卡、333 个地级单元,包含地级市、自治州、地区、盟,不含县和县级市。直辖市、港澳不设地级关卡;数据源暂缺台湾省地级轮廓。

岛屿及未纳入的省直辖县造成的间隔,使用明确标记的跨海 / 隔区连接。地图仅供游戏示意,不用于测绘、导航或区划查询。

纪录仅在本地保存,存储失败不影响游玩。

');}); function fitCard(){var box=$('result-card').parentNode,r=box.getBoundingClientRect(),sc=Math.max(.01,Math.min((r.width-22)/750,(r.height-22)/1400));$('result-card').style.width=Math.floor(750*sc)+'px';$('result-card').style.height=Math.floor(1400*sc)+'px';} function showResult(){ @@ -158,5 +176,5 @@ window.addEventListener('resize',layout);if(window.visualViewport&&typeof window document.addEventListener('visibilitychange',function(){if(document.hidden){stopInput();pause();cancelAnimationFrame(rafId);rafId=0;}else{last=0;if(game&&game.status==='playing')schedule();}}); layout();updateUI();storePromise=initStore(); // Read-only development diagnostics: interaction is exclusively through the tank controls. -window.shanheDebug={state:function(){return {screen:screen,status:game?game.status:'entry',score:game?game.score:0,level:level.id,speed:speed,bounce:bounce,bounceName:Engine.BOUNCES[bounce].name,history:game?game.history.map(function(p){return {ms:p.ms,score:p.score};}):[],elapsed:game?game.clock:0,result:result,shakeY:game?game.shake.y:0,dropped:game?game.dropped:0,remaining:game?game.queue.length:level.regions.length,groups:game?game.groups.length:0,shakeCount:game?game.shakeCount:0,hopCount:game?game.hopCount:0,shakeOffset:game?game.shake.offset:0,scale:game?game.scale:0,initialScale:game?game.initialScale:0,zoom:game?game.zoom:1,width:w,height:h,collisionCount:game?game.collisionCount:0,impactCount:game?game.impacts.length:0,contactPulse:game?game.groups.filter(function(g){return g.hitUntil>game.clock;}).length:0,labels:lastLabelBoxes.map(function(b){return {name:b.name,x:b.x,y:b.y,w:b.w,h:b.h};}),regions:game?game.groups.map(function(g){return {ids:g.ids.slice(),x:g.body.position.x,y:g.body.position.y,angle:g.body.angle,vx:g.body.velocity.x,vy:g.body.velocity.y};}):[]};}}; +window.shanheDebug={state:function(){return {screen:screen,status:game?game.status:'entry',score:game?game.score:0,level:level.id,speed:speed,bounce:bounce,bounceName:Engine.BOUNCES[bounce].name,history:game?game.history.map(function(p){return {ms:p.ms,score:p.score};}):[],elapsed:game?game.clock:0,result:result,shakeY:game?game.shake.y:0,dropped:game?game.dropped:0,remaining:game?game.queue.length:level.regions.length,groups:game?game.groups.length:0,shakeCount:game?game.shakeCount:0,swipeCount:game?game.swipeCount:0,swiping:!!(tankGesture&&tankGesture.active),hopCount:game?game.hopCount:0,shakeOffset:game?game.shake.offset:0,scale:game?game.scale:0,initialScale:game?game.initialScale:0,zoom:game?game.zoom:1,width:w,height:h,collisionCount:game?game.collisionCount:0,impactCount:game?game.impacts.length:0,contactPulse:game?game.groups.filter(function(g){return g.hitUntil>game.clock;}).length:0,labels:lastLabelBoxes.map(function(b){return {name:b.name,x:b.x,y:b.y,w:b.w,h:b.h};}),regions:game?game.groups.map(function(g){return {ids:g.ids.slice(),x:g.body.position.x,y:g.body.position.y,angle:g.body.angle,vx:g.body.velocity.x,vy:g.body.velocity.y};}):[]};}}; })(); diff --git a/src/game.js b/src/game.js index 378a77e..93bea6b 100644 --- a/src/game.js +++ b/src/game.js @@ -6,7 +6,7 @@ function baseScale(level,w,h){var maxw=0,maxh=0;level.regions.forEach(function(r var SPEEDS=[{name:'佛系看山',interval:8500,gravity:.32,multiplier:1},{name:'说走就走',interval:6000,gravity:.48,multiplier:1.5},{name:'一路狂飙',interval:4000,gravity:.7,multiplier:2},{name:'山河起飞',interval:2500,gravity:1,multiplier:3}]; var BOUNCES=[{name:'轻轻弹',restitution:.65,hop:2.15,rise:90,air:.022,push:1,maxX:7.2,friction:.22,scatter:0},{name:'蹦蹦跳',restitution:.82,hop:6,rise:250,air:.012,push:1.22,maxX:9.5,friction:.16,scatter:2.6},{name:'弹力全开',restitution:.96,hop:14,rise:540,air:.006,push:1.7,maxX:13,friction:.10,scatter:5}]; function Game(level,width,height,speed,emit,rng,bounce){ -this.bounceIndex=BOUNCES[bounce]?bounce:0;this.bounce=BOUNCES[this.bounceIndex];this.history=[{ms:0,score:0}];this.endReason=null;this.lastUp=-1000;this.level=level;this.w=width;this.h=height;this.speed=SPEEDS[speed];this.emit=emit||function(){};this.rng=rng||Math.random;this.scale=baseScale(level,width,height);this.initialScale=this.scale;this.zoom=1;this.shake={offset:0,velocity:0,y:0,vy:0};this.shakeCount=0;this.hopCount=0;this.engine=M.Engine.create({enableSleeping:true});this.engine.gravity.y=this.speed.gravity;this.groups=[];this.queue=C.shuffle(level.regions.map(function(_,i){return i;}),this.rng);this.score=0;this.chain=0;this.maxChain=0;this.merges=0;this.dropped=0;this.clock=0;this.lastMerge=-99999;this.nextAt=0;this.overflow=0;this.status='ready';this.fx=[];this.impacts=[];this.collisionCount=0;this.wallHitUntil=0; +this.bounceIndex=BOUNCES[bounce]?bounce:0;this.bounce=BOUNCES[this.bounceIndex];this.history=[{ms:0,score:0}];this.endReason=null;this.lastUp=-1000;this.lastSwipe=-1000;this.level=level;this.w=width;this.h=height;this.speed=SPEEDS[speed];this.emit=emit||function(){};this.rng=rng||Math.random;this.scale=baseScale(level,width,height);this.initialScale=this.scale;this.zoom=1;this.shake={offset:0,velocity:0,y:0,vy:0};this.shakeCount=0;this.swipeCount=0;this.hopCount=0;this.engine=M.Engine.create({enableSleeping:true});this.engine.gravity.y=this.speed.gravity;this.groups=[];this.queue=C.shuffle(level.regions.map(function(_,i){return i;}),this.rng);this.score=0;this.chain=0;this.maxChain=0;this.merges=0;this.dropped=0;this.clock=0;this.lastMerge=-99999;this.nextAt=0;this.overflow=0;this.status='ready';this.fx=[];this.impacts=[];this.collisionCount=0;this.wallHitUntil=0; var self=this;M.Events.on(this.engine,'collisionStart',function(e){self.onContacts(e.pairs,true);});M.Events.on(this.engine,'collisionActive',function(e){self.onContacts(e.pairs,false);}); this.walls=[M.Bodies.rectangle(width/2,height+25,width+100,50,{isStatic:true}),M.Bodies.rectangle(-25,height/2,50,height*4,{isStatic:true}),M.Bodies.rectangle(width+25,height/2,50,height*4,{isStatic:true})];M.Composite.add(this.engine.world,this.walls); } @@ -52,6 +52,24 @@ Game.prototype.tryQueuedHops=function(){ M.Sleeping.set(g.body,false);var acceleration=this.speed.gravity*.001*Math.pow(1000/60,2);M.Body.setVelocity(g.body,{x:g.body.velocity.x,y:Math.min(g.body.velocity.y,-Math.sqrt(2*acceleration*height))});g.lastHop=this.clock;g.pendingHopUntil=-1;this.hopCount++; },this); }; +// One released flick delivers one short impulse with a spatial falloff. +// Every group moves; no piece is selected, grabbed or teleported by the finger. +Game.prototype.swipe=function(point,delta,elapsed){ + if(this.status!=='playing'||this.clock-this.lastSwipe<240||!point||!delta||![point.x,point.y,delta.x,delta.y,elapsed].every(Number.isFinite))return false; + var distance=Math.hypot(delta.x,delta.y);if(distance<18)return false; + var dt=Math.max(16,elapsed),speed=Math.min(2.8,distance/dt);if(speed<.16)return false;this.lastSwipe=this.clock;var power=(2.8+Math.min(5.5,speed*2.8))*Math.min(1.2,.6+distance/160); + var dx=delta.x/distance,dy=delta.y/distance,radius=Math.max(90,Math.min(180,this.w*.55)),acc=this.speed.gravity*.001*Math.pow(1000/60,2),maxUp=Math.sqrt(2*acc*this.riseLimit()); + this.shake.velocity=Math.max(-.6,Math.min(.6,this.shake.velocity+dx*power*.065));this.shake.vy=Math.max(-.48,Math.min(.48,this.shake.vy+dy*power*.05)); + this.groups.forEach(function(g){ + var body=g.body,bounds=M.Bounds.create(body.vertices),nearX=Math.max(bounds.min.x,Math.min(bounds.max.x,point.x)),nearY=Math.max(bounds.min.y,Math.min(bounds.max.y,point.y)); + var distance2=Math.pow(point.x-nearX,2)+Math.pow(point.y-nearY,2),local=.25+1.25*Math.exp(-2*distance2/(radius*radius)),weight=1/(1+(g.ids.length-1)*.12),impulse=power*local*weight*this.bounce.push*(.85+this.rng()*.3),spread=(this.rng()-.5)*.8,cos=Math.cos(spread),sin=Math.sin(spread),jx=dx*cos-dy*sin,jy=dx*sin+dy*cos; + if(body.isSleeping)g.supportedUntil=this.clock+80;M.Sleeping.set(body,false); + M.Body.setVelocity(body,{x:Math.max(-this.bounce.maxX,Math.min(this.bounce.maxX,body.velocity.x+jx*impulse)),y:Math.max(-maxUp,Math.min(MAX_FALL_SPEED,body.velocity.y+jy*impulse*.85))}); + if(dy<.4){g.pendingHopUntil=this.clock+300;g.pendingHopHeight=Math.min((16+speed*12)*this.bounce.hop*local*weight,this.riseLimit()*.92);} + M.Body.setAngularVelocity(body,Math.max(-.02,Math.min(.02,body.angularVelocity+dx*impulse*.0015))); + },this); + this.tryQueuedHops();this.swipeCount=(this.swipeCount||0)+1;this.shakeCount++;return true; +}; // Score events retain the exact active-play time; pauses never advance the clock. Game.prototype.recordScore=function(){var last=this.history[this.history.length-1];if(last.ms===this.clock){last.score=this.score;return;}this.history.push({ms:this.clock,score:this.score});}; Game.prototype.complete=function(reason){if(this.endReason)return false;this.endReason=reason;this.status=reason==='stopped'?'ended':reason;this.recordScore();this.emit('end',{won:reason==='won',reason:reason});return true;}; diff --git a/src/index.html b/src/index.html index ccf521a..36269c5 100644 --- a/src/index.html +++ b/src/index.html @@ -12,7 +12,7 @@
山河拼图SHAN HE · MAP PUZZLE
-
一片一片,认识中国

把山河,
拼在一起。

晃动这个框,
让相邻的山河,在碰撞中相遇。

34 个省级行政区 · 等你拼完整
←

左右轻摇,向上轻颠
晃动整个容器,碎片自动吸合

→
+
一片一片,认识中国

把山河,
拼在一起。

晃动这个框,
让相邻的山河,在碰撞中相遇。

34 个省级行政区 · 等你拼完整
←

轻划一下,晃动山河
晃动整个容器,碎片自动吸合

→
CHOOSE YOUR JOURNEY01

选择你的旅程

从一片故乡,出发去看山河。

@@ -26,10 +26,9 @@