Skip to content

Commit

Permalink
fix: initializate pos with tilepos
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Sep 9, 2024
1 parent e0bd34a commit 8d542ba
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/game/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export function addLevel(
if (comp.id === "pos") hasPos = true;
}

if (!hasPos) comps.push(pos());
if (!hasPos) comps.push(pos(this.tile2Pos(p)));
if (!hasTile) comps.push(tile());

const obj = level.add(comps);
Expand Down Expand Up @@ -415,9 +415,15 @@ export function addLevel(
return spatialMap![hash] || [];
},

raycast(this: GameObj<LevelComp | PosComp>, origin: Vec2, direction: Vec2) {
raycast(
this: GameObj<LevelComp | PosComp>,
origin: Vec2,
direction: Vec2,
) {
const worldOrigin = this.toWorld(origin);
const worldDirection = this.toWorld(origin.add(direction)).sub(worldOrigin);
const worldDirection = this.toWorld(origin.add(direction)).sub(
worldOrigin,
);
const levelOrigin = origin.scale(
1 / this.tileWidth(),
1 / this.tileHeight(),
Expand Down

0 comments on commit 8d542ba

Please sign in to comment.