jumpstorm/engine/systems/WallBounds.ts

26 lines
729 B
TypeScript
Raw Normal View History

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';
export class WallBounds extends System {
2023-08-25 18:48:17 -04:00
constructor() {
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-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
);
});
}
}