aboutsummaryrefslogtreecommitdiff
path: root/kennel/engine/entities
diff options
context:
space:
mode:
Diffstat (limited to 'kennel/engine/entities')
-rw-r--r--kennel/engine/entities/__init__.py0
-rw-r--r--kennel/engine/entities/cat.py33
-rw-r--r--kennel/engine/entities/entity.py60
-rw-r--r--kennel/engine/entities/laser.py13
4 files changed, 106 insertions, 0 deletions
diff --git a/kennel/engine/entities/__init__.py b/kennel/engine/entities/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/kennel/engine/entities/__init__.py
diff --git a/kennel/engine/entities/cat.py b/kennel/engine/entities/cat.py
new file mode 100644
index 0000000..02fdb33
--- /dev/null
+++ b/kennel/engine/entities/cat.py
@@ -0,0 +1,33 @@
+#
+# # IDLE, FROLICKING, EEPY, ALERT, CHASING_CURSOR, CHASING_CAT, SCRATCHING, ITCHY
+# state_stochastic_matrix = [
+# # IDLE
+# [0.5, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0],
+# # FROLICKING
+# [0.1, 0.5, 0.1, 0.1, 0.1, 0.05, 0.05, 0],
+# # EEPY
+# [0.1, 0.1, 0.5, 0.1, 0.1, 0.05, 0.05, 0],
+# # ALERT
+# [0.1, 0.1, 0.1, 0.5, 0.1, 0.05, 0.05, 0],
+# # CHASING_CURSOR
+# [0.1, 0.1, 0.1, 0.1, 0.5, 0.05, 0.05, 0],
+# # CHASING_CAT
+# [0.1, 0.1, 0.1, 0.1, 0.1, 0.5, 0.05, 0],
+# # SCRATCHING
+# [0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.5, 0],
+# # ITCHY
+# [0, 0, 0, 0, 0, 0, 0, 1],
+# ]
+#
+#
+# class CatState(Enum):
+# IDLE = 0
+# FROLICKING = 1
+# EEPY = 2
+# ALERT = 3
+# CHASING_CURSOR = 4
+# CHASING_CAT = 5
+# SCRATCHING = 6
+# ITCHY = 7
+#
+#
diff --git a/kennel/engine/entities/entity.py b/kennel/engine/entities/entity.py
new file mode 100644
index 0000000..0ca8666
--- /dev/null
+++ b/kennel/engine/entities/entity.py
@@ -0,0 +1,60 @@
+from enum import Enum
+from kennel.engine.components.component import Component, ComponentType
+from typing import List, Optional
+
+
+class EntityType(str, Enum):
+ LASER = "LASER"
+
+
+class Entity:
+ def __init__(
+ self, entity_type: EntityType, id: str, component_list: List[Component]
+ ):
+ self.entity_type = entity_type
+ self.id = id
+ self.components = {}
+ for component in component_list:
+ self.add_component(component)
+
+ def get_component(self, component_type: ComponentType) -> Optional[Component]:
+ return self.components[component_type]
+
+ def add_component(self, component: Component) -> None:
+ self.components[component.component_type] = component
+
+
+class EntityManager:
+ def __init__(self):
+ self.entities = {}
+ self.component_entities = {}
+
+ def update(self) -> None:
+ self.component_entities = {}
+ for entity in self.entities.values():
+ for component in entity.components.values():
+ if component.component_type not in self.component_entities:
+ self.component_entities[component.component_type] = set()
+ self.component_entities[component.component_type].add(entity)
+
+ def get_entities_with_component(
+ self, component_type: ComponentType
+ ) -> List[Entity]:
+ return self.component_entities.get(component_type, [])
+
+ def add_entity(self, entity: Entity) -> None:
+ self.entities[entity.id] = entity
+ for component in entity.components.values():
+ if component.component_type not in self.component_entities:
+ self.component_entities[component.component_type] = set()
+ self.component_entities[component.component_type].add(entity)
+
+ def remove_entity(self, entity_id: str) -> None:
+ if entity_id in self.entities:
+ entity = self.entities[entity_id]
+ for component in entity.components.values():
+ if component.component_type in self.component_entities:
+ self.component_entities[component.component_type].remove(entity)
+
+ def get_entity(self, entity_id: str) -> Optional[Entity]:
+ return self.entities.get(entity_id)
diff --git a/kennel/engine/entities/laser.py b/kennel/engine/entities/laser.py
new file mode 100644
index 0000000..ead72a6
--- /dev/null
+++ b/kennel/engine/entities/laser.py
@@ -0,0 +1,13 @@
+from .entity import Entity, EntityType
+from kennel.engine.components.position import Position
+from kennel.engine.components.controllable import Controllable
+
+
+class Laser(Entity):
+ def __init__(self, id: str, controllable_by: str):
+ components = [
+ Position(0, 0),
+ Controllable(controllable_by),
+ ]
+
+ super().__init__(EntityType.LASER, id, components)