2023-08-25 18:48:17 -04:00
|
|
|
import { System, SystemNames } from '.';
|
|
|
|
import { BoundingBox, ComponentNames } from '../components';
|
|
|
|
import { Game } from '../Game';
|
|
|
|
import { clamp } from '../utils';
|
|
|
|
import { Miscellaneous } from '../config';
|
2023-07-20 23:47:32 -04:00
|
|
|
|
|
|
|
export class WallBounds extends System {
|
2023-08-25 18:48:17 -04:00
|
|
|
constructor() {
|
2023-07-20 23:47:32 -04:00
|
|
|
super(SystemNames.WallBounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
public update(_dt: number, game: Game) {
|
2023-08-12 15:49:16 -04:00
|
|
|
game.forEachEntityWithComponent(ComponentNames.WallBounded, (entity) => {
|
|
|
|
const boundingBox = entity.getComponent<BoundingBox>(
|
2023-08-25 18:48:17 -04:00
|
|
|
ComponentNames.BoundingBox
|
2023-08-12 15:49:16 -04:00
|
|
|
);
|
2023-07-20 23:47:32 -04:00
|
|
|
|
2023-08-12 15:49:16 -04:00
|
|
|
boundingBox.center.x = clamp(
|
|
|
|
boundingBox.center.x,
|
|
|
|
boundingBox.dimension.width / 2,
|
2023-08-25 18:48:17 -04:00
|
|
|
Miscellaneous.WIDTH - boundingBox.dimension.width / 2
|
2023-08-12 15:49:16 -04:00
|
|
|
);
|
|
|
|
});
|
2023-07-20 23:47:32 -04:00
|
|
|
}
|
|
|
|
}
|