Skip to content

Commit

Permalink
Test for level raycast
Browse files Browse the repository at this point in the history
  • Loading branch information
mflerackers committed Sep 8, 2024
1 parent b2c46af commit baf5e68
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/levelraycast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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

0 comments on commit baf5e68

Please sign in to comment.