-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs.js
90 lines (74 loc) · 2.25 KB
/
inputs.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
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
82
83
84
85
86
87
88
89
90
function keyDown(key) {
if (!lastKey.includes(key.code)) {
lastKeyTime[key.code] = 0;
lastKey.push(key.code);
gameTick(key.code)
}
};
function keyUp (key) {
if (lastKey.includes(key.code)) {
lastKey.splice(lastKey.indexOf(key.code), 1);
}
};
function gameTick(key) {
let pressed = false;
if (key == "KeyD") {
move(certainTetrimo, MOVE_DIER.right)
pressed = true;
} else if (key == "KeyA") {
move(certainTetrimo, MOVE_DIER.left)
pressed = true;
} else if (key == "KeyW") {
while (move(certainTetrimo, MOVE_DIER.down));
pressed = true;
clearFullLines(certainTetrimo, true);
newCertainTetrimo();
} else if (key == "KeyS") {
fallDown();
pressed = true;
} else if (key == "ArrowUp") {
rotation(certainTetrimo, true)
pressed = true;
} else if (key == "ArrowDown") {
rotation(certainTetrimo, false);
pressed = true;
} else if (key == "ShiftRight" || key == "ShiftLeft") {
switchHold(true);
pressed = true;
} else if (key == "KeyK"){
aiSwitchIntervall()
pressed = true;
}
if (pressed) {
preview(certainTetrimo);
}
};
function holdKeyCheck(){
lastKey.forEach(key =>{
if(lastKeyTime[key] > 15){
gameTick(key);
lastKeyTime[key] = 13;
} else lastKeyTime[key] ++;
});
};
// -- falling Speed range funcitons ----
function fallingSpeedChange(){
fallingSpeed = Number(document.getElementById("fallingSpeed").value)
switchFalling();
switchFalling();
};
function fallingSpeedChangeDisplay(){
document.getElementById("fallingSpeedDisplay").innerHTML = "Falling speed: " + document.getElementById("fallingSpeed").value + " rows per second"
};
fallingSpeedChangeDisplay()
// -- AI Speed range functions ----
function aiSpeedChange(){
aiSpeed = Number(document.getElementById("aiSpeed").value);
aiSwitchIntervall();
aiSwitchIntervall();
};
function aiSpeedChangeDisplay(){
document.getElementById("aiSpeedDisplay").innerHTML = "AI speed: " + document.getElementById("aiSpeed").value + " moves per second";
};
aiSpeedChangeDisplay();
setInterval(holdKeyCheck, 1000 / 60);