silphius/public/assets/tomato-seeds/projection-check.js
2024-07-07 17:32:54 -05:00

29 lines
649 B
JavaScript

const layer = ecs.get(1).TileLayers.layer(1)
const filtered = []
for (let i = 0; i < projected.length; ++i) {
const x0 = projected[i].x * layer.tileSize.x;
const y0 = projected[i].y * layer.tileSize.y;
const entities = Array.from(ecs.system('Colliders').within({
x0,
x1: x0 + layer.tileSize.x - 1,
y0,
y1: y0 + layer.tileSize.y - 1,
}));
let hasPlant = false;
for (let j = 0; j < entities.length; ++j) {
if (entities[j].Plant) {
hasPlant = true
}
}
if (!hasPlant) {
const tile = layer.tile(projected[i])
if ([7].includes(tile)) {
filtered.push(projected[i])
}
}
}
return filtered