|
|
@ -8,6 +8,8 @@ |
|
|
|
const nav=main.querySelector('nav'); |
|
|
|
const nav=main.querySelector('nav'); |
|
|
|
const canvas=main.querySelector('canvas'); |
|
|
|
const canvas=main.querySelector('canvas'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const config=assets.get('config'); |
|
|
|
|
|
|
|
|
|
|
|
let currentGame=null; |
|
|
|
let currentGame=null; |
|
|
|
let currentInputs={}; |
|
|
|
let currentInputs={}; |
|
|
|
|
|
|
|
|
|
|
@ -61,12 +63,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
const magnitude=Math.hypot(gp.axes[0], gp.axes[1]); |
|
|
|
const magnitude=Math.hypot(gp.axes[0], gp.axes[1]); |
|
|
|
const angle=((Math.atan2(gp.axes[0], gp.axes[1])+2*Math.PI)%(2*Math.PI))/Math.PI; |
|
|
|
const angle=((Math.atan2(gp.axes[0], gp.axes[1])+2*Math.PI)%(2*Math.PI))/Math.PI; |
|
|
|
if(magnitude>.5) { |
|
|
|
if(magnitude>config.gamepad.deadzone) { |
|
|
|
if(angle>.25 && angle <.75) inputs.right=true; |
|
|
|
if(angle>.25 && angle <.75) inputs.right=true; |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!config.gamepad.buffer) inputs.clearBuffer=true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('hashchange', async () => { |
|
|
|
window.addEventListener('hashchange', async () => { |
|
|
@ -105,23 +109,51 @@ |
|
|
|
else if(e.key=='ArrowDown') inputs.down=true; |
|
|
|
else if(e.key=='ArrowDown') inputs.down=true; |
|
|
|
else if(e.key=='ArrowLeft') inputs.left=true; |
|
|
|
else if(e.key=='ArrowLeft') inputs.left=true; |
|
|
|
else if(e.key=='ArrowRight') inputs.right=true; |
|
|
|
else if(e.key=='ArrowRight') inputs.right=true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!config.keyboard.buffer) inputs.clearBuffer=true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const handleTouch=e => { |
|
|
|
if(config.touchscreen.mode=='crosspad') { |
|
|
|
e.preventDefault(); |
|
|
|
const handleTouch=e => { |
|
|
|
let x=e.touches[0].clientX-window.innerWidth/2; |
|
|
|
let x=e.touches[0].clientX-window.innerWidth/2; |
|
|
|
let y=e.touches[0].clientY-window.innerHeight/2; |
|
|
|
let y=e.touches[0].clientY-window.innerHeight/2; |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
let inputs=currentInputs; |
|
|
|
let inputs=currentInputs; |
|
|
|
if(angle>.25 && angle <.75) inputs.right=true; |
|
|
|
if(angle>.25 && angle <.75) inputs.right=true; |
|
|
|
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; |
|
|
|
if(!config.touchscreen.buffer) inputs.clearBuffer=true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
window.addEventListener('touchstart', handleTouch); |
|
|
|
window.addEventListener('touchstart', handleTouch); |
|
|
|
window.addEventListener('touchmove', handleTouch); |
|
|
|
window.addEventListener('touchmove', handleTouch); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(config.touchscreen.mode=='joystick') { |
|
|
|
|
|
|
|
let center={x: 0, y: 0}; |
|
|
|
|
|
|
|
window.center=center; |
|
|
|
|
|
|
|
window.addEventListener('touchstart', e => { |
|
|
|
|
|
|
|
center.x=e.touches[0].clientX; |
|
|
|
|
|
|
|
center.y=e.touches[0].clientY; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
window.addEventListener('touchmove', e => { |
|
|
|
|
|
|
|
let x=e.touches[0].clientX-center.x; |
|
|
|
|
|
|
|
let y=e.touches[0].clientY-center.y; |
|
|
|
|
|
|
|
const angle=((Math.atan2(x, y)+2*Math.PI)%(2*Math.PI))/Math.PI; |
|
|
|
|
|
|
|
const magnitude=Math.hypot(x, y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let inputs=currentInputs; |
|
|
|
|
|
|
|
if(magnitude>config.touchscreen.deadzone) { |
|
|
|
|
|
|
|
if(angle>.25 && angle <.75) inputs.right=true; |
|
|
|
|
|
|
|
else if(angle>.75 && angle<1.25) inputs.up=true; |
|
|
|
|
|
|
|
else if(angle>1.25 && angle<1.75) inputs.left=true; |
|
|
|
|
|
|
|
else inputs.down=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!config.touchscreen.buffer) inputs.clearBuffer=true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
})(); |
|
|
|
})(); |
|
|
|