From 0fd9fb097552686f2257c1aa689d797e80057bd1 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 19 Jul 2023 20:38:24 -0700 Subject: initial commit --- client/lib/systems/WallBounds.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 client/lib/systems/WallBounds.ts (limited to 'client/lib/systems/WallBounds.ts') diff --git a/client/lib/systems/WallBounds.ts b/client/lib/systems/WallBounds.ts new file mode 100644 index 0000000..3fd5dc4 --- /dev/null +++ b/client/lib/systems/WallBounds.ts @@ -0,0 +1,35 @@ +import { System, SystemNames } from "."; +import { BoundingBox, ComponentNames } from "../components"; +import type { Entity } from "../entities"; + +export class WallBounds extends System { + private screenWidth: number; + + constructor(screenWidth: number) { + super(SystemNames.WallBounds); + + this.screenWidth = screenWidth; + } + + public update( + _dt: number, + entityMap: Map, + componentEntities: Map> + ) { + componentEntities.get(ComponentNames.WallBounded)?.forEach((entityId) => { + const entity = entityMap.get(entityId); + if (!entity.hasComponent(ComponentNames.BoundingBox)) { + return; + } + + const boundingBox = entity.getComponent( + ComponentNames.BoundingBox + ); + + boundingBox.center.x = Math.min( + this.screenWidth - boundingBox.dimension.width / 2, + Math.max(boundingBox.dimension.width / 2, boundingBox.center.x) + ); + }); + } +} -- cgit v1.3