-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathquery.js
92 lines (80 loc) · 1.87 KB
/
query.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
91
92
// @ts-check
kaplay();
loadSprite("bean", "/sprites/bean.png");
loadSprite("ghosty", "/sprites/ghosty.png");
const bean = add([
pos(50, 50),
sprite("bean"),
color(WHITE),
"bean",
]);
add([
pos(200, 50),
sprite("ghosty"),
color(WHITE),
"ghosty",
]);
add([
pos(400, 50),
sprite("ghosty"),
color(WHITE),
"ghosty",
]);
add([
pos(100, 250),
sprite("ghosty"),
color(WHITE),
"ghosty",
named("Candy&Carmel"),
]);
function makeButton(p, t, cb) {
const button = add([
pos(p),
rect(150, 40, { radius: 5 }),
anchor("center"),
color(WHITE),
area(),
"button",
]);
button.add([
text(t),
color(BLACK),
anchor("center"),
area(),
]);
button.onClick(() => {
get("button").forEach(o => o.color = WHITE);
button.color = GREEN;
cb();
});
}
makeButton(vec2(200, 400), "bean", () => {
get("sprite").forEach(o => o.color = WHITE);
query({ include: "bean" }).forEach(o => o.color = RED);
});
makeButton(vec2(360, 400), "ghosty", () => {
get("sprite").forEach(o => o.color = WHITE);
query({ include: "ghosty" }).forEach(o => o.color = RED);
});
makeButton(vec2(200, 450), "near", () => {
get("sprite").forEach(o => o.color = WHITE);
bean.query({
distance: 150,
distanceOp: "near",
hierarchy: "siblings",
exclude: "button",
}).forEach(o => o.color = RED);
});
makeButton(vec2(360, 450), "far", () => {
get("sprite").forEach(o => o.color = WHITE);
bean.query({
distance: 150,
distanceOp: "far",
hierarchy: "siblings",
exclude: "button",
}).forEach(o => o.color = RED);
});
makeButton(vec2(520, 400), "name", () => {
get("sprite").forEach(o => o.color = WHITE);
query({ name: "Candy&Carmel" }).forEach(o => o.color = RED);
});