aboutsummaryrefslogtreecommitdiff
path: root/kennel/engine/systems
diff options
context:
space:
mode:
Diffstat (limited to 'kennel/engine/systems')
-rw-r--r--kennel/engine/systems/network.py1
-rw-r--r--kennel/engine/systems/system.py1
-rw-r--r--kennel/engine/systems/world.py24
3 files changed, 26 insertions, 0 deletions
diff --git a/kennel/engine/systems/network.py b/kennel/engine/systems/network.py
index 7df8088..c9696c8 100644
--- a/kennel/engine/systems/network.py
+++ b/kennel/engine/systems/network.py
@@ -6,6 +6,7 @@ import asyncio
class EventType(str, Enum):
+ INITIAL_STATE = "INITIAL_STATE"
ENTITY_BORN = "ENTITY_BORN"
ENTITY_POSITION_UPDATE = "ENTITY_POSITION_UPDATE"
ENTITY_DEATH = "ENTITY_DEATH"
diff --git a/kennel/engine/systems/system.py b/kennel/engine/systems/system.py
index 0e51f3a..78bda58 100644
--- a/kennel/engine/systems/system.py
+++ b/kennel/engine/systems/system.py
@@ -5,6 +5,7 @@ from abc import abstractmethod
class SystemType(str, Enum):
NETWORK = "NETWORK"
+ WORLD = "WORLD"
class System:
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)