-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboard Input Getter
102 lines (98 loc) · 2.13 KB
/
Keyboard Input Getter
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
91
92
93
94
95
96
97
98
99
100
101
102
var xVel = 0;
var yVel = 0;
var keys = [false, false, false, false];
// keys is an array that represents whether a certain
// key is currently pressed
// keys[0] -> left
// keys[1] -> right
// keys[2] -> up
// keys[3] -> down
onEvent("button1", "click", function(event) {
setScreen("screen2");
timedLoop(17, function() {
xVel = 0;
yVel = 0;
if (keys[0]) {
xVel += -5;
}
if (keys[1]) {
xVel += 5;
}
if (keys[2]) {
yVel += -5;
}
if (keys[3]) {
yVel += 5;
}
setPosition("image1", getXPosition("image1")+xVel, getYPosition("image1")+yVel);
});
});
onEvent("screen2", "keydown", function(event) {
if (event.key == "Up") {
keys[2] = true;
} else if ((event.key == "Down")) {
keys[3] = true;
} else if ((event.key == "Left")) {
keys[0] = true;
} else if ((event.key == "Right")) {
keys[1] = true;
}
});
onEvent("screen2", "keyup", function(event) {
if (event.key == "Up") {
keys[2] = false;
} else if ((event.key == "Down")) {
keys[3] = false;
} else if ((event.key == "Left")) {
keys[0] = false;
} else if ((event.key == "Right")) {
keys[1] = false;
}
});
//
//
//
//modified vesion for pen up and down
//
//
onEvent("button10", "click", function(event) {
timedLoop(17, function() {
xVel = 0;
yVel = 0;
if (keys[0]) {
xVel += -5;
}
if (keys[1]) {
xVel += 5;
}
if (keys[2]) {
yVel += -5;
}
if (keys[3]) {
yVel += 5;
}
moveTo(getX()+xVel, getY()+yVel);
});
});
onEvent("screen2", "keydown", function(event) {
if (event.key == ("w" || "Up")) {
keys[2] = true;
} else if ((event.key == ("s" || "Down"))) {
keys[3] = true;
} else if ((event.key == ("a" || "Left"))) {
keys[0] = true;
} else if ((event.key == ("d" || "Right"))) {
keys[1] = true;
}
});
onEvent("screen2", "keyup", function(event) {
if (event.key == ("w" || "Up")) {
keys[2] = false;
} else if ((event.key == ("s" || "Dowm"))) {
keys[3] = false;
} else if ((event.key == ("a" || "Left"))) {
keys[0] = false;
} else if ((event.key == ("d" || "Right"))) {
keys[1] = false;
}
});