-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectWithInput.class.js
More file actions
70 lines (63 loc) · 1.76 KB
/
ObjectWithInput.class.js
File metadata and controls
70 lines (63 loc) · 1.76 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
import { GameObject } from './Object.class.js'
import { EngineStateMachine } from './EngineStateMachine.class.js';
var ObjectWithInput = function() {
var that = new GameObject();
that.camx = 0;
that.camy = 0;
that.updateCam = function() {
that.camx = round(that.x - window.cfg.screen_width / 2);
that.camy = round(that.y - window.cfg.screen_height / 2);
};
that.cam = function() {
that.updateCam();
//window.scrollTo(that.camx, that.camy);
};
that.hasInput = function() {
if(that.pressed_keys === 'undefined')
return false;
if(that.pressed_keys.length > 0)
return true;
};
that.keyUp = function() {
if(that.pressed_keys[that.pressed_keys.length-1] == that.assigned_keys[4])
return true;
};
that.key2Up = function() {
if(that.pressed_keys[that.pressed_keys.length-2] == that.assigned_keys[4])
return true;
};
that.keyLeft = function() {
if(that.pressed_keys[that.pressed_keys.length-1] == that.assigned_keys[0])
return true;
};
that.keyRight = function() {
if(that.pressed_keys[that.pressed_keys.length-1] == that.assigned_keys[1])
return true;
};
that.keyDown = function() {
if(that.pressed_keys[that.pressed_keys.length-1] == that.assigned_keys[2])
return true;
};
that.keySpace = function() {
if(that.pressed_keys == undefined)
return false;
if(that.pressed_keys.length == 0)
return false;
if(that.pressed_keys[that.pressed_keys.length-1] == that.assigned_keys[3]) {
return true;
}
return false;
};
that.keySpaceRelease = function() {
if(that.released_keys == undefined)
return false;
if(that.released_keys.length == 0)
return false;
if(that.released_keys[that.released_keys.length-1] == that.assigned_keys[3]) {
return true;
}
return false;
};
return that;
};
export { ObjectWithInput }