Compare commits

...

4 commits

5 changed files with 92 additions and 10 deletions

View file

@ -1,11 +1,42 @@
{ {
"dimensions": [32, 32], "world": [
" w ",
" w ",
" wwwwwww w wwwwwww ",
" w w ",
" w w ",
" w wwwwwwwwwwwww w ",
" w w ",
" w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
"www w wwwwwwwwwwwwwww w www",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w ",
" w w ",
" w wwwwwwwwwwwww w ",
" w w ",
" w w ",
" wwwwwww w wwwwwww ",
" w ",
" w "
],
"delay": 200, "delay": 200,
"food": [],
"snake": [ "snake": [
[16, 12], [16, 3],
[16, 11], [15, 3],
[16, 10] [14, 3]
], ],
"rules": { "rules": {
"worldWrap": false, "worldWrap": false,

View file

@ -19,5 +19,5 @@
[6,8], [6,8],
[6,9] [6,9]
], ],
"delay": 100 "delay": 150
} }

41
levels/level3.json Normal file
View file

@ -0,0 +1,41 @@
{
"world": [
" w ",
" w ",
" wwwwwww w wwwwwww ",
" w f w ",
" w w ",
" w wwwwwwwwwwwww w ",
" w w ",
" w f w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
"wwwf w fwwwwwwwwwwwwwwwf w fwww",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w w w ",
" w f w ",
" w w ",
" w wwwwwwwwwwwww w ",
" w w ",
" w f w ",
" wwwwwww w wwwwwww ",
" w ",
" w "
],
"delay": 200,
"snake": [
[16, 4],
[15, 4],
[14, 4]
]
}

View file

@ -90,11 +90,10 @@
} }
}; };
currentGame=snek; currentGame=snek;
//XXX
window.snek=snek;
}); });
window.addEventListener('keydown', async e => { window.addEventListener('keydown', async e => {
e.preventDefault();
if(e.key=='f') { if(e.key=='f') {
if(document.fullscreenElement) await document.exitFullscreen(); if(document.fullscreenElement) await document.exitFullscreen();
else await main.requestFullscreen(); else await main.requestFullscreen();
@ -108,7 +107,8 @@
else if(e.key=='ArrowRight') inputs.right=true; else if(e.key=='ArrowRight') inputs.right=true;
}); });
window.addEventListener('touchstart', e => { const handleTouch=e => {
e.preventDefault();
let x=e.touches[0].clientX/window.innerWidth-.5; let x=e.touches[0].clientX/window.innerWidth-.5;
let y=e.touches[0].clientY/window.innerHeight-.5; let y=e.touches[0].clientY/window.innerHeight-.5;
const angle=((Math.atan2(x, y)+2*Math.PI)%(2*Math.PI))/Math.PI; const angle=((Math.atan2(x, y)+2*Math.PI)%(2*Math.PI))/Math.PI;
@ -118,6 +118,10 @@
else if(angle>.75 && angle<1.25) inputs.up=true; else if(angle>.75 && angle<1.25) inputs.up=true;
else if(angle>1.25 && angle<1.75) inputs.left=true; else if(angle>1.25 && angle<1.75) inputs.left=true;
else inputs.down=true; else inputs.down=true;
});
inputs.clearBuffer=true;
};
window.addEventListener('touchstart', handleTouch);
window.addEventListener('touchmove', handleTouch);
})(); })();

View file

@ -322,6 +322,12 @@ class SnekGame {
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;
else if(inputs.down && trySet([ 0, 1])) return delete inputs.down; else if(inputs.down && trySet([ 0, 1])) return delete inputs.down;
if(inputs.clearBuffer) {
Object
.keys(inputs)
.forEach(k => delete inputs[k]);
}
} }
start() { start() {