From 6f374aac7f4d553c484eecc77c9599be79f2d834 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Tue, 20 Aug 2024 18:17:33 -0700 Subject: send the initial state to clients --- kennel/engine/systems/world.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 kennel/engine/systems/world.py (limited to 'kennel/engine/systems/world.py') diff --git a/kennel/engine/systems/world.py b/kennel/engine/systems/world.py new file mode 100644 index 0000000..396e7cb --- /dev/null +++ b/kennel/engine/systems/world.py @@ -0,0 +1,24 @@ +from kennel.engine.systems.system import System, SystemType +from kennel.engine.entities.entity import EntityManager +from kennel.engine.components.component import ComponentType +from kennel.app import logger + + +class WorldSystem(System): + def __init__(self, width: int, height: int): + super().__init__(SystemType.WORLD) + self.width = width + self.height = height + + async def update(self, entity_manager: EntityManager, delta_time: float): + entities = entity_manager.get_entities_with_component(ComponentType.POSITION) + for entity in entities: + position = entity.get_component(ComponentType.POSITION) + if position is None: + logger.error(f"Entity {entity} has no position component") + continue + + position.x = max(0, min(self.width, position.x)) + position.y = max(0, min(self.height, position.y)) + + entity.add_component(position) -- cgit v1.3