-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
81 lines (73 loc) · 1.94 KB
/
input.js
File metadata and controls
81 lines (73 loc) · 1.94 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Input handler for player controls
class InputHandler {
constructor(player) {
this.player = player;
this.inputCooldown = 0;
this.lastKeyStates = {};
}
// Handle continuous input with cooldown system
handleContinuousInput() {
this.inputCooldown++;
// Key mappings for wave control
const keys = {
w: {
pressed: keyIsDown(87) || keyIsDown(119), // W/w
action: () => {
this.player.increaseAmplitude();
blueKnob.nextFrame();
},
},
s: {
pressed: keyIsDown(83) || keyIsDown(115), // S/s
action: () => {
this.player.decreaseAmplitude();
blueKnob.nextFrame();
},
},
a: {
pressed: keyIsDown(65) || keyIsDown(97), // A/a
action: () => {
this.player.decreaseFrequency();
redKnob.nextFrame();
},
},
d: {
pressed: keyIsDown(68) || keyIsDown(100), // D/d
action: () => {
this.player.increaseFrequency();
redKnob.nextFrame();
},
},
};
let anyJustPressed = false;
// Process each key
for (const [key, keyData] of Object.entries(keys)) {
const justPressed = keyData.pressed && !this.lastKeyStates[key];
// Handle instant presses
if (justPressed) {
keyData.action();
anyJustPressed = true;
}
// Handle continuous presses (with cooldown)
else if (
this.inputCooldown >= CONFIG.inputCooldownMax &&
keyData.pressed &&
!anyJustPressed
) {
keyData.action();
}
// Save current key state
this.lastKeyStates[key] = keyData.pressed;
}
// Reset cooldown timer when action performed
if (anyJustPressed || this.inputCooldown >= CONFIG.inputCooldownMax) {
this.inputCooldown = 0;
}
}
// Handle single key presses
handleKeyPressed() {
if (key === " ") {
this.player.reset();
}
}
}