-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.js
87 lines (75 loc) · 2.15 KB
/
input.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
import Keyboard from "./keyboard.js";
import Configs from "./configs.js"
import Colors, { nextColor } from "./colors.js";
export default class Input
{
constructor()
{
this.Keyboard = Keyboard;
this.keysPressed = [];
this.keysUp = [];
}
update(game)
{
if (this.keyup(Keyboard.KEY_2))
{
Configs.render.clipping = !Configs.render.clipping
console.log('Note: Clipping Mode: ', Configs.render.clipping)
}
if (this.keyup(Keyboard.KEY_3))
{
Configs.render.fakeNormals = !Configs.render.fakeNormals
console.log('Note: FakeNormals Mode: ', Configs.render.fakeNormals)
}
if (this.keyup(Keyboard.KEY_5))
{
Configs.render.drawLines = !Configs.render.drawLines
console.log('drawLines mode', Configs.render.drawLines)
}
if (this.keyup(Keyboard.KEY_6))
{
Configs.render.fill = !Configs.render.fill
console.log('Note: Fill traingles: ', Configs.render.fill)
}
// clear Up keys (important)
this.keysUp = []
}
keypress(keyCode)
{
//console.log(keyCode)
return this.keysPressed.includes(keyCode);
}
keyup(keyCode)
{
//console.log(keyCode)
return this.keysUp.includes(keyCode);
}
capturePressKeys(e)
{
e.preventDefault();
let keyCode = e.which || e.keyCode;
if (!this.keysPressed.includes(keyCode))
this.keysPressed.push(keyCode);
}
capturnDownKeys(e)
{
let keyCode = e.which || e.keyCode;
if (!this.keysPressed.includes(keyCode))
this.keysPressed.push(keyCode);
}
capturnUpKeys(e)
{
let keyCode = e.which || e.keyCode;
if (this.keysPressed.includes(keyCode))
{
// remove the key here
this.keysPressed.splice(this.keysPressed.indexOf(keyCode), 1);
this.keysUp.push(keyCode)
}
}
clear()
{
// we dont need to clear keysPressed (capturnUpKeys handles this for us)
//this.keysPressed = [];
}
}