silphius/public/assets/tomato-seeds/projection-check.js
2024-07-12 18:32:55 -05:00

29 lines
593 B
JavaScript

const layer = ecs.get(1).TileLayers.layer(1)
const filtered = []
for (const position of projected) {
const x0 = position.x * layer.tileSize.x;
const y0 = position.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 (const {Plant} of entities) {
if (Plant) {
hasPlant = true
break;
}
}
if (!hasPlant) {
if ([7].includes(layer.tile(position))) {
filtered.push(position)
}
}
}
return filtered