-
Notifications
You must be signed in to change notification settings - Fork 1
/
controls.js
executable file
·36 lines (32 loc) · 938 Bytes
/
controls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
canvas.on('mousemove', e => {
e.preventDefault();
if (started) {
const pos = (e.clientX - $(window).width() / 2) / (($(window).width() < 450 ? $(window).width() : 450) / 5);
if (pos >= -3.5 && pos <= 3.5) {
ball.mesh.position.x = pos;
camera.position.x = pos / 7;
}
}
});
canvas.on('touchmove', e => {
e.preventDefault();
if (started) {
const pos =
(e.changedTouches[0].pageX - $(window).width() / 2) / (($(window).width() < 450 ? $(window).width() : 450) / 5);
if (pos >= -3.5 && pos <= 3.5) {
ball.mesh.position.x = pos;
camera.position.x = pos / 7;
}
}
});
$(window).on('keydown', e => {
if (started && !ball.count2Lose) keystate[e.keyCode] = true;
});
$(window).on('keyup', e => {
delete keystate[e.keyCode];
});
$(window).on('resize', e => {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});