fixed engine to limit input buffering in time

Nathan DECHER 5 years ago
parent de390dff8a
commit 10585fef98
  1. 15
      src/js/snek.js

@ -82,7 +82,9 @@ class SnekGame {
worldWrap: true,
winCondition: 'none',
scoreSystem: 'fruit',
netPlay: false
netPlay: false,
autoSizeGrow: false,
autoSpeedIncrease: false
}, rules, settings.rules || {});
}
@ -305,6 +307,17 @@ class SnekGame {
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;
else if(inputs.right && trySet([ 1, 0])) return delete inputs.right;
else if(inputs.up && trySet([ 0,-1])) return delete inputs.up;

Loading…
Cancel
Save