-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathlevelraycast.js
51 lines (45 loc) · 956 Bytes
/
levelraycast.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
// @ts-check
kaplay({
background: [31, 16, 42],
});
loadSprite("grass", "/sprites/grass.png");
const level = addLevel([
"===",
"= =",
"===",
], {
tileWidth: 64,
tileHeight: 64,
pos: vec2(256, 128),
tiles: {
"=": () => [
sprite("grass"),
area(),
],
},
});
level.use(rotate(45));
onLoad(() => {
level.spawn([
pos(
level.tileWidth() * 1.5,
level.tileHeight() * 1.5,
),
circle(6),
color("#ea6262"),
{
add() {
const rayHit = level.raycast(
this.pos,
Vec2.fromAngle(0).scale(100),
);
debug.log(
`${rayHit != null} ${
rayHit && rayHit.object ? rayHit.object.id : -1
}`,
);
},
},
]);
});
debug.inspect = true;