silphius/app/ecs-systems/clamp-positions.js
2024-07-02 10:22:25 -05:00

30 lines
600 B
JavaScript

import {System} from '@/ecs/index.js';
export default class ClampPositions extends System {
static get priority() {
return {
after: 'IntegratePhysics',
}
}
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;
}
}
}
}