feat: shake the puzzle tank with single flick gestures
This commit is contained in:
@@ -34,3 +34,25 @@ test('四档下落速度下,实测上晃分别为轻弹、正常和强弹,
|
||||
|
||||
test('左右晃动会缓存请求,碎片在两次150ms按键之间落地也能颠起',()=>{const l={id:'100000',name:'落地时序',width:1000,height:1000,regions:[square(0,0,0)],edges:[]};for(const delay of [0,25,60,100]){const g=new Game(l,320,590,0,()=>{},()=>.5,1);g.start();g.queue=[];g.clock=delay;const p=g.groups[0],b=p.body;M.Body.translate(b,{x:0,y:g.h-6-b.bounds.max.y});M.Body.setVelocity(b,{x:0,y:1});assert.ok(g.nudge(1));assert.equal(g.hopCount,0,'尚未接触时不在空中加速');for(let i=0;i<9;i++)g.tick(1000/60);assert.equal(g.hopCount,1,'下一次按键前已在落地时触发');assert.ok(b.velocity.y<0);g.destroy();}});
|
||||
test('过期请求、空中长按和暂停不会凭空产生连续上抛',()=>{const l={id:'100000',name:'时序限制',width:1000,height:1000,regions:[square(0,0,0)],edges:[]},g=new Game(l,320,590,0,()=>{},()=>.5,1);g.start();g.queue=[];g.nudge(1);for(let i=0;i<180;i++)g.tick(1000/60);assert.equal(g.hopCount,0,'初始空中请求已过期');g.status='paused';assert.equal(g.nudge(1),false);const count=g.hopCount;g.tick(100);assert.equal(g.hopCount,count);g.destroy();});
|
||||
|
||||
test('容器滑动按位置分配力度:附近更强,远处仍动,没有瞬移或单片抓取',()=>{
|
||||
const l={id:'100000',name:'位置力度',width:1000,height:1000,regions:[square(0,0,0),square(1,300,0)],edges:[]},g=new Game(l,420,560,0,()=>{},()=>.5,1);g.status='playing';g.queue=[];
|
||||
const near=g.createGroup([0],{tx:0,ty:0,angle:0}),far=g.createGroup([1],{tx:0,ty:0,angle:0});M.Body.setPosition(near.body,{x:90,y:200});M.Body.setPosition(far.body,{x:330,y:420});const positions=g.groups.map(p=>({...p.body.position}));
|
||||
assert.ok(g.swipe({x:90,y:200},{x:30,y:-10},32));assert.ok(near.body.velocity.x>far.body.velocity.x*3);assert.ok(far.body.velocity.x>0);assert.ok(near.body.velocity.y<far.body.velocity.y&&far.body.velocity.y<0);assert.deepEqual(g.groups.map(p=>({...p.body.position})),positions);assert.equal(g.swipeCount,1);g.tick(16.67);assert.ok(g.shake.offset>0);assert.ok(g.shake.y<0);g.destroy();
|
||||
});
|
||||
test('同样距离快速划动更有力;轻触、无效输入与暂停不触发晃动',()=>{
|
||||
const run=elapsed=>{const g=game();g.start();g.queue=[];const body=g.groups[0].body,p={...body.position};g.swipe(p,{x:24,y:0},elapsed);const vx=body.velocity.x;g.destroy();return vx;};assert.ok(run(16)>run(64)*1.3);
|
||||
const g=game();g.start();const p={x:200,y:200};assert.equal(g.swipe(p,{x:.1,y:.1},16),false);assert.equal(g.swipe(p,{x:NaN,y:0},16),false);assert.equal(g.swipe(p,{x:20,y:0},Infinity),false);g.status='paused';assert.equal(g.swipe(p,{x:20,y:0},16),false);assert.equal(g.swipeCount,0);g.destroy();
|
||||
});
|
||||
test('三档弹性连续任意方向滑动不超速、穿墙、旋转失控,落地滑动能颠起',()=>{
|
||||
const l={id:'100000',name:'滑动边界',width:1000,height:1000,regions:[square(0,0,0)],edges:[]};for(let bounce=0;bounce<3;bounce++){
|
||||
const g=new Game(l,320,590,0,()=>{},()=>.5,bounce);g.start();g.queue=[];const b=g.groups[0].body;M.Body.translate(b,{x:0,y:g.h-1-b.bounds.max.y});M.Sleeping.set(b,true);g.swipe({...b.position},{x:30,y:0},32);assert.ok(b.velocity.y<0,'落地碎片有上弹反馈');
|
||||
for(let i=0;i<600;i++){g.swipe({x:160,y:450},{x:Math.sin(i*.13)*300,y:Math.cos(i*.17)*300},16.67);g.tick(16.67);const real=M.Bounds.create(b.vertices);assert.ok(Math.abs(b.velocity.x)<=g.bounce.maxX+.001);assert.ok(b.velocity.y<=9.001);assert.ok(Math.abs(b.angle)<=.1601);assert.ok(real.min.x>=-3&&real.max.x<=g.w+3&&real.max.y<=g.h+4);assert.ok(g.impacts.length<=20);}g.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('每次划动只给一次冲量,短间隔限频,地块方向有分散且随后自由运动',()=>{
|
||||
const l={id:'100000',name:'单次惯性',width:1000,height:1000,regions:[square(0,0,0),square(1,300,0)],edges:[]};let seq=0;const g=new Game(l,420,560,0,()=>{},()=>[.1,.9,.9,.1][seq++%4],1);g.status='playing';g.queue=[];
|
||||
const a=g.createGroup([0],{tx:0,ty:100,angle:0}),b=g.createGroup([1],{tx:0,ty:100,angle:0});M.Body.setPosition(a.body,{x:120,y:200});M.Body.setPosition(b.body,{x:260,y:200});assert.ok(g.swipe({x:190,y:200},{x:70,y:0},100));assert.ok(a.body.velocity.x>0&&b.body.velocity.x>0);assert.ok(a.body.velocity.y*b.body.velocity.y<0,'相同大方向下有不同偏转');
|
||||
const pos={...a.body.position};assert.equal(g.swipe({x:120,y:200},{x:-70,y:0},100),false);for(let i=0;i<15;i++)g.tick(16.67);assert.equal(g.swipeCount,1);assert.notDeepEqual(a.body.position,pos);assert.ok(g.swipe({x:120,y:200},{x:70,y:0},100));assert.equal(g.swipeCount,2);g.destroy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user