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