silphius/public/assets/tomato-seeds/projection-check.js

29 lines
593 B
JavaScript
Raw Normal View History

2024-07-07 17:32:54 -05:00
const layer = ecs.get(1).TileLayers.layer(1)
2024-06-28 12:12:38 -05:00
const filtered = []
2024-07-12 17:41:55 -05:00
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({
2024-07-02 14:41:54 -05:00
x0,
x1: x0 + layer.tileSize.x - 1,
y0,
y1: y0 + layer.tileSize.y - 1,
}));
2024-06-28 14:36:49 -05:00
let hasPlant = false;
2024-07-12 17:41:55 -05:00
for (const {Plant} of entities) {
if (Plant) {
2024-06-28 14:36:49 -05:00
hasPlant = true
2024-07-12 18:32:55 -05:00
break;
2024-06-28 14:36:49 -05:00
}
}
if (!hasPlant) {
2024-07-12 17:41:55 -05:00
if ([7].includes(layer.tile(position))) {
filtered.push(position)
2024-06-28 14:36:49 -05:00
}
2024-06-28 12:12:38 -05:00
}
}
return filtered