silphius/app/ecs-systems/clamp-positions.js
2024-06-22 12:30:25 -05:00

24 lines
517 B
JavaScript

import {System} from '@/ecs/index.js';
export default class ClampPositions extends System {
tick() {
const {AreaSize} = this.ecs.get(1);
for (const {Position} of this.ecs.changed(['Position'])) {
if (Position.x < 0) {
Position.x = 0;
}
if (Position.y < 0) {
Position.y = 0;
}
if (Position.x >= AreaSize.x) {
Position.x = AreaSize.x - 0.0001;
}
if (Position.y >= AreaSize.y) {
Position.y = AreaSize.y - 0.0001;
}
}
}
}