blob: b74816fc6742ed20b66bd9caf96f946259077c16 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
from kennel.app import logger
from kennel.engine.components.component import ComponentType
from kennel.engine.entities.entity import EntityManager
from kennel.engine.systems.system import System, SystemType
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)
|