fixed engine to limit input buffering in time

This commit is contained in:
Nathan DECHER 2020-03-26 10:46:50 +01:00
parent de390dff8a
commit 10585fef98

View file

@ -82,7 +82,9 @@ class SnekGame {
worldWrap: true, worldWrap: true,
winCondition: 'none', winCondition: 'none',
scoreSystem: 'fruit', scoreSystem: 'fruit',
netPlay: false netPlay: false,
autoSizeGrow: false,
autoSpeedIncrease: false
}, rules, settings.rules || {}); }, rules, settings.rules || {});
} }
@ -305,6 +307,17 @@ class SnekGame {
return true; return true;
} }
} }
Object
.keys(inputs)
.forEach(k => {
let v=inputs[k];
if(v===true) v=5;
v--;
if(!v) delete inputs[k];
else inputs[k]=v;
});
if(inputs.left && trySet([-1, 0])) return delete inputs.left; if(inputs.left && trySet([-1, 0])) return delete inputs.left;
else if(inputs.right && trySet([ 1, 0])) return delete inputs.right; else if(inputs.right && trySet([ 1, 0])) return delete inputs.right;
else if(inputs.up && trySet([ 0,-1])) return delete inputs.up; else if(inputs.up && trySet([ 0,-1])) return delete inputs.up;