-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
70 lines (66 loc) · 2.02 KB
/
input.js
File metadata and controls
70 lines (66 loc) · 2.02 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
var Input = (function() {
var left = false,
right = false,
up = false,
down = false,
action = false,
crafting = false,
throwItem = false,
mouseScroll = 0;
document.onkeydown = function (evt) {
var event = evt || window.event;
//console.log("code: "+ event.keyCode);
if (event.keyCode == 65) {
left = true;
} else if (event.keyCode == 68) {
right = true;
} else if (event.keyCode == 87) {
up = true;
} else if (event.keyCode == 83) {
down = true;
}else if (event.keyCode == 32) {
action = true;
}else if (event.keyCode == 9||event.keyCode == 69) {
crafting = true;
}else if (event.keyCode == 81) {
throwItem = true;
console.log("Entered")
}
};
document.onkeyup = function (evt) {
evt = evt || window.event;
var event = evt || window.event;
if (event.keyCode == 65) {
left = false;
} else if (event.keyCode == 68) {
right = false;
} else if (event.keyCode == 87) {
up = false;
} else if (event.keyCode == 83) {
down = false;
}else if (event.keyCode == 32) {
action = false;
}else if (event.keyCode == 9||event.keyCode == 69) {
crafting = false;
}else if (event.keyCode == 81) {
throwItem = false;
}
};
var onMouseWheel = function(evt){
var e = window.event || e; // old IE support
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
mouseScroll = delta;
};
document.addEventListener("mousewheel", onMouseWheel, false);
return {
upPressed: function() { return up; },
downPressed: function() { return down; },
leftPressed: function() { return left; },
rightPressed: function() { return right; },
actionPressed: function() { return action; },
craftingPressed: function() { return crafting; },
craftingUnPress: function() { crafting =false; },
mouseScroll: function() { var m = mouseScroll; mouseScroll =0;return m; },
throwPressed: function() { var s = throwItem;throwItem = false;return s; }
};
})();